%circle proggy:
%use sine and cosine to generate circles
%sine of a number will always be between 1 and -1 and if you graph it you will
%get a "sine wave". cosine is similar to sine in that when graphed it produces
%a wave but the trough of the wave is half a wave length to the right. this
%relationship can be used to generate circles...
%to generate a circle, we need to generate x values by using sine
%and y values using cosine. the numbers that we find the sine/cosine of are
%0 - 360 (1 for each angle in a circle) this is because in one full sine wave,
%there are are 360 degrees. the thing is, these angles need to
%be expressed in radians, so to convert degrees into radians we multiply the
%angle by PI/180. so our formula would be x = sin(ang*(PI/180)). now to make
%things easier, we could use the predefined functoin cosd() which automaticaly
%converts the angle into radians. since the result of the sine/cosine of a
%number is number between -1 and 1, this means that we can use this number as
%a percent. therefore we multiply our x by the desired diameter and we get the
%coordinate for our circle...
procedure drawCircle (centerx, centery, diam, c : int)
var x, y, oldx, oldy : real
oldx := cos (0) * diam + centerx
oldy := sin (0) * diam + centery
for i : 1 .. 360
%in radians:
x := cos (i * (Math.PI / 180)) * diam + centerx
%using sind() to automatically convert to radians:
y := sind (i) * diam + centery
drawline (round (oldx), round (oldy), round (x), round (y), c)
oldx := x
oldy := y
end for
end drawCircle
drawCircle (maxx div 2, maxy div 2, 100, 7)
|