Wibbly Wobbly Timey Wimey (Source Included)

BlitzMax Forums/BlitzMax Programming/Wibbly Wobbly Timey Wimey (Source Included)

dw817(Posted 2015) [#1]
As I'm working on a busy game maker, I was curious about the graphic animated background you can see on the Sony Playstation 3 and the Sony PSP. A trailing stream of animated and wavy lines. Something nice to see while you contemplated your tiles and sprites.

While I haven't been able to match it, I did write this, which I think is a bit interesting in itself.

' Wibbly Wobbly Timey Wimey
' An experiment in ambient image backgrounds
' Written by David W (12-15-15)
' Updated 12-30-15
Strict
SetGraphicsDriver(GLMax2DDriver()) ' NECESSARY FOR AGGRESSIVE PIXEL READING & WRITING
Graphics 1024,768
SetBlend lightblend
AutoMidHandle 1
Local i,bgswirl,img_stripe:TImage=CreateImage(256,256)
For i=0 To 256 Step 8
  DrawLine i,0,i,256
  DrawLine 0,i,256,i
Next
GrabImage img_stripe,0,0
Repeat
  SetAlpha .008
  SetClsColor Sin((bgswirl+500)/2000.0)*64.0,Sin((bgswirl+500)/4000.0)*64.0,Sin((bgswirl+750)/6000.0)*64.0
  Cls
  For i=-256 To 1024+256 Step 2
    SetRotation bgswirl*.0005
    DrawImage img_stripe,i,Sin(bgswirl/2000.0+(i/8.0))*200.0+350.0
    If i Mod 4=0
      bgswirl:+1
    EndIf
  Next
  Flip -1
Until KeyDown(27)



BlitzSupport(Posted 2015) [#2]
Whoa, nice! I wouldn't have figured out how to do that in a million years!


Floyd(Posted 2015) [#3]
It's hard to visualize how this works. This slightly modified version let's you see, sort of, what is happening.

Graphics 1024,768
SetBlend lightblend
AutoMidHandle 1
Local i,bgswirl,img_stripe:TImage=CreateImage(256,256)
For i=0 To 256 Step 8
  SetColor 0,0,255
  DrawLine i,0,i,256
  SetColor 100, 100, 0
  DrawLine 0,i,256,i
Next
SetColor 255,255,255
GrabImage img_stripe,0,0
Repeat
'  SetAlpha .008
'  SetClsColor Sin((bgswirl+500)/2000.0)*64.0,Sin((bgswirl+500)/4000.0)*64.0,Sin((bgswirl+750)/6000.0)*64.0
  Cls
  For i=-256 To 1024+256 Step 16 ' so we can see individual lines
    SetRotation bgswirl*.0005
    DrawImage img_stripe,i,Sin(bgswirl/2000.0+(i/8.0))*200.0+350.0
    bgswirl:+1
  Next
  Flip
  Flip
Until KeyDown(27)


Some of the "op art" effects reminded me of an earlier experiment, in Blitz3D.

; May 8 2015 there was a question about strange antialiasing effects which were very sentitive to scale.
; I thought perhaps "Moire" was the underlying cause. Anyway, here are some odd effects which
; would never be guessed without prior experience.

; Note the checkerboard texture never changes. All the apparent motion is from interactions
; between the grid of texture texels and the grid of screen pixels. 

Graphics3D 600, 600, 0, 2
HidePointer

chex = CreateTexture(512,512)   ; black and white checkerboard, 1x1 squares.
SetBuffer TextureBuffer( chex )
For x = 0 To 511 Step 2
	For y = 0 To 511 Step 2
		WritePixel x,y, $FFFFFFFF
	Next
Next
SetBuffer BackBuffer()

spr = CreateSprite()
EntityTexture spr, chex

cam = CreateCamera()

ClearTextureFilters 

; The various magic numbers, 0.001 etc, were chosen for my 1920 x 1080 screen.

For z# = -4 To -1.2 Step 0.001
	PositionEntity cam, 0, 0, z
	RenderWorld
	Flip
Next

For a# = 1 To 88 Step 0.03
	RotateSprite spr, a
	RenderWorld
	Flip	
Next

For n = 1 To 2500
	MoveEntity spr, 0.0001, 0, -0.00004
	RenderWorld
	Flip
Next
WaitKey



dw817(Posted 2015) [#4]
Floyd:

* (Breaks out the 3D goggles and starts a dubstep) :)
BTW, to speed up the motion of the wave, use a lower STEP rate, with 16 it will take a LONG time for it to move up and down the screen.

Change the line, "bgswirl:+1" to "bgswirl:+10" for better movement and an added animated effect of shooting squares.

Captainpool:

* I can't get this to run in BlitzMAX. Now the main reason I chose BlitzMAX is because of its very smooth graphics and motion and the effect that it uses very little of the CPU. This program alone uses 3% of my CPU (checking Process Explorer).

If there is a programming language that offers better graphics and can keep those 2-values, (1) smooth animation and (2) little to no CPU usage (for like a program above), I might be tempted to investigate it for my key projects.

BlitzSupport:

* You're welcome to add it to graphic toys. My biggest problem with BlitzMAX is the serious lack of submitted code. BlitzBASIC rules the roost and I still have yet to know how to access the MCI properly where I can ask questions like playing a MIDI or WMA and the ability to retrieve or set the position it is playing at.

What =IS= the big difference between all the programming languages provided by BLITZ and which one would cover my needs, smooth animation, easy coding, and very little CPU usage for loops with FLIP.