Class: Ranicoma::Design::RotObj
- Defined in:
- lib/ranicoma/design/rotobj.rb
Constant Summary collapse
- LINE =
1.0/80
Instance Attribute Summary collapse
-
#body_seed ⇒ Object
readonly
Returns the value of attribute body_seed.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Attributes inherited from Base
Instance Method Summary collapse
- #body(theta, seed) ⇒ Object
- #colmove(r, c) ⇒ Object
- #create ⇒ Object
-
#initialize(rng) ⇒ RotObj
constructor
A new instance of RotObj.
- #make_dists(body_rng, lo, hi, depth) ⇒ Object
- #unit(theta) ⇒ Object
Methods inherited from Base
add_subclass, #fill, inherited, #points_str, #rainbow, #rand, #rand_rotate, #rect_element, #rectpos, #stroke, subclasses
Methods included from Util
Constructor Details
#initialize(rng) ⇒ RotObj
Returns a new instance of RotObj.
12 13 14 15 16 17 |
# File 'lib/ranicoma/design/rotobj.rb', line 12 def initialize(rng) super @ct0 = rng.rand(Math::PI*2) @count = rng.rand(5..10) @body_seed = rng.rand(2**256) end |
Instance Attribute Details
#body_seed ⇒ Object (readonly)
Returns the value of attribute body_seed.
20 21 22 |
# File 'lib/ranicoma/design/rotobj.rb', line 20 def body_seed @body_seed end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
19 20 21 |
# File 'lib/ranicoma/design/rotobj.rb', line 19 def count @count end |
Instance Method Details
#body(theta, seed) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ranicoma/design/rotobj.rb', line 40 def body(theta, seed) body_rng = Random.new(seed) arc=20 r=0.48 dt = Math::PI*2/count/2*0.9 t0 = -Math::PI/2 - dt t1 = -Math::PI/2 + dt pts = [ [0.5, 0.5] ]+Array.new(arc+1){ |ix| t = (t1-t0)*ix*1.0/arc + t0 [Math.cos(t)*r+0.5, Math.sin(t)*r+0.5] } bc = rainbow( theta*3/(Math::PI*2) + @ct0 ) dists=make_dists(body_rng, 0, 0.5, 3).flatten clip_id = Random.new_seed [ element( "clipPath", id:clip_id ){ element( "polygon", points:points_str(pts)) }, element( "g", "clip-path":"url(##{clip_id})", style:"fill:#0000" ){ dists.map{ |dist| t = body_rng.rand(t0..t1) cx = Math.cos(t)*dist + 0.5 cy = Math.sin(t)*dist + 0.5 cr = body_rng.rand(0.05..0.1) color = colmove(body_rng,bc) if body_rng.rand(2)==0 element( "circle", cx:cx, cy:cy, r:cr, **fill(color) ) else element( "circle", cx:cx, cy:cy, r:cr, **stroke( color, 1.0/20) ) end } } ] end |
#colmove(r, c) ⇒ Object
34 35 36 37 38 |
# File 'lib/ranicoma/design/rotobj.rb', line 34 def colmove( r, c ) delta = 80 f = ->(x){ r.rand(x-delta..x+delta).clamp(0,255).round } c.map{ |e| f[e] } end |
#create ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/ranicoma/design/rotobj.rb', line 92 def create basecol = rainbow(rng.rand(Math::PI*2), ->(v){ (v+3)/4.0 } ) [ element("circle", cx:0.5, cy:0.5, r:0.4, **fill(basecol) ) ]+Array.new(count){ |ix| unit(Math::PI*2*ix/count) }.flatten end |
#make_dists(body_rng, lo, hi, depth) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ranicoma/design/rotobj.rb', line 22 def make_dists(body_rng, lo, hi, depth) return [] if depth<=0 x = (hi-lo)*0.2 mid = body_rng.rand(lo+x..hi-x) [ body_rng.rand(lo..mid), make_dists(body_rng, lo, mid, depth-1), make_dists(body_rng, mid, hi, depth-1), body_rng.rand(mid..hi), ] end |
#unit(theta) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/ranicoma/design/rotobj.rb', line 85 def unit(theta) rot = "rotate(#{theta*180/Math::PI},0.5,0.5)" element("g", transform:rot ){ body(theta, body_seed) } end |