Hi everybody!
This is my first Freebasic program!
Just a simple drawing demo!
The code isn't perfect and isn't optimized.
It's all realtime calculated and realtime drawn.
You will see some rotating and shapechanging "superellipses". (100 at same time)
hit spacekey for new ellipses/shapes
Greetings
stef
EDIT: added "supershape.exe" (in "supershape.rar")
' Superellipses/Supershapes on the fly
' by stef
OPTION STATIC
OPTION EXPLICIT
CONST SCREENW=800 '640
CONST SCREENH=600 '480
CONST MAXSHAPES=100
declare sub initshapes()
declare sub calcshapes()
declare sub drawshapes()
dim shared rad as single
dim shared rot as single
dim shared dist as single
dim status as integer
dim time2 as single
type tshapes
originx as single
originy as single
xradius as single
yradius as single
p as single
dp as single
rotangle as single
drotangle as single
col as integer
posx1(36) as single
posy1(36) as single
rotposx as single
rotposy as single
end type
dim shared shape(MAXSHAPES) as tshapes
SCREEN 19, 16, 2, 1
SCREENSET 1, 0
time2=timer
RANDOMIZE TIMER
DO
CLS
if status = 0 then
initshapes()
status=1
endif
IF MULTIKEY(&h39) then
status=0
endif
calcshapes()
drawshapes()
locate 1,1,0
print "hit space"
if timer-time2>0.033 then
time2=timer
SCREENCOPY
endif
LOOP UNTIL INKEY$=CHR$(27)
sub initshapes()
dim x as integer
for x= 0 to MAXSHAPES
shape(x).originx=Rnd*SCREENW
shape(x).originy=Rnd*SCREENH
shape(x).xradius=Rnd*80+20
shape(x).yradius=Rnd*80+20
shape(x).p=rnd*4
shape(x).dp=rnd*0.1
shape(x).rotangle=Rnd*360
shape(x).drotangle=(Rnd*2)-1
shape(x).col=rgb(rnd*255,rnd*255,rnd*255)
next
end sub
sub calcshapes()
dim a as integer
dim ang as integer
dim x as single
dim y as single
for a= 0 to MAXSHAPES
For ang= 0 To 36
rad=ang*0.17453293 '10 * PI / 180
x=Cos(rad)
y=sin(rad)
shape(a).posx1(ang)=sgn(x)*shape(a).xradius*(Abs(x)^shape(a).p)
shape(a).posy1(ang)=sgn(y)*shape(a).yradius*(Abs(y)^shape(a).p)
rot=atan2((shape(a).originx-(shape(a).originx+shape(a).posx1(ang))),(shape(a).originy-(shape(a).originy+shape(a).posy1(ang))))
dist= Sqr ( (shape(a).originx-(shape(a).originx+shape(a).posx1(ang)))^2 + (shape(a).originy-(shape(a).originy+shape(a).posy1(ang)))^2 )
shape(a).posx1(ang)=dist*Cos((shape(a).rotangle) * 0.17453293-rot)
shape(a).posy1(ang)=dist*Sin((shape(a).rotangle) * 0.17453293-rot)
next
shape(a).rotangle=shape(a).rotangle+shape(a).drotangle
shape(a).p=shape(a).p+shape(a).dp
if shape(a).p> 5 then
shape(a).dp=-shape(a).dp
endif
if shape(a).p< 0 then
shape(a).p=0
shape(a).dp=-shape(a).dp
endif
next
end sub
sub drawshapes()
dim a as integer
dim ang as integer
for a= 0 to MAXSHAPES
For ang= 0 To 36
If ang<36 then
Line (shape(a).originx+shape(a).posx1(ang),shape(a).originy+shape(a).posy1(ang))-(shape(a).originx+shape(a).posx1(ang+1),shape(a).originy+shape(a).posy1(ang+1) ),shape(a).col
endif
next
paint (shape(a).originx,shape(a).originy) ,shape(a).col,shape(a).col
next
end sub