Spiral Draw
Author |
Message |
Cezna

|
Posted: Mon May 31, 2010 4:33 pm Post subject: Spiral Draw |
|
|
This is a program I made to experiment with drawing circles manually (as opposed to using the drawoval procedure)
Right now it draws a spiral, but you can make it draw a circle by setting rchange to 0.
Pretty much all of the variables of consequence are at the top where they are easy to change.
If r becomes less than or equal to x, it draws a straight vertical line instead of continuing to spiral. If anyone can figure out why (I have a vague idea, but I need to know exactly why), please tell me.
It's not very efficient either, of that I am sure, so if anyone can improve, please post the code.
So here it is, feel free to do whatever you want with it:
EDIT: just learned that I just use the code tag, so I fixed that to make it more readable.
code: |
var x, y, r, xprev, yprev, xchange, rchange, linethickness, centx, centy, minr : real
var clr : int
r := 50
x := 50
y := 200
xprev := x + 320
yprev := y
centx := 320
centy := 200
xchange := .002 % this determines how fast the is drawn
rchange := .0005 % this determines how fast the spiral's radius expands
minr := 10
linethickness := 20
clr := 52
colourback (black)
cls
loop
% quad 1
if x > 0 and y < 0 then
x += xchange
if (r ** 2 - x ** 2) > 0 then
y := (sqrt (r ** 2 - x ** 2) * -1)
else
y := (sqrt ((r ** 2 - x ** 2) * -1))
end if
% quad 2
elsif x > 0 and y > 0 then
x -= xchange
if (r ** 2 - x ** 2) > 0 then
y := sqrt (r ** 2 - x ** 2)
else
y := (sqrt ((r ** 2 - x ** 2) * -1) * -1)
end if
% quad 3
elsif x < 0 and y > 0 then
x -= xchange
if (r ** 2 - x ** 2) > 0 then
y := sqrt (r ** 2 - x ** 2)
else
y := ((sqrt ((r ** 2 - x ** 2) * -1)) * -1)
end if
% quad 4
elsif x < 0 and y < 0 then
x += xchange
if (r ** 2 - x ** 2) > 0 then
y := (sqrt (r ** 2 - x ** 2) * -1)
else
y := ((sqrt ((r ** 2 - x ** 2) * -1)) * -1)
end if
end if
if r > minr and r > x then
r += rchange
end if
if r <= minr then
r := minr
end if
if r <= x then
xchange += .0001
end if
Draw.ThickLine (round (xprev), round (yprev), round (x + centx), round (y + centy), round (linethickness), clr)
xprev := x + centx
yprev := y + centy
end loop
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|
|