TGC Codebase Backup



Ellipse by Proteus 1935

7th Oct 2003 13:27
Summary

This code shows you how to draw ellipses by getting it's "radius" to a given angle, giving you the power to draw angled ellipses, giving a little thougth to it you can cr



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem b^2 = a^2 - c^2
rem c = sqrt(a^2 - b^2)
rem e = sqrt(1 - (b^2/a^2))
rem e^2 = 1 - (b^2/a^2)
rem -e^2 +1 =  b^2/a^2
rem (1 -(e^2))*a^2 = b^2
rem b = sqrt( (1-(e^2))*a^2 )
set text font "arial"
set text size 100
center text screen width()/2,screen height()/2-50,"PharosFx"
wait key
set text size 20
sync on
a# = 135.0
b# = 135.0
angle = 0




do
set cursor 0,0
Print "Elliptical Path"
Print "a:";a#
print "b:";b#
mk_ellipse(a#,b#,turn#)
print turn#


if shiftkey()=1 then inc turn# : turn# = wrapvalue(turn#)
if upkey()=1 then inc a#
if downkey()=1 then dec a#
if rightkey()=1 then inc b#
if leftkey()=1 then dec b#


sync
cls
loop
function ellipse_radius(a#,b#,angle#,rotation#)
r# = sqrt(a#^2*b#^2/(a#^2 * sin(angle#+rotation#)^2 + b#^2 *cos(angle#+rotation#)^2))
X# = newXvalue(320,angle#,r#)
Z# = newZvalue(240,angle#,r#)
endfunction r#


function mk_ellipse(a#,b#,turn#)
for angle# = 0 to 360.0 step 0.1
r# = sqrt(a#^2*b#^2/(a#^2 * sin(angle#+turn#)^2 + b#^2 *cos(angle#+turn#)^2))
X# = newXvalue(320.0,angle#,r#)
Z# = newZvalue(240.0,angle#,r#)
dot X#,Z#
next angle#

remstart
x2# = 320.0 : x3# = 320.0
y2# = 240.0 : y3# = 240.0
if a#^2 - b#^2 > 0
y2# = 240 + sqrt(a#^2 - b#^2)
y3# = 240 - sqrt(a#^2 - b#^2)
dist# = abs(240.0-y2#)
x2# = newxvalue(320.0,-turn#,dist#)
x3# = newxvalue(320.0,-turn#,-dist#)

else
x2# = 320 + sqrt(b#^2 - a#^2)
x3# = 320 - sqrt(b#^2 - a#^2)
dist# = abs(320.0-x2#)
y3# = newZvalue(240.0,-turn#,-dist#)
y2# = newZvalue(240.0,-turn#,dist#)
endif


print "dist:";dist#
x2# = newxvalue(320.0,-turn#,dist#)
x3# = newxvalue(320.0,-turn#,-dist#)

dot x2#,y2#
dot x3#,y3#
remend


endfunction