News:

Function Finder  Find all the functions within source code files

Main Menu

Hal Teach me to code - Morphing Shapes - PlayBASIC Code Snippet - 2022-05-12

Started by kevin, May 12, 2022, 09:52:30 AM

Previous topic - Next topic

kevin

  Hal Teach me to code  -  Morphing Shapes - PlayBASIC Code Snippet - 2022-05-12


Hal Teach me to code  -  Morphing Shapes - PlayBASIC Code Snippet - 2022-05-12

 This tiny source code snippet uses PlayBASIC's shapes to draw batches of line fragments. The fragments are all connected in a circle were each vertex is waving and rotating.   On their own the effect is really simple; but when you overlay (rotate and scale) a bunch of them on top of each other it creates a sort of button effect similar to the robotic voice in the classic science function movie 2001 A Space Odyssey.   Excuse my poor impressions of Hal in this  video.. It's just for laughs :)






PlayBASIC Code: [Select]
; PROJECT : Morphing Shape Tunnel
; AUTHOR : Learn To Code PlayBASIC - http://playbasic.com
; CREATED : 11/05/2022
; EDITED : 13/05/2022
; ---------------------------------------------------------------------

openscreen 1280,960,32,1

positionscreen getscreenxpos(),10

Count=360*3

RingShape = NewShape(Count, Count)

// Set the edge links for this shape.
For lp =0 to Count-2
SetShapeEdge RingShape,lp, lp,lp+1
next
; // link the last one back to the first
SetShapeEdge RingShape,lp,lp,0


Screen=NewFxImage(GetSurfaceWidth(),GetSurfaceHeight())

Scaler#=2

Rings=10
Ringcolour=$505050
ColourCountDown=200

do

rendertoimage Screen

inkmode 1+2048
boxc 0,0,getsurfacewidth(),getsurfaceheight(),true,$f0e0d0

mx#=getsurfacewidth()/2
my#=GetSurfaceheight()/2

Scaler#=wrapvalue(scaler#+0.25,1,100)


for lp =0 to Count-1
; randomly init the vertex as polar coordinates
Angle#=(360.0/Count)*lp
; Radius# =120+cosRadius(WobbleAngle2#+lp*1.23,34)+ Cos(WobbleAngle#+(Angle#*Scaler#))*50
Radius# =90+cos(WobbleAngle#+(Angle#*Scaler#))*50
setshapevertex RingShape,lp,Cosradius(Angle#,Radius#) ,Sinradius(Angle#,Radius#)
next
; WobbleAngle2#+=0.43
WobbleAngle#-=(2.25)*4

lockbuffer
Scale#=0.5


inkmode 1+64
for lp=0 to Rings
ink RgbFade( Ringcolour, Float(lp)/Rings *50)
rotateshape ringShape,SpinAngle#+lp*10,Scale#
drawshape RingShape,mx#,my#,1
Scale#+=0.33
next
unlockbuffer

SpinAngle#+=0.2


rendertoscreen
drawimage Screen,0,0,false


ColourCountDown--
if ColourCountDown<0
ColourCountDown=30
Ringcolour= rgbalphaadd( (rndrgb() and $3f3f3f), $080808)
endif


sync
loop spacekey()







[ Links ]


  - Buy 2001 A Space Odyssey [1968] [Region Free]
 
  Music:
  The Right Direction by Shane Ivers - https://www.silvermansound.com

  - Movie Samples:
 



[ HashTags ]


  #learntocode #sourcecode #basic