1. aCircle.ex
Here's an interesting little demo of drawing a circle with draw_line.
Have fun with it.
James Powell
<-- Begin Cut Here -->
-- program ACIRCLE.EX by James Powell {wizard at djo.com}
--
-- ACIRCLE.EX is derived from a heavily modified version
-- of ACIRCLE.X, which was distributed by BASMARK with
-- their Windows xBASIC compiler.
--
-- (I decided to include this disclaimer to point out that )
-- (the circle generation routine is not my work. I thought )
-- (that passing it off as mine would be unethical. All other)
-- (parts of ACIRCLE.EX are modifications that I made to the )
-- (original source. )
--
-- modify the variables to expirement with different shapes,
-- sizes, etc.
-- Have fun!
include graphics.e
constant PI = 3.141592653589793 -- Pi, of course
constant TWOPI = PI * 2 -- Duh!
constant GMode = 19 -- 320*200*256 VGA
constant SCREEN = 1
atom s1, s2, a1, a2, key, rad, prad
integer cW, cH, xdir, ydir, looper, dx, dy
procedure aCircle()
integer p1x, p1y, p2x, p2y
if (a1 >= TWOPI) then
a1 = a1 - TWOPI
end if
if (a2 >= TWOPI) then
a2 = a2 - TWOPI
looper = looper + 1
end if
p1x = floor(sin(a1) * rad + dx) -- Line segment endpoints
p1y = floor(cos(a1) * rad + dy) -- when drawn, forms a line
p2x = floor(sin(a2) * rad + dx) -- from xcenter - xradius,
p2y = floor(cos(a2) * rad + dy) -- ycenter - yraduis to
draw_line(WHITE, {{p1x, p1y},{p2x, p2y}}) -- xcenter + xradius,
a1 = a1 + s1 -- ycenter + xradius
a2 = a2 + s2
s2 = 1.0002 * s2
if (s2 > TWOPI) then
s2 = s2 - TWOPI
end if
end procedure
s1 = PI / 256
s2 = 4.9 * s1
a1 = 0
a2 = PI / 4
cW = 50 -- circle width diameter
cH = 50 -- circle height diameter
dx = 158 -- x center
dy = 98 -- y center
xdir = 1 -- x direction | 1 = --> or \/
ydir = 1 -- y direction | -1 = <-- or /\
if cW < cH then
rad = floor(cW / 2) -- radius of the circle
else
rad = floor(cH / 2)
end if
prad = rad -- we want the polygon to erase
rad = rad - 6 -- the whole circle
if graphics_mode(GMode) then
puts(SCREEN, "You need 320 X 200, 256 color VGA")
abort(1)
end if
key = get_key() -- draw a box to erase the
while key = -1 do -- lines
polygon(BLACK, 1,{{dx - prad, dy - prad},{dx + prad, dy - prad},
{dx + prad, dy + prad}, {dx - prad, dy + prad}})
looper = 0
while looper <= 35 do
aCircle() -- draw 35 staggered lines
looper = looper + 1 -- neato! makes a circle shape
end while
dx = dx + xdir -- now, lets move the center
dy = dy + ydir -- coordinates
if (dx > (320 - (floor(cW / 2) + 2))) or (dx < (floor(cW / 2) + 2)) then
xdir = -xdir -- are we at the edges?
end if
if (dy > (200 - (floor(cH / 2) + 2))) or (dy < (floor(cH / 2) + 2)) then
ydir = -ydir -- are we at the top or bottom?
end if
key = get_key() -- keep going as long as no
end while -- key was pressed
if graphics_mode(-1) then
puts(SCREEN, "I couldn't reset to text mode")
abort(1)
end if
<-- End Cut Here-->