Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Monday, 24 May 2010
Towards Penrose Tiling Using ruby-processing context-free DSL
#########################
# rubystar.rb
#########################
load_library 'context_free'
PHI = (1 + Math.sqrt(5))/2
def setup_the_sunstar
@hexa = ContextFree.define do
############ Begin defining custom terminals, as a sharp and flat triangles
class << self
include Math
define_method(:sharp) do |some_options|
size, options = *self.get_shape_values(some_options)
rot = options[:rotation]
rotate(rot) if rot # NB: sin(0) = 0, cos(0) = 1
super.triangle(0, 0, size, 0, size * cos(PI/5), size * sin(PI/5))
rotate(-rot) if rot
end
define_method(:flat) do |some_options|
size, options = *self.get_shape_values(some_options)
rot = options[:rotation]
rotate(rot) if rot
f = (options[:flip])? -1 : 1 # flip adjustment NB: sin(0) = 0, cos(0) = 1
super.triangle(0, 0, size/PHI, 0, size * cos(PI * f/5), size * sin(PI * f/5))
rotate(-rot) if rot
end
end
########### End definition of custom terminals 'sharp and flat'
rule :tiling do
sun :brightness => 0.8
star :brightness => 0.8, :alpha => 0.8
tiling :size => 1/PHI, :brightness => 1.0
end
rule :dart do
flat :size => 1, :color => [0.18, 0.6, 0.6]
flat :size => 1, :color => [0.18, 1.0, 1.0], :flip => true
end
rule :kite do
sharp :size => 1, :color => [0, 0.6, 0.6]
sharp :size => 1, :color => [0, 1.0, 1.0], :rotation => 180, :flip => true
end
rule :star do
split do
5.times do |i|
dart :rotation => 72 * i
rewind
end
end
end
rule :sun do
split do
5.times do |i|
kite :rotation => 72 * i
rewind
end
end
end
end
end
def setup
size 800, 800
background 150, 20, 0
smooth
setup_the_sunstar
draw_it
end
def draw_it
@hexa.render :tiling, :start_x => width/2, :start_y => height/2,
:size => height
end
Labels:
context free,
DSL,
penrose tiling,
ruby processing
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2010
(73)
-
▼
May
(9)
- Towards Penrose Tiling Using ruby-processing conte...
- Ruby Processing Context Free DSL (how to do a cfdg...
- Colored Penrose Tiling using LSystems
- Op Art using Voronoi Cell, Ruby Processing
- Voronoi Cells from the Coordinates of A Penrose Ti...
- Random Voronoi Sketch
- A Simple flower using ruby processing context free...
- Custom hbar shape for ruby processing Context Free...
- Penrose Tiling Ruby-Processing LSystems
-
▼
May
(9)
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2
No comments:
Post a Comment