Dark Bit Factory & Gravity
ARCHIVE => Archive => Cobra => Topic started by: Clyde on January 08, 2007
-
Here's an experiment with Cobra, which is the plasma routine adapted and featured in the Gravity Dimenisons series. Thanks go to Alan MacDonald for the inspiration with the method.
//
// Plasma Effect.
// By Clyde January '07
//
program uses pure2d,keyset
Const
XRES=640
YRES=480
Var
cs:Array[ 3000 ] Of Integer
sn:Array[ 3000 ] Of Integer
a,c:Real
Procedure InitializePlasma()
Var a
Begin
For a=0 To 3000
CS[ a ] = Cos( a )*85
SN[ a ] = Sin( a )*85
Next
End
Procedure UpdatePlasma()
var
d,b
red,grn,blu,col
x,y
//
// Update the plasma movement.
//
Begin
a = a + 1
c = c - 2
If a < 0 Then a=a+360
If a > 360 Then a=a-360
If c < 0 Then c=c+360
If c > 360 Then c=c-360
d = a
b = c
//
// Draw the plasma effect on the texture.
//
For y = 0 To YRES-1
d = d + 4
b = b + 2
For x = 0 To XRES-1 //Step 2
Red = Abs(CS[d+x] + SN[y+x] + CS[b])*2
Grn = Abs(CS[d+x] + SN[y+x] + CS[b])*1
Blu = Abs(CS[d+x] + SN[y+x] + CS[b])*3
If Red>255 then Red=255
If Grn>255 then Grn=255
If blu>255 then Blu=255
Col = ( Red Shl 16) Or ( Grn Shl 8 ) Or ( Blu )
PixelFast(x,y, Col )
Next
Next
End
//End
Procedure RunPlasma()
Begin
OpenScreen(XRES,YRES)
While Not KeyDown(VK_Escape)
Cls
UpdatePlasma()
Flip
Wend
End
//End
Begin
InitializePlasma()
RunPlasma()
End
I can't judge what the overal speed is with these snippets, as I am using a demo version - which runs in a window, and seems to have debug mode turned on; so it makes for really slow visuals my end. If anyone has the full version of Cobra, I'd be very interested in seeing the results in a full screen application.
Anyhows I hope these prove a bit useful to anyone who is learning ( like myself ), or thinking about looking into Cobra.
Cheers and all the very best,
Clyde.
-
Cool :) I'll give it a try when I get home. So far I have been lazy with learning Cobra, but I spose leaning C is a bit more of a priority for me at the moment.
-
Nice one Clyde. I'm going to download the demo of Cobra at some point this week so I can run your listings.
-
No worries and thanks. Im going to post more up as and when I do them.
The only draw back to the demo version is that, it runs in a window with debug on so they run a tad slow, and there's limited content in the help. It is quite fun dabbling in, and has a nice IDE.
-
He he, glad you like it :D
Full release is very soon....
Anyway, enough plugging, here is another 'plasma' you may find interesting.
Not as pretty as the one above, but may prove a nice starting point for some demo stuff as it uses the paletted bitmap.
program
uses pure2d,keyset
const
width=640
height=480
var
i,x,y : integer
col:integer
t1,t2:integer;
begin
openscreen(width,height)
for i = 0 to 255
palette(i,torgba(sin(i*(359.0/255.0))*127+128,sin((i*2)*(359.0/255.0))*127+128,sin((i*3)*(359.0/255.0))*127+128))
next
for x = 0 to width-1
for y = 0 to height-1
col= ((sin(y+(2*x)))+(sin(x)*4))*127+128
pixelp(x,y,col mod 256)
next
next
while not keydown(vk_escape)
t1 = MILLISECS;
pal2bmp
shiftpalette(1)
t2 = MILLISECS;
text(0,0,'Time:'+(t2-t1))
flip
wend
closescreen
end
interesting thing about paletted mode, is that any image can have one (autocreated first time you write to it using pixelP). So, cheeky demo coders, can use the standard bitmap, and hide values (0-255) behind pixels. Not exactly sure what you could use it for (maybe heightmap info, or maybe 2 4bit offsets for doing warps), but I'm sure people will get creative with it...
-
Neat dude 8)
-
Thanks for the plasma Graham :) :clap:
Always nice to see demo effects coded in as many languages as possible!
-
Just got around to testing these and they both look real nice. Grahams one runs very smoothly too :)
-
Grahams one is using colour cycling, that's why it's so smooth :)
I can't honestly say what I think though, the ide looks nice, it's a shame that it's in debug mode.. I might be tempted to write something if I could get a decent turn of speed, or maybe I will soon anyway.
The ability to rotate the palette is very nice.
-
he he, my miggy/c64 roots showing :D
Sorry about the debug mode, but with making the demo not timeout, It is one of the ways to get people to buy.
I still feel it's reasonably fast in debug mode, certainly enough to evaluate it (which is what the demo is all about after all), but for people to get an idea of the speed without, I'm going to post some of the examples compiled without debug, so people can compare them.
I've been looking at some of the demo's / techniques on your site, and I'm going to add some features which make some of them easier (eg. resetting the alpha channel of a complete image, allowing HSL->RGB conversion etc)... So, I'd be really interested in what people over here do with Cobra :D
-
Some examples would be great :)
I'll see if I can make some nice effects in the meantime :) I can think of at least 30 that can be done with colour cycling!!
-
oooh.. can't wait.
I'm hoping to get a final demo (with the new features) out after the weekend, which I'm hoping will be the same time as it going up for sale!
I've got a nice, voxel demo with movement blur running at a decent rate.
I 'think' I have a bit of trouble with paletted mode inside sprites, but as long as you are just doing image stuff they should be fine.