Dark Bit Factory & Gravity
ARCHIVE => Archive => Cobra => Topic started by: Hotshot on May 14, 2008
-
I have fixed the error but my plamsa isnt working :-[
PROGRAM
uses pure2d,keyset
var
cosinus : Array[641] of integer
R : Array[64] of integer
G : Array[64] of integer
B : Array[64] of integer
MRGB : Array[256] of integer
i :integer
position :integer
c :integer
a :string
wave1,wave2,wave4,x,y:integer
plasma :element
Procedure Grahamplasma()
var
wave1,wave2,wave3,wave4:integer
x,y,f,d :integer
cosinus : Array[641] of integer
mrgb : Array[256] of integer
begin
wave1 = wave1 + 2
If wave1 >= 320 Then wave1 = 0
wave2 = wave2 + 2
If wave2 >= 320 Then wave2 = 0
wave3 = wave3 + 3
If wave3 >= 320 Then wave3 = 0
LockBuffer
For y = 0 To 319
d = cosinus[y + wave2] + cosinus[y + wave3]
For x = 0 To 319
f = cosinus[x + wave1] + cosinus[x + y] + d And $FF
PixelFast(x, y, ToRGBA(f,f,f))
Next
Next
UnlockBuffer
DrawImage (plasma,0,0)
END
Begin
OPENSCREEN
plasma=CreateImage(320,320)
position = 0
For c = 0 To 640
cosinus[c] = Cos((115*3.14159265358 * c) / 320) * 32 + 32
Next
For i=0 To 63
r[i]=i*4
g[i]=0
b[i]=255-(i*4)
Next
For i=0 To 63
r[i+64]=255-(i*4)
g[i+64]=i*2
b [i+64]=0
Next
For i=0 To 63
r[i+128]=i*2
g[i+128]=128-(i*2)
b[i+128]=i*4
Next
For i=0 To 63
r[i+192]=128+(i*2)
g[i+192]=i
b[i+192]=255-(i*4)
Next
For i=0 To 255
mrgb[i]=((r[i]*$10000)+(g[i]*$100)+b[i])And $FFFFFF
Next
// mainloop
While a<>27
a=GetKey()
Grahamplasma()
Flip
Wend
End
-
What is 'f'? Where do you define or set it to anything?
Also, is your screen really 320x320 or is it 320x240? 320x200? I think the 'y' For loop is wrong.
Jim
-
I have fixed the error and now it is working :)
What people think of it?
I will post EXE Files on here soon
PROGRAM
uses pure2d,keyset
var
cosinus : Array[641] of integer
R : Array[64] of integer
G : Array[64] of integer
B : Array[64] of integer
MRGB : Array[256] of integer
position :integer
a :string
wave1,wave2,wave3,wave4:integer
x,y,i,c,f,d :integer
plasma :element
Procedure Grahamplasma()
begin
wave1 = wave1 + 2
If wave1 >= 320 Then wave1 = 0
wave2 = wave2 + 2
If wave2 >= 320 Then wave2 = 0
wave3 = wave3 + 3
If wave3 >= 320 Then wave3 = 0
LockBuffer
For y = 0 To 319
d = cosinus[y + wave2] + cosinus[y + wave3]
For x = 0 To 319
f = cosinus[x + wave1] + cosinus[x + y] + d And $FF
PixelFast(x, y, ToRGBA(f,f,f))
Next
Next
UnlockBuffer
DrawImage (plasma,0,0)
END
Begin
OPENSCREEN
plasma=CreateImage(320,320)
position = 0
For c = 0 To 640
cosinus[c] = Cos((115*3.14159265358 * c) / 320) * 32 + 32
Next
For i=0 To 63
r[i]=i*4
g[i]=0
b[i]=255-(i*4)
Next
For i=0 To 63
r[i+64]=255-(i*4)
g[i+64]=i*2
b [i+64]=0
Next
For i=0 To 63
r[i+128]=i*2
g[i+128]=128-(i*2)
b[i+128]=i*4
Next
For i=0 To 63
r[i+192]=128+(i*2)
g[i+192]=i
b[i+192]=255-(i*4)
Next
For i=0 To 255
mrgb[i]=((r[i]*$10000)+(g[i]*$100)+b[i])And $FFFFFF
Next
// mainloop
While a<>27
a=GetKey()
Grahamplasma()
Flip
Wend
End
Screenshot
(http://img218.imageshack.us/img218/4651/cobrapicbg0.th.jpg)
EXE FILES
http://www.uploading.com/files/B3VBIH8V/PLASMA.rar.html
http://www.megafileupload.com/en/file/64257/PLASMA-rar.html
-
I get diagonal lines with palette-overflow and it crashes on 'esc'.
-
Sorry Hellfire. what do you think of it?
-
Some suggestions:
Clamp the colours (instead of wrapping by "AND $FF") or use a repeatable colour-lookup-table.
The "plasma" (the two cosines) should have more variation (multiple waves of different amplitude and frequency).
Pick tasteful colours.
The diagonal lines make it look somewhat "buggy".
An easy way to make it look much more interesting is to not only compute one value (used to look up a colour from a 1d palette), but calculate two different values (x,y) and pick the resulting colour from a 2d texture.
-
I had the same result as Hellfire and it actually crashed on exit. To be honest it doesn't look like a plasma, Cobra is not a good language to use for this style of effect anyway, it's too slow for pixelwise stuff.
You'd be better off using another language for a start and then reading some tutorials of making raster bars and work your way along to making plasmas.
Here is an example of something simple in freebasic.. If you upped the ante a little bit and used opengl you'd find it even easier too!
'
' Plasma thing by shockwave
'
'-------------------------------------------------------------------------------
OPTION STATIC
OPTION EXPLICIT
' SCREEN RES
CONST XRES = 640
CONST YRES = 480
' GRID RES
CONST GRID = 4
DIM SHARED AS INTEGER WXRES
DIM SHARED AS INTEGER WYRES
WXRES = XRES / GRID
WYRES = YRES / GRID
' INCLUDES
#INCLUDE "TINYPTC_EXT.BI"
#INCLUDE "WINDOWS.BI"
'-------------------------------------------------------------------------------
' VARIABLES
DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )
DIM SHARED AS UINTEGER WBUFFER ( WXRES * WYRES )
dim shared as double fuckfuck(xres)
DIM SHARED AS UINTEGER COL_PAL(10000)
DIM SHARED AS DOUBLE GADD,GADD2
'-------------------------------------------------------------------------------
' SUBS
DECLARE SUB BLIT_BUFFER()
DECLARE SUB PRECALC()
DECLARE SUB PLASMA()
'-------------------------------------------------------------------------------
' OPEN SCREEN
PTC_ALLOWCLOSE(0)
PTC_SETDIALOG(0,"",0,0)
IF (PTC_OPEN("PLASMA",XRES,YRES)=0) THEN
END-1
END IF
PRECALC()
'-------------------------------------------------------------------------------
' MAIN LOOP;
'-------------------------------------------------------------------------------
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<>-32767)
GADD=GADD-1.5
GADD2=GADD2-1.4
PLASMA()
BLIT_BUFFER()
PTC_UPDATE@BUFFER(0)
WEND
END
SUB PLASMA()
DIM AS INTEGER YY,XX,VALL,QQ,RR
dim as double ll,mm
for xx=0 to xres
fuckfuck(xx)=171+50*sin((GADD+xx)/39)
next
FOR YY=0 TO WYRES-1
QQ = 599 * SIN (( GADD2 + YY) /69)
rr = 599 * SIN (( GADD - YY) /87)
mm=171+50*sin((GADD+yy)/237)
FOR XX=0 TO WXRES-1
VALL = 5000+(2499*cos((gadd2-YY+QQ)/fuckfuck(xx))+2499*SIN((gadd-YY+rr)/mm))
WBUFFER(XX+(YY*WXRES))=COL_PAL(VALL)
NEXT
NEXT
END SUB
SUB PRECALC()
DIM X AS INTEGER
DIM AS DOUBLE RR,GG,BB
RR=125
GG=125
BB=125
FOR X=0 TO 10000
rr=125+124*sin(X/1813)
gg=125+124*sin((X+1000)/1813)
bb=125+124*sin((X+2000)/1813)
COL_PAL(X) = RGB( INT(RR),INT(GG),INT(BB) )
NEXT
END SUB
'-------------------------------------------------------------------------------
' DRAWS THE SCREEN ACCORDING TO WHAT IS IN WBUFFER.
'-------------------------------------------------------------------------------
SUB BLIT_BUFFER()
DIM AS INTEGER XX,YY,Y2,SLICE,tc
DIM PP AS UINTEGER PTR
FOR YY=0 TO WYRES-1
FOR XX=0 TO WXRES-1
FOR Y2=0 TO GRID-1
pp=@buffer((XX*GRID)+(((YY*GRID)+Y2)*XRES))
SLICE = GRID
TC=WBUFFER(XX+(YY*WXRES))
asm
mov eax,dword ptr[TC]
mov ecx, [SLICE]
mov edi, [PP]
rep stosd
end asm
NEXT
NEXT
NEXT
END SUB
-
1MB? Wow, This is actually the first time I'v taken a look at some Cobra source code I see similarities to pascal and basic which I actually think is a great combination. I can only say that you might want to use something like this ...
f = cosinus[x + wave1] + cosinus[x + y] + d And $FF
PixelFast(x, y, ToRGBA(f,255,f))
for red, green and blue calculated separately, atm red = blue and green is fixed at 255, Plasma needs to be multi colour, also IMO at least one of the colours should be done outside the loop maybe green to let one colour change more slowly than the others, I think lodes graphics tutorials is the best code to look at because it gives you more than one way to skin the cat, Im using those tutorials myself at the moment
http://student.kuleuven.be/~m0216922/CG/plasma.html
-
If you upped the ante a little bit
Eh? Do you mean If I keep the good work up?
I'll have go at Freebasic and I already made 3D Starfield( the files size was just 10K ;) ) in other post.
Rain_Storm:
thank for link for plasma.