Written for Pixel Outlaw and for piece of mind, also proved a little tease to convert.
Demonstrating the use of the old familar WritePixel ( no WPF sidekick ) in it's new disguise in BMAX.
'
' Ze BMAX WritePixel + PixelMap Plasma Experiment
' Based On B2D examples courtesy of Alan MacDonald And Zawran
' Converted And Adapted by Clyde "A Little Fuzzy Wuzzy" Radcliffe
'
' For pixelwize operations, use bitwize AND aka &, plus bitwize OR aka | ( only work with Int's )
' Needs an alpha bit value set To see fx.
'
' NB: Please Improve "Not Quite There Yet But It's An Improvement To When BMAX Came Out" Manual.
' IDE: Needs ability to select and drag lines of code as per other Blitz IDE's.
'
' On Monday June 6th 2009
'
Strict
Const XRES:Int=640
Const YRES:Int=480
Const PIE:Float=3.14159
Global Depth:Int=0
Graphics XRES,YRES,Depth
HideMouse
Global Plasma_Image:TImage
Global Palette_Image:TImage
Global Plasma_Palette: Int [ 256 ]
Global Plasma_Pattern: Float [ 1500 ]
Global Plasma_Wave1, Plasma_Wave2, Plasma_Wave3: Int
Initialize_Plasma()
Run_Plasma()
End
Function Create_Palette( red_inc:Int=0, grn_inc:Int=45, blu_inc:Int=90, spread:Int=360)
Local index, div, red, grn, blu:Int
For index=0 To 255
div = ( index*spread / 255 )
red = Cos( div+red_inc ) *127+127
grn = Cos( div+grn_inc ) *127+127
blu = Cos( div+blu_inc ) *127+127
Plasma_Palette[ index ]=( red Shl 16 ) | ( grn Shl 8 ) | blu
Next
End Function
Function Draw_Palette( Image:TImage )
Local a: Int
Local r,g,b: Int
Local image_buffer:TPixmap=LockImage( Image )
For a=0 To 255
WritePixel( image_buffer, a, 0, Plasma_Palette[ a ] )
Next
UnlockImage( Image )
End Function
Function Initialize_Plasma()
Local a,x,y: Int
Plasma_Image=CreateImage(320,240, dynamicimage )
Create_Palette( 10,45,90 )
Palette_Image=CreateImage(255,1)
For a=0 To 1499
Plasma_Pattern[ a ] = Sin( ( 115*PIE * a ) / (XRES/2) ) * 128 + 128
Next
End Function
Function Run_Plasma()
While Not KeyHit(27)
Cls
Update_Plasma( Plasma_Image,1,1,2 )
SetScale 2,2
DrawImage Plasma_Image,0,0
'SetScale 1,1
'Draw_palette( Palette_Image )
'DrawImage Palette_Image
If KeyHit(KEY_RETURN) Then
Depth=32-Depth
Graphics XRES,YRES,Depth
HideMouse
FlushKeys
End If
Flip
Wend
End Function
Function Update_Plasma( Image:TImage, Wave_Inc1:Int=1, Wave_Inc2:Int=2, Wave_Inc3:Int=3 )
Local x,y, col1, col2: Int
Local Image_Buffer:TPixmap=LockImage( Image )
For y=0 To ImageHeight( Image )-1
Col1 = Plasma_Pattern[ y + Plasma_Wave2 ] + Plasma_Pattern[ y + Plasma_Wave3 ]
For x= 0 To ImageWidth( Image )-1
Col2 = (Plasma_Pattern[ x + Plasma_Wave1 ] + Plasma_Pattern[ x + y ] + Col1 )
WritePixel( Image_Buffer, x, y, Plasma_Palette[ Col2 &255 ] | $FF000000 )
Next
Next
UnlockImage( Image )
'
' Update the Plasma sinewave.
'
Plasma_Wave1:+ Wave_Inc1
Plasma_Wave2:+ Wave_Inc2
Plasma_Wave3:+ Wave_Inc3
If Plasma_Wave1 => (XRES-1) Then Plasma_Wave1:- (XRES-1)
If Plasma_Wave2 => (XRES-1) Then Plasma_Wave2:- (XRES-1)
If Plasma_Wave3 => (XRES-1) Then Plasma_Wave3:- (XRES-1)
End Function
Hope its usefull to demo fans with Blitz Max.