class Ranicoma::Design::Base
Attributes
rng[R]
Public Class Methods
add_subclass(cls)
click to toggle source
# File lib/ranicoma/design/base.rb, line 10 def self.add_subclass(cls) @subclasses ||= [] @subclasses.push(cls) end
inherited(subclass)
click to toggle source
# File lib/ranicoma/design/base.rb, line 83 def Base.inherited(subclass) Base.add_subclass(subclass) end
new(rng)
click to toggle source
# File lib/ranicoma/design/base.rb, line 33 def initialize(rng) @rng=rng end
subclasses()
click to toggle source
# File lib/ranicoma/design/base.rb, line 29 def Base.subclasses @subclasses end
Public Instance Methods
fill(col)
click to toggle source
# File lib/ranicoma/design/base.rb, line 60 def fill(col) case col when Array { style:"fill:rgb(#{col.join(",")})" } when /^\d+\,\d+\,\d+$/ { style:"fill:rgb(#{col})" } else { style:"fill:#{col}" } end end
points_str(pts)
click to toggle source
# File lib/ranicoma/design/base.rb, line 37 def points_str(pts) pts.map{ |e| e.join(",") }.join(" ") end
rainbow(t,mx=->(v){v}
click to toggle source
# File lib/ranicoma/design/base.rb, line 15 def rainbow(t,mx=->(v){v}) f = lambda{ |t0| v = lambda{ |x| case x when 0..1 then x when 1..2 then 2-x else 0 end }[t0 % 3] (mx[v]*255).round } [f[t],f[t+1],f[t+2]] end
rand(*args)
click to toggle source
# File lib/ranicoma/design/base.rb, line 47 def rand(*args) rng.rand(*args) end
rand_rotate(ary)
click to toggle source
# File lib/ranicoma/design/base.rb, line 55 def rand_rotate(ary) ix=rng.rand(ary.size) ary[ix,ary.size-ix] + ary[0,ix] end
rect_element(rc, col)
click to toggle source
# File lib/ranicoma/design/base.rb, line 41 def rect_element(rc, col) element("rect", **rectpos(rc), **fill(col)) end
rectpos(rc)
click to toggle source
# File lib/ranicoma/design/base.rb, line 51 def rectpos(rc) { x:rc.x, y:rc.y, width:rc.w, height:rc.h } end
stroke(col, w)
click to toggle source
# File lib/ranicoma/design/base.rb, line 71 def stroke(col, w) c=case col when Array "rgb(#{col.join(",")})" when /^\d+\,\d+\,\d+$/ "rgb(#{col})" else col end { stroke:c, "stroke-width":w } end