Created
October 11, 2021 20:56
-
-
Save SIRprise/2449a6fa88c82f40a3e8627703cb4e93 to your computer and use it in GitHub Desktop.
PureBasicGraphicsTest.pb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ScreenWidth = 1024 ; Feel free to change this to see the pixel filling speed ! | |
#ScreenHeight = 768 | |
If InitSprite() = 0 Or InitKeyboard() = 0 | |
MessageRequester("Error", "DirectX is needed.",0) | |
EndIf | |
Structure Pixel | |
Pixel.l | |
EndStructure | |
Procedure.f GSin(angle.f) | |
ProcedureReturn Sin(angle*(2*3.14/360)) | |
EndProcedure | |
; Pre-calculated values are faster than realtime calculated ones... | |
; ... so we save them in an array before starting gfx operations | |
Dim CosTable(#ScreenWidth*2) | |
Dim ColorTable(255) | |
For i = 0 To #ScreenWidth*2 | |
CosTable(i) = GSin(360*i/320)* 32 + 32 | |
Next | |
If OpenWindow(0, 0, 0, #ScreenWidth, #ScreenHeight, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) | |
If OpenWindowedScreen(WindowID(0),0,0,#ScreenWidth, #ScreenHeight) | |
SetFrameRate(30); | |
Define xp.w=30, yp.w=30, sx.b = 5, sy.b = 6 | |
Repeat | |
;----------------------- | |
Wave+6 | |
If Wave > 320 : Wave = 0 : EndIf | |
If StartDrawing(ScreenOutput()) | |
Buffer = DrawingBuffer() ; Get the start address of the screen buffer | |
Pitch = DrawingBufferPitch() ; Get the length (in byte) took by one horizontal line | |
PixelFormat = DrawingBufferPixelFormat() ; Get the pixel format. | |
If PixelFormat = #PB_PixelFormat_32Bits_RGB | |
For i = 0 To 255 | |
ColorTable(i) = i ; Blue is at the 3th pixel | |
Next | |
Else ; Else it's 32bits_BGR | |
For i = 0 To 255 | |
ColorTable(i) = i << 16 ; Blue is at the 1th pixel | |
Next | |
EndIf | |
For y = 0 To #ScreenHeight-1 | |
pos1 = CosTable(y+wave) | |
*Line.Pixel = Buffer+Pitch*y | |
For x = 0 To #ScreenWidth-1 | |
pos2 = (CosTable(x+Wave) + CosTable(x+y) + pos1) | |
*Line\Pixel = ColorTable(pos2) ; Write the pixel directly to the memory ! | |
*Line+4 | |
Next | |
Next | |
Circle(xp,yp,10,RGB(255,255,255)); | |
xp=xp+sx; | |
yp=yp+sy; | |
If (xp > (#ScreenWidth -30)) Or (xp<30) | |
sx = -sx | |
EndIf | |
If (yp > (#ScreenHeight -30)) Or (yp<30) | |
sy = -sy | |
EndIf | |
;------------------------ | |
StopDrawing() | |
EndIf | |
ExamineKeyboard() | |
FlipBuffers() | |
Until KeyboardPushed(#PB_Key_Escape) | |
Else | |
MessageRequester("Error","Can't open the screen !",0) | |
EndIf | |
EndIf | |
End | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment