Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Clyde on June 08, 2009
-
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.
-
Exe please? :)
-
I have compiled it and attached an exe.
-
Yeah I enjoyed this very much!
-
Nice, I liked that a lot. :clap:
-
Thanks Zawran & Co. !!!
PO: Notice I fixed the palette bug :)
Inbetween imagebuffer:Pixmap=LockImage( Image ) and unlockImage( image ), where the writepixel command is, you can do a mountain of stuff thats allready been posted on these very pages Blitz And FreeBASIC ( some cases you may need to turn the sin / cos parts back into degrees ).
Also remember to set the alpha channel. Ive used in this example | $FF000000, where $FF= ( 255 shl 24 )
-
Rocks, Clyde dude!
-
Cheers for compiling that Zawran, I liked this too, runs smooth and nice :)
Well done Clyde.
-
Thankyou mate.
I have used an old trick for those who havent spotted it, of drawing into a screen area of half the width and height of the graphics display, and then used the built in graphics command of setscale 2,2.
If anyone wants to see some more stuff converted like Blitz2D WritePixelFast give us a PM, it would give me an excuse to use my Blitz Max, as i havent done a busting lot with it and would be a break from the norm.
Oh, and if you press Return / Enter it'll toggle between windowed and full screen modes.
-
Clyde suggested we move hellfire's code to the C++ section, so here is a link. A bit more organized this way.
http://www.dbfinteractive.com/forum/index.php/topic,4102.msg54939.html#new
-
In the lacklustre manual / reference guide of sorts for BMAX, there is a small tit bit on a pixmap ptr, anyone ever used this approcah before? If so, how'd the plamsa code look?
Cheers,
Clyde.
-
You use the PixmapPixelPtr:Byte Ptr( pixmap:TPixmap,x=0,y=0 ) function to get a byte pointer. You will have to change your code to storing the colors as bytes. Then you take the y position and multiply by 4 and then multiply that result by the width of the pixmap. Then you add the x position multiplied by 4. Now you you have the location of the first bytes of the four where you want to put your color values.
-
impressing looking plasma. sorry for digging up an old thread but since this interests me i assume it'll interest any other budding demo coders.
Also in case its helpfu I use this code for ploting bytes as recalculating the y pixel position in bytes can slow down your code needlessly.
The code below is for 1byte=1pixel. ie anything of 256 colours or less.
'Screen Y LUT for speed in 8 bit gfx ops
dim tmpsd as uinteger=0
DIM SHARED AS INTEGER YLUT(0 TO SCREENH-1)
For i as integer = 0 TO SCREENH-1
YLUT(i) = tmpsd : tmpsd +=SCREENW
Next
The code below is for 4byte=1pixel. ie 32 bit.
'Screen Y LUT for speed in 32 bit gfx ops
dim tmpsd as uinteger=0
DIM SHARED AS INTEGER YLUT(0 TO SCREENH-1)
For i as integer = 0 TO SCREENH-1
YLUT(i) = tmpsd : tmpsd +=SCREENW*4
Next ' Makes a LUT for line offsets in bytes