Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Shockwave on May 11, 2006
-
Taken from the old board, original post by Shockwave.
Here's a quick plasma code for you;
;-------------------------------------------------
;
; Quick ' N simple plasma coded by Shockwave ^ DBF
;
;-------------------------------------------------
; Vars;
;-------------------------------------------------
Global xres = 320
Global yres = 240
Global genadd1 = 0
Global genadd2 = 0
Const escape = 1
;-------------------------------------------------
; Set Up GFX mode;
;-------------------------------------------------
Graphics xres,yres,32,1
SetBuffer BackBuffer()
;-------------------------------------------------
; Set up sine tables;
;-------------------------------------------------
Dim sintable#(2880)
Dim costable#(2880)
For a=1 To 2880
sintable#(a) = Sin(Float(a))
costable#(a) = Cos(Float(a))
Next
;-------------------------------------------------
; Pre-calculate plasma colours
;-------------------------------------------------
Dim screenarray(xres,yres)
Dim colourtable(1024)
create_plasma_colours()
;-------------------------------------------------
; Loop starts.
;-------------------------------------------------
While Not KeyDown(escape)
plasma()
Flip
Cls
Wend
End
;-------------------------------------------------
; Loop ends.
;-------------------------------------------------
;-------------------------------------------------
; This function draws a plasma.
;-------------------------------------------------
Function plasma()
;-------------------------------------------------
Local loopx,loopy; Loop variables.
Local cv1,cv2,ca,ca2; Used in calculations.
;-------------------------------------------------
genadd1=genadd1+4; Change these additions
genadd2=genadd2+3; For different speed X+Y.
If genadd1>360 genadd1=genadd1-360
If genadd2>360 genadd2=genadd2-360
;-------------------------------------------------
ca1 = 50+49*costable(genadd1); You can play with these vars.
ca2 = 50+49*sintable(genadd2); Strange things may happen though.
;-------------------------------------------------
; Calculate the plasma and store it, it's stored in case
; you want to do any pixel wise effects in the same screen
; array so it only needs to be drawn once.
;-------------------------------------------------
For loopy = 1 To yres - 1
cv1 = 205+Int(ca1*sintable(genadd2+loopy))
For loopx = 1 To xres - 1
cv2 = 400+Int(ca2*costable(genadd1+loopx))
screenarray(loopx,loopy) = cv1+cv2
Next
Next
;-------------------------------------------------
; Render the screen array.
;-------------------------------------------------
LockBuffer BackBuffer()
For loopy = 1 To yres - 1
For loopx = 1 To xres - 1
WritePixelFast loopx,loopy,colourtable(screenarray(loopx,loopy))
Next
Next
UnlockBuffer BackBuffer()
;-------------------------------------------------
End Function
;-------------------------------------------------
;-------------------------------------------------
; Precalculate some colours;
;-------------------------------------------------
Function create_plasma_colours()
Local colourload
Local basered=0
Local basegreen=0
Local baseblue=0
Local colourpixel
Local redbounce = 0
Local greenbounce = 0
Local bluebounce = 0
;-------------------------------------------------------------------------------------------------------
For colourload=1 To 1024
;-------------------------------------------------------------------------------------------------------
If redbounce=0 Then
basered=basered+2
If basered>255 basered = 255:redbounce=1
End If
;-------------------------------------------------------------------------------------------------------
If greenbounce=0 And colourload>512 Then
basegreen=basegreen+1
If basegreen>255 basegreen= 255: greenbounce=1
End If
;-------------------------------------------------------------------------------------------------------
If bluebounce=0 Then
baseblue=baseblue+1
If baseblue>255 baseblue = 255:bluebounce=1
End If
;-------------------------------------------------------------------------------------------------------
If redbounce=1 Then
basered=basered-3
If basered<0 basered = 0:redbounce=0
End If
;-------------------------------------------------------------------------------------------------------
If greenbounce=1 Then
basegreen=basegreen-1
If basegreen<0 basegreen= 0: greenbounce=0
End If
;-------------------------------------------------------------------------------------------------------
If bluebounce=1 Then
baseblue=baseblue-1
If baseblue<0 baseblue = 0:bluebounce=0
End If
;-------------------------------------------------------------------------------------------------------
; Calculate colour and store;
;-------------------------------------------------------------------------------------------------------
colourpixel=(((basered Shl 8)+basegreen) Shl 8)+baseblue
colourtable(colourload)=colourpixel
Next
;-------------------------------------------------------------------------------------------------------
End Function