Superellipses / Supershapes on the fly

Started by stef, March 14, 2007, 02:45:42 PM

Previous topic - Next topic

stef

Hi!

That's some 2D drawing stuff.

It's drawing some (realtime generated,rotated) superellipses/supershapes

Atm it's running correctly in PB 1.63 (and below)

there are 2 codes

the first code is syncing without fps restriction
you see fps in top left corner (I got about fps 380)

the second code is syncing every 30 ms.
you see number of shapes generated in this time (got about 100;= about 3000 shapes in 1 second))



; PROJECT : Superellipses/Supershapes 1
; AUTHOR  : stef
; CREATED : 12.03.2007
; EDITED  : 14.03.2007
; ---------------------------------------------------------------------



OpenScreen 800,600,16,2
;setfps 30

  im=NewImage(800,600)

  Do
 
LockBuffer

   originx#=Rnd#(800)
   originy#=Rnd#(600)
   xradius=RndRange(20,100)
   yradius=RndRange(20,100)
   p#=RndRange#(0,4)
   angle=Rnd(360)
   Ink RndRGB()
   fill=1-fill

RenderToImage im
 
    For ang= 0 To 37
    x#=Cos(ang*10)
    y#=Sin(ang*10)
    xs#=1.0:ys#=1.0
    If x#<0 Then xs#=-1.0
    If y#<0 Then ys#=-1.0
   
   
    posx1#=xs#*xradius*(Abs(x#)^p#)
    posy1#=ys#*yradius*(Abs(y#)^p#)
   
    a1#=GetAngle2D(originx#,originy#,originx#+posx1#,originy#+posy1#)
  dist#=GetDistance2D(originx#,originy#,originx#+posx1#,originy#+posy1#)
   
    posx#=dist#*Cos(angle-a1#)
    posy#=dist#*Sin(angle-a1#)
   
   If ang>0 
   
   If fill=0
   
      Line originx#+posx#,originy#+posy#,originx#+posxold#,originy#+posyold#
   
   Else
       
    Tri originx#,originy#,originx#+posx#,originy#+posy#,originx#+posxold#,originy#+posyold#
   
   EndIf
   EndIf
 
 
  posxold#=posx#
   posyold#=posy#
     
  Next 
 
   
   UnLockBuffer
   
   
  ;Inc counter
   
   
   RenderToScreen
   
   DrawImage im,0,0,1
   BoxC 0,0,50,12,1,RGB(10,10,10)
   Text 0,0,Str$( FPS())
   
   Sync
   
  If EscKey()=1 Then End
 
Loop







; PROJECT : Superellipses/Supershapes 2
; AUTHOR  : stef
; CREATED : 12.03.2007
; EDITED  : 14.03.2007
; ---------------------------------------------------------------------



OpenScreen 800,600,16,2
time1=Timer()
im=NewImage(800,600)

  Do
 
LockBuffer

   originx#=Rnd#(800)
   originy#=Rnd#(600)
   xradius=RndRange(20,100)
   yradius=RndRange(20,100)
   p#=RndRange#(0,4)
   angle=Rnd(360)
   Ink RndRGB()
   fill=1-fill

RenderToImage im
 
    For ang= 0 To 37
    x#=Cos(ang*10)
    y#=Sin(ang*10)
    xs#=1.0:ys#=1.0
    If x#<0 Then xs#=-1.0
    If y#<0 Then ys#=-1.0
   
   
   
    posx1#=xs#*xradius*(Abs(x#)^p#)
    posy1#=ys#*yradius*(Abs(y#)^p#)
   
    a1#=GetAngle2D(originx#,originy#,originx#+posx1#,originy#+posy1#)
    dist#=GetDistance2D(originx#,originy#,originx#+posx1#,originy#+posy1#)
   
    posx#=dist#*Cos(angle-a1#)
    posy#=dist#*Sin(angle-a1#)
   
   If ang>0 
   
   If fill=0
   
      Line originx#+posx#,originy#+posy#,originx#+posxold#,originy#+posyold#
   
   Else
   
    Tri originx#,originy#,originx#+posx#,originy#+posy#,originx#+posxold#,originy#+posyold#
   EndIf
   
   EndIf
 
 
     posxold#=posx#
     posyold#=posy#
     
    Next 
 
 
   UnLockBuffer
   
   
  Inc counter
 
   if Timer()-time1>30
   
   
   RenderToScreen
   
   DrawImage im,0,0,1
   BoxC 0,0,50,12,1,RGB(10,10,10)
   Text 0,0,Str$( counter)
   
   Sync
   counter=0
   time1=Timer()
   
   EndIf
 
  If EscKey()=1 Then End
 
Loop