Image noise: Difference between revisions

Content added Content deleted
m (→‎{{header|PureBasic}}: Update to 320x240 and showing output)
m (→‎{{header|PureBasic}}: Increased FPS by running without synchronization)
Line 248: Line 248:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>#filter=0.02
<lang PureBasic>#filter=0.2 ; Filter parameter for the FPS-calculation
#UpdateFreq=100 ; How often to update the FPS-display
#Flags =#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget


If OpenWindow(0,#PB_Ignore,#PB_Ignore,320,240,"PureBasic",#Flags)
OpenWindow(0,400,300,320,240,"PureBasic")
Define w=WindowWidth(0), h=WindowHeight(0)
SmartWindowRefresh(0,#True)
Define x, y, T, TOld, FloatingMedium.f, cnt
AddWindowTimer(0,0,1)
InitSprite()
Repeat
OpenWindowedScreen(WindowID(0),0,0,w,h,1,0,0,#PB_Screen_NoSynchronization)
Define x, y, dT, T, TOld, FloatingMedium.f, cnt
Repeat
Define Event=WaitWindowEvent()
cnt+1
Select Event
StartDrawing(ScreenOutput())
Case #PB_Event_Timer
For y=0 To h-1
Define w=WindowWidth(0), h=WindowHeight(0)
CreateImage(0,w+1,h+1)
For x=0 To w-1
StartDrawing(ImageOutput(0))
If Random(1)
For y=0 To h
Plot(x,y,#Black)
For x=0 To w
Else
If Random(1)
Plot(x,y,#White)
EndIf
Plot(x,y,#White)
EndIf
Next
Next
Next
StopDrawing()
Next
FlipBuffers()
StopDrawing()
cnt+1
TOld=T: T=ElapsedMilliseconds()
If cnt>=#UpdateFreq
dT=(T-TOld)
cnt=0: TOld=T: T=ElapsedMilliseconds()
If dT
FloatingMedium*(1-#filter)+1000*#filter/dT
FloatingMedium*(1-#filter)+1000*#filter/(T-TOld)
SetWindowTitle(0,"PureBasic: "+StrF(#UpdateFreq*FloatingMedium,2)+" FPS")
cnt+1
Repeat
If Not cnt%10
Event=WindowEvent()
SetWindowTitle(0,"PureBasic: "+StrF(FloatingMedium,2)+" fps.")
If Event=#PB_Event_CloseWindow
EndIf
EndIf
End
EndIf
ImageGadget(0,0,0,w,h,ImageID(0))
EndSelect
Until Not Event
EndIf
Until Event=#PB_Event_CloseWindow
EndIf</lang>
ForEver</lang>
[[Image:Image_Noise_in_PureBasic.png‎]]
[[Image:Image_Noise_in_PureBasic.png‎]]