An Old school Demo effect

Share your advanced PureBasic knowledge/code with the community.
omnikam
User
User
Posts: 27
Joined: Sat Apr 15, 2017 10:58 am

An Old school Demo effect

Post by omnikam »

After learning about the old school tunnel effect from the legend Vain, I decided to take it to completely new place
Please enjoy this old school Demo effect. Running on5.7 and 5.4
You might notice ch0_state and it's counterpart
, they were connected to vu channels for interactive variance, amazing it still complies without the extra externals. This is a cut down from an actual project I'm working on
Feel free to use it but credit me and Vain if you find it useful

Code: Select all

InitSprite() 
UsePNGImageDecoder()
OpenScreen(640,480,32,"Cool Effect")
; -------- Init Code --------
Global angle.f:   angle=0.0 
Global lTextureSize.l  = 256 
lScreenWidth.l  = 640
lScreenHeight.l = 480
#xres=640
#yres=480
Dim aTexture  (lTextureSize, lTextureSize)
Dim aDistance (lScreenWidth, lScreenHeight)
Dim aAngle    (lScreenWidth, lScreenHeight)
Dim aBuffer   (lScreenWidth, lScreenHeight)
Procedure.f GSin(winkel.f)                              ; angle calculation by Danilo -> thanks comrade :)
   ProcedureReturn Sin(winkel*(2*3.14159265/360))
 EndProcedure
 
 Procedure.d ATon2(y.d, x.d)
  !FLD qword[p.v_y]
  !FLD qword[p.v_x]
  !FPATAN
  ProcedureReturn 
EndProcedure
; -------- Generating Distance and Angle Table --------
For i = 1 To 1000
  dDistance.d = i
  Next 
dParts.d    =  0.5 
       For x = 0 To lScreenWidth -1      
  For y = 0 To lScreenHeight -1
    aDistance(x,y) = Int(dDistance * lTextureSize / Sqr( (x-lScreenWidth/2) * (x-lScreenWidth/2) + (y-lScreenHeight/2) * (y-lScreenHeight/2) )) % lTextureSize
    dAngle.d = (dParts * lTextureSize * ATon2(y-lScreenHeight/2, x-lScreenWidth/2) / #PI)
    aAngle(x,y) = Int (256 - dAngle) & 255
  Next
Next
dSpeedX.d = 5.0
dSpeedY.d = 5.0


Repeat
  ; ------- Stuff for doing the animation -------
  
  dAnimation.d = dAnimation.d + 0.005+ch1_size            ; timeGetTime_() / 1000
  If dAnimation.d >= 1.0 : dAnimation = 0.0 : EndIf
  
  lShiftX.l = Int(lTextureSize * dSpeedX.d * dAnimation.d)
  lShiftY.l = Int(lTextureSize * dSpeedY.d * dAnimation.d)

  ; -------- Calculate Texture coordinates and draw Tunnel -------
  image = CreateSprite (0, lScreenWidth, lScreenHeight)
  StartDrawing(SpriteOutput(0))
    For x = 1 To lScreenWidth -1
      For y = 1 To lScreenHeight-1
        lCoordinateX.l = (aDistance(x,y) + lShiftX) % lTextureSize     
        lCoordinateY.l = (aDistance(x,y)    + lShiftY) % lTextureSize   
        aBuffer(x,y) = aDistance (lCoordinateX.l , lCoordinateY.l) 
       Plot(x, y,RGB(255,0 ,aBuffer(x,y)))
           Next 
    Next
    StopDrawing()
    Global z
  help6.f=0   ; From ID_buffer2 to Screen with y deforming
  b=5
  For i=0 To 400                                        ;clip 400
    help6+0.6
    ClipSprite(0,0,i-ch0_size,600+48+48-ch2_size,20+ch1_size)
    help7.f    =GSin(angle+ help6*5 )*40   
    help7=help7+GSin(angle+(help6*2))*60
  
    DisplayTransparentSprite(0,0+help7-10+30,5+i+0-310,30); 
    DisplayTransparentSprite(0,-90+help7-10-20,5+i+0-310,30); 
   DisplayTransparentSprite(0,-70+help7-10,1+i+0+370,30); 
    DisplayTransparentSprite(0,70+help7-10,1+i+0+370,30); 
    If b>900000
       b=5
    EndIf
 Next
 r+0.085
    FlipBuffers()
     ClearScreen(0)
   Until GetAsyncKeyState_(#VK_ESCAPE)