class Target
include Drawing
...
def draw
left, top, size = @x - @radius, @y - @radius, @radius * 2
# Draw the :target layer; the painting operations only get called when the
# layer needs to be repainted.
paint_layer(:target, left, top, size, size, :z => 0) do |canvas|
cx = cy = @radius # for clarity below
canvas.circle cx, cy, @radius, :color => :red, :fill => true
canvas.circle cx, cy, @radius * 0.8, :color => :white, :fill => true
canvas.circle cx, cy, @radius * 0.6, :color => :red, :fill => true
canvas.circle cx, cy, @radius * 0.4, :color => :white, :fill => true
canvas.circle cx, cy, @radius * 0.2, :color => :red, :fill => true
end
end
def radius= new_radius
@radius = Float(new_radius)
# The :target layer must be redrawn when the radius changes.
invalidate_layer_cache! :target
end
end
draw_circle
; if I were going to be writing code that required arbitrary primitives, I'd probably use the "layer caching" thing with TexPlay that I mentioned above. I thought it was pretty clever. I like your solution too, though. :D
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill