Class: Ranicoma::Design::Geji
Constant Summary collapse
- PROJ_METHODS =
[]
Instance Attribute Summary collapse
-
#center_rc ⇒ Object
readonly
Returns the value of attribute center_rc.
-
#line_width ⇒ Object
readonly
Returns the value of attribute line_width.
-
#projsize ⇒ Object
readonly
Returns the value of attribute projsize.
Attributes inherited from Base
Instance Method Summary collapse
- #bezier(rc, corners) ⇒ Object
- #center_rect ⇒ Object
- #create ⇒ Object
- #eqcolors(n) ⇒ Object
-
#initialize(rng) ⇒ Geji
constructor
A new instance of Geji.
- #proj_attr ⇒ Object
- #projects(pos) ⇒ Object
- #shorten_rc(rc) ⇒ 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
Instance Attribute Details
#center_rc ⇒ Object (readonly)
Returns the value of attribute center_rc.
27 28 29 |
# File 'lib/ranicoma/design/geji.rb', line 27 def center_rc @center_rc end |
#line_width ⇒ Object (readonly)
Returns the value of attribute line_width.
25 26 27 |
# File 'lib/ranicoma/design/geji.rb', line 25 def line_width @line_width end |
#projsize ⇒ Object (readonly)
Returns the value of attribute projsize.
26 27 28 |
# File 'lib/ranicoma/design/geji.rb', line 26 def projsize @projsize end |
Instance Method Details
#bezier(rc, corners) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ranicoma/design/geji.rb', line 76 def bezier(rc, corners) q = corners.each_cons(2).map{ |(x0,y0),(x1,y1)| mx = (x0+x1)/2.0 my = (y0+y1)/2.0 "Q #{x0} #{y0} #{mx} #{my} " } path = <<~PATH M #{rc.x} #{rc.bottom} #{q.join} L #{corners.last.join(" ")} L #{rc.x} #{rc.bottom} PATH element( "path", d:path, **proj_attr ) end |
#center_rect ⇒ Object
35 36 37 38 39 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 |
# File 'lib/ranicoma/design/geji.rb', line 35 def center_rect gx = center_rc.w * rand(0.05..0.3) gy = center_rc.h * rand(0.05..0.3) w0 = (center_rc.w-gx*2)*rand(0.6..0.9) h0 = (center_rc.h-gy*2)*rand(0.6..0.9) w1 = (center_rc.w-gx*2)*rand(0.6..0.9) h1 = (center_rc.h-gy*2)*rand(0.6..0.9) subrects = if rand(2)==0 [ Rect.new( center_rc.x+gx, center_rc.y+gy, w0, h0 ), Rect.new( center_rc.right-gx-w1, center_rc.bottom-gy-h1, w1, h1 ), ] else [ Rect.new( center_rc.right-gx-w0, center_rc.y+gy, w0, h0 ), Rect.new( center_rc.x+gx, center_rc.bottom-gy-h1, w1, h1 ), ] end.shuffle( random:rng ) if rand(2)==0 h = [h0, h1].min * rand(0.3..1.1) w = [w0, w1].min * rand(0.3..1.1) subrects.push( Rect.new( center_rc.cx-w/2, center_rc.cy-h/2, w, h ) ) end cols = eqcolors(subrects.size+1) makeattr=->(){ { rx:line_width*3, **fill(cols.pop), **stroke(:black, line_width) } } ([ center_rc ]+subrects).map{ |rc| element( "rect", **rectpos(rc), **makeattr[] ) } end |
#create ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/ranicoma/design/geji.rb', line 238 def create [ Array.new(4){ |pos| projects(pos) }, center_rect ].flatten end |
#eqcolors(n) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ranicoma/design/geji.rb', line 29 def eqcolors(n) base=rand(3.0) Array.new(n){ |ix| rainbow(base+3.0*ix/n) } end |
#proj_attr ⇒ Object
21 22 23 |
# File 'lib/ranicoma/design/geji.rb', line 21 def proj_attr fill(rainbow(rand(3.0))).merge(stroke(:black, line_width)) end |
#projects(pos) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/ranicoma/design/geji.rb', line 216 def projects(pos) count = rand(2..5) rot = "rotate(#{90*pos},0.5,0.5)" proj_rects = center_rc.hsplit(*([1]*count)) proj_rects.each{ |e| e.x += e.w*0.1 e.w *= 0.8 e.y=line_width e.h = projsize } pattern = rand(1..2**count-1) | rand(1..2**count-1) element("g", transform:rot ){ Array.new(count){ |ix| if pattern[ix]==0 [] else send PROJ_METHODS.sample(random:rng), proj_rects[ix] end }.flatten } end |
#shorten_rc(rc) ⇒ Object
71 72 73 74 |
# File 'lib/ranicoma/design/geji.rb', line 71 def shorten_rc(rc) d = rand(rc.h/2) Rect.new( rc.x, rc.y+d, rc.w, rc.h-d ) end |