Just for fun a tried to use setrendertoimage and drawsprite , but that was even more slow.
A sonar is slow updating so why not:
Use sonerlines to set what fps you want , i get 60 fps on my old samsung s2 using sonerlines=9
Sorry code formatting was lost in copy/paste ?
// Project: test
// Created: 2017-08-20
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
XCreateMemblockForImageRGBA( 1, 512, 512 )
CreateImageFromMemblock( 1, 1 )
CreateSprite( 1, 1 )
global sonary = 0
global sonarlines = 7 // old samsung s2 , 9 = 60 fps.
do
Local y, x As Integer
Local t1, t2, t3 As Integer
t1 = GetMilliseconds()
Local col As Integer
col = MakeColor(255,0,0)
for a = 0 to sonarlines
sonary = sonary + 1
if sonary > 511 then sonary = 0
For x = 0 To 511
//DrawBox( x, y, x+1, y+1, col, col, col, col, 1 )
XDrawPixel( 1, x, sonary, 512, 255, 0, 0, 255 )
//XDrawPixel2( 1, x, y, 512, 4278190335 )
Next x
next a
if sonary < 511
For x = 0 To 511
//DrawBox( x, y, x+1, y+1, col, col, col, col, 1 )
XDrawPixel( 1, x, sonary+1, 512, 255, 196, 196, 255 )
//XDrawPixel2( 1, x, y, 512, 4278190335 )
Next x
endif
t2 = GetMilliseconds()
CreateImageFromMemblock( 1, 1 )
SetSpriteImage( 1, 1 )
t3 = GetMilliseconds()
Print( "FPS: " + Str( ScreenFPS() ) )
Print( "Draw Pixel Time: " + Str( t2 - t1 ) + "ms" )
Print( "Create Image Time: " + Str( t3 - t2 ) + "ms" )
Sync()
loop
Function XCreateMemblockForImageRGBA( memId As Integer, width As Integer, height As Integer )
// memblock 'size' is summary of image width (integer, 4 bytes),
// image height (integer, 4 bytes), image depth (integer, 4 bytes)
// that is 12 bytes - and raw image data (the number of pixels multiplied by 4 bytes)
Local size As Integer
size = 12 + width * height * 4
CreateMemblock( memId, size )
SetMemblockInt( memId, 0, width ) // writing starts with offset 0
SetMemblockInt( memId, 4, height ) // variable 'width' occupies 4 bytes, so now offset 0 + 4 = 4
SetMemblockInt( memId, 8, 32 ) // variable 'height' occupies 4 bytes, so now offset 4 + 4 = 8
Local i As Integer
For i = 12 To size-1 Step 4
SetMemblockByte( memId, i, Random( 0, 255 ) )
SetMemblockByte( memId, i+1, Random( 0, 255 ) )
SetMemblockByte( memId, i+2, Random( 0, 255 ) )
SetMemblockByte( memId, i+3, Random( 0, 1 ) )
Next i
EndFunction
Function XDrawPixel( memId As Integer, x As Integer, y As Integer, w As Integer, r As Integer, g As Integer, b As Integer, a As Integer )
Local dst As Integer
dst = 12+4*(y*w+x)
SetMemblockByte( memId, dst, r )
SetMemblockByte( memId, dst+1, g )
SetMemblockByte( memId, dst+2, b )
SetMemblockByte( memId, dst+3, a )
EndFunction
Function XDrawPixel2( memId As Integer, x As Integer, y As Integer, w As Integer, rgba As Integer )
Local dst As Integer
dst = 12+4*(y*w+x)
SetMemblockInt( memId, dst, rgba )
EndFunction
Not really a faster way to do it, but looks great with the "updating sonar line"
best regards Preben Eriksen,