class Straightedge::Figures::Grid
Attributes
dimensions[R]
figure[R]
scale[R]
Public Class Methods
each_coordinate(dim) { |x,y| ... }
click to toggle source
# File lib/straightedge/figures/grid.rb, line 54 def self.each_coordinate(dim) dim.x.times do |x| dim.y.times do |y| yield [x,y] end end end
new(dimensions=[1,1], opts={})
click to toggle source
Calls superclass method
Straightedge::Figures::Figure::new
# File lib/straightedge/figures/grid.rb, line 11 def initialize(dimensions=[1,1], opts={}) @dimensions = dimensions @scale = opts.delete(:scale) { 1.0 } super(to_a, opts) end
Public Instance Methods
at(xy)
click to toggle source
# File lib/straightedge/figures/grid.rb, line 17 def at(xy) [xy.x, xy.y] end
cell_at(xy)
click to toggle source
# File lib/straightedge/figures/grid.rb, line 33 def cell_at(xy) @cells ||= {} @cells[xy] = Figures::Quadrilateral.new(color: color_at(xy), dimensions: [@scale, @scale], location: to_pixels(xy)) end
clip(xys=[])
click to toggle source
# File lib/straightedge/figures/grid.rb, line 47 def clip(xys=[]) xys.reject do |xy| _x, _y = xy.x, xy.y _x < 0 || _y < 0 || _x >= width || _y >= height end end
color_at(_)
click to toggle source
over-ride with data
# File lib/straightedge/figures/grid.rb, line 32 def color_at(_); :none end
each() { |at([x,y])| ... }
click to toggle source
# File lib/straightedge/figures/grid.rb, line 25 def each Grid.each_coordinate([width, height]) do |x, y| yield(at([x,y])) end end
each_cell() { |c| ... }
click to toggle source
# File lib/straightedge/figures/grid.rb, line 38 def each_cell each { |xy| c = cell_at(xy); yield c if c } end
orbit(xy)
click to toggle source
# File lib/straightedge/figures/grid.rb, line 21 def orbit(xy) clip compass.orbit(xy) end
paint!()
click to toggle source
# File lib/straightedge/figures/grid.rb, line 42 def paint! #each(&:to_point) each_cell(&:paint) end
to_pixels(xy)
click to toggle source
why scale/2? there's something goofy somewhere
# File lib/straightedge/figures/grid.rb, line 63 def to_pixels(xy) [xy.x * (@scale/2), xy.y * (@scale/2)] end