A simple 3D demo :
#!/usr/bin/egsl
-----------------------
-- screen set
-----------------------
openwindow(650,450,32,"3D demo - EGSL")
backcolour(255,255,255)
colour(0,0,0)
clearscreen()
---------------------------
-- constants & variables
---------------------------
rad = math.rad
ox, oy = screenwidth()/2, screenheight()/2
coorx, coory = 0, 0
pen = true
heading = 0
--------------------------------
-- main graphic function
--------------------------------
function pos(x,y)
-- draw if pen is down (== true)
if pen then aaline(ox+coorx, oy-coory, ox+x, oy-y) end
-- set new position
coorx, coory = x, y
end
-----------------
-- 3D functions
-----------------
function isopoint(a,b,c)
pos( (a-c)*0.886 , b-(a+c)*0.5 )
end
function cone(r,l)
r = l/2
-- set at point (0,0,0)
pen = false
local h, v
for h = 0, l, 10 do
for v = 0, 360, 20 do
isopoint( (h/2)*cos(rad(v)), h, (h/2)*sin(rad(v)) )
pen = true
end
pen = false
end
for v = 0, 360, 20 do
for h = 0, l, 10 do
isopoint( (h/2)*cos(rad(v)), h, (h/2)*sin(rad(v)) )
pen= true
end
pen = false
end
end
function ellipsoid(r1, r2, r3)
-- set at point (100,-30,100)
local u, v, l, m, n
pen = false
for u = 0, 360, 20 do
for v = 0, 180, 20 do
l = (r1 * cos(rad(u))) * sin(rad(v))
m = r3 * sin(rad(u))
n = (r2 * cos(rad(u))) * cos(rad(v))
isopoint(100 + l, -30 + m, 100 + n)
pen = true
end
pen= false
end
for v = 0, 180, 20 do
for u = 0, 360, 20 do
l = (r1 * cos(rad(u))) * sin(rad(v))
m = r3 * sin(rad(u))
n = r2 * cos(rad(u)) * cos(rad(v))
isopoint(100 + l, -30 + m, 100 + n)
pen = true
end
pen = false
end
end
function cylinder(r, l)
-- set at point (120,-100,-120)
local h, v
pen= false
for h = 0, l, 10 do
for v = 0, 360, 20 do
isopoint( 120+r*cos(rad(v)), -100+h, -120+r*sin(rad(v)) )
pen = true
end
pen = false
end
for v = 0, 360, 20 do
for h = 0, l, 10 do
isopoint( 120+r*cos(rad(v)), -100+h, -120+r*sin(rad(v)) )
pen = true
end
pen= false
end
end
function sphere(r)
-- set at point (-120,-100,120)
local u, v, l, m, n
pen = false
for u = 0, 360, 20 do
for v = 0, 180, 20 do
l = (r * cos(rad(u))) * sin(rad(v))
m = r * sin(rad(u))
n = (r * cos(rad(u))) * cos(rad(v))
isopoint(-120 + l, -100 + m, 120 + n)
pen= true
end
pen = false
end
for v = 0, 180, 20 do
for u = 0, 360, 20 do
l = (r * cos(rad(u))) * sin(rad(v))
m = r * sin(rad(u))
n = (r * cos(rad(u))) * cos(rad(v))
isopoint(-120 + l, -100 + m, 120 + n)
pen= true
end
pen = false
end
end
---------------------------------
-- 3D demo : main program
---------------------------------
sphere(40)
cone(40, 70)
cylinder(30, 90)
ellipsoid(60, 40, 25)
redraw()
inkey()
closewindow()