Just try! You'll see it's not so difficultliam wrote:wow, i cant believe you can do so much with such little code in PB!
you guys are sick!

Code: Select all
DisableDebugger:InitSprite():InitKeyboard():Dim CosTable.l(1599):Dim ColorTable.l(255):For i.w=0 To 1599:CosTable(i)=Sin(9/8*i*#PI/180.)*32+32:Next:OpenScreen(800,600,32,"Plasma")
StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:Pitch=DrawingBufferPitch():For i=0 To 255:ColorTable(i)=i:Next:StopDrawing():FlipBuffers()
Repeat:ExamineKeyboard():If *Buffer2<>*Buffer:StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:StopDrawing():EndIf
For y.l=0 To 599:pos1.l=CosTable(y+wave):*Line.long=*Buffer+Pitch*y:For x.l=0 To 799:*Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1):*Line+4:Next:Next:Wave+6:If Wave>320:Wave=0:EndIf
Delay(16):Until KeyboardPushed(#PB_Key_Escape)
Sorry but that's exactly what makes it crash herePsychophanta wrote:Plasma, based in an example from PB team, but arranged by me in 2 important aspects:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.
Well, putting the StartDrawing()/DrawingBuffer() bit _inside_ the loopPsychophanta wrote:Oh! here it works like a charm!
May be pure luck or what?
I really doubt any of those arrangements are the cause of a crash :roll:
Code: Select all
InitSprite()
InitKeyboard()
If OpenScreen(800,600,32,"Plasma")=0
Debug "Can't create screen"
End
EndIf
StartDrawing(ScreenOutput())
If DrawingBufferPixelFormat()&(#PB_PixelFormat_32Bits_RGB|#PB_PixelFormat_32Bits_RGB)=0
Debug "No 32 bits screen mode available"
End
EndIf
StopDrawing()
Dim CosTable.l(1599)
Dim ColorTable.l(255)
For i.w=0 To 1599
CosTable(i)=Sin(9/8*i*#PI/180.)*32+32
Next
If DrawingBufferPixelFormat()=#PB_PixelFormat_32Bits_RGB
For i=0 To 255
ColorTable(i)=i
Next
Else
For i=0 To 255
ColorTable(i)=i<<16
Next
EndIf
Repeat
ExamineKeyboard()
StartDrawing(ScreenOutput())
*Buffer=DrawingBuffer()
Pitch=DrawingBufferPitch()
For y.l=0 To 599
pos1.l=CosTable(y+wave)
*Line.long=*Buffer
For x.l=0 To 799
*Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1)
*Line+4
Next
*Buffer+Pitch
Next
Wave+6
If Wave>320
Wave=0
EndIf
StopDrawing()
FlipBuffers(1)
Until KeyboardPushed(#PB_Key_Escape)
End
Code: Select all
;Should only work with PB4.30b5
SetPriorityClass_( GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
End
EndIf
If OpenScreen(640, 480, 32, "Sprite")
CreateSprite(0, 128, 128, #PB_Sprite_Texture)
StartDrawing(SpriteOutput(0))
a.f = 0
For y = 0 To 127
For x = 0 To 127
vx.f = x - 64
vy.f = y - 64
dist.f = Sqr(vx * vx + vy * vy)
If dist = 0 : dist = 0.0001 : EndIf
If dist < 64
vx = vx / dist
vy = vy / dist
c = 128 + 128 * ACos(vx * vy)
Plot(x, y, RGB(c, $55, c/2))
EndIf
Next x
Next y
StopDrawing()
CopySprite(0, 1)
CreateSprite3D(0, 0)
SetFrameRate(60)
SetRefreshRate(60)
frame_counter = 0
Repeat
ClearScreen(RGB($55, 0, $55))
If Start3D()
RotateSprite3D(0, frame_counter * 5, 0)
For u=0 To 255 Step 1
x = 150 * Sin((frame_counter * 2 + u) / 50)
DisplaySprite3D(0, 256 + x, u, 255 * Sin(u * #PI / 256))
ZoomSprite3D(0, 64, 32 + u/2)
RotateSprite3D(0, 5, 1)
Next u
Stop3D()
EndIf
; Delay(15)
FlipBuffers(1)
frame_counter + 1
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "Can't open a 640*480 - 32 bit screen !", 0)
EndIf
End