Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,40 @@
|
|||
require "./pixmap"
|
||||
require "./bresenham"
|
||||
|
||||
class Pixmap
|
||||
def circle (cx, cy, r, color, fill = false)
|
||||
f = 1 - r
|
||||
ddF_X = 0
|
||||
ddF_Y = -2 * r
|
||||
x = 0
|
||||
y = r
|
||||
self[cx, cy + r] = color
|
||||
self[cx, cy - r] = color
|
||||
p1, p2 = {cx + r, cy}, {cx - r, cy}
|
||||
if fill
|
||||
line(*p1, *p2, color)
|
||||
else
|
||||
self[*p1] = self[*p2] = color
|
||||
end
|
||||
while x < y
|
||||
if f >= 0
|
||||
y -= 1
|
||||
ddF_Y += 2
|
||||
f += ddF_Y
|
||||
end
|
||||
x += 1
|
||||
ddF_X += 2
|
||||
f += ddF_X + 1
|
||||
[{cx - x, cy - y}, {cx + x, cy - y},
|
||||
{cx - x, cy + y}, {cx + x, cy + y},
|
||||
{cx - y, cy - x}, {cx + y, cy - x},
|
||||
{cx - y, cy + x}, {cx + y, cy + x}].each_slice(2, reuse: true) do |(p1, p2)|
|
||||
if fill
|
||||
line(*p1, *p2, color)
|
||||
else
|
||||
self[*p1] = self[*p2] = color
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
require "./circle"
|
||||
require "./write_ppm"
|
||||
|
||||
img = Pixmap.new 100, 100, Color::WHITE
|
||||
|
||||
img.circle 50, 50, 40, Color::RED, true
|
||||
img.circle 70, 60, 15, Color::BLUE, true
|
||||
img.circle 40, 20, 20, Color::BLACK
|
||||
img.circle 40, 20, 19, Color.new(255, 144, 0)
|
||||
img.circle 40, 20, 18, Color::BLACK
|
||||
|
||||
img.write "crystal_circles.ppm"
|
||||
Loading…
Add table
Add a link
Reference in a new issue