RetroBASIC
Basicprogramming(.org) => General questions and discussions => Topic started by: B+ on May 25, 2017, 05:28:46 PM
-
Method or Madness, method to madness? ;D
I say it is crazy addictive ear worm started at Naalaa because no built-in circle drawing at all, which is maddening for graphics crazed hobby programmers.
Here is my latest filled circle algo in SmallBASIC time is 40% of my last best filled circle algo. Results are more dramatic for larger radii.
'new circle algo test.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-05-25 post
' MIT license info below for fCirc2 algo
const sqr12 = sqr(.5)
radius = 350
ox = xmax/2
oy = ymax/2
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc ox, oy, radius
next
t = ticks - t0
? t;" ms to draw 100 of these filled circles (r =350) my old fastest algo."
delay 4000
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc2 ox, oy, radius
next
t = ticks - t0
? t;" ms for same circle test with new fastest algo."
pause
sub fCirc(xx, yy, r)
r2 = r * r
for x = 0 to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
sub fCirc2(xx, yy, r)
'const sqr12 = sqr(.5) 'in main const section
r2 = r * r
sqr12r = sqr12*r
rect xx-sqr12r, yy-sqr12r, xx + sqr12r, yy+sqr12r filled
for x = 0 to sqr12r
y = sqr(r2-x*x)
line xx-x, yy+sqr12r, xx-x, yy+y
line xx-x, yy-sqr12r, xx-x, yy-y
line xx+x, yy+sqr12r, xx+x, yy+y
line xx+x, yy-sqr12r, xx+x, yy-y
next
for x = sqr12*r to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
##################################################################################
# The MIT License (MIT)
# Copyright (c) 2016-2017 B+=MGA
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##################################################################################
(see attached)
Hi Marcus,
I would have posted in Naalaa a translation of SmallBASIC code but the madness is how Naalaa does math eg floats and integers, crazy confusing for a language that claims not to be advanced.
-
In my experience, the time to draw circles depends exclusively on what the graphics card can deliver. Calculating sinuses costs cycles, of course, but the filling and drawing costs much more.
Do you have an explanation why you see such big differences? Do you have timings?
Attached an example that fills a window with a hundred circles. Here is the source:
include \masm32\MasmBasic\Res\MbGui.asm ; MasmBasic (http://masm32.com/board/index.php?topic=94.0)
Dim Pens() As DWORD
Dim Brushes() As DWORD
For_ ct=0 To 99
MakePen Pens(ct), Rand(-1), width 9 ; use random colours
MakeBrush Brushes(ct), Rand(-1) ; also for the fill
Next
MakePath 123, Circle(200) ; radius as n/1000 of window rect
SetGlobals posX, posY, pen, brush
Event Paint
NanoTimer()
For_ ecx=0 To 99 ; ID pen/brush x y scaleX scaleY
GuiDraw 123, <Pens(ecx)/Brushes(ecx)>, <Rand(500)>, <Rand(550)>, <Rand(800)>, <Rand(800)>
Next
GuiText 100.0-220, 100.0-22, Str$("%i ms (resize window to refresh)", NanoTimer(ms)) ; ca 20ms on a Core i5
GuiEnd
-
Results are different on different systems of course, that is why we should be comparing one algo versus another.
In SmallBASIC there IS a significant speed improvement for large radii circles (attached my results with SB).
Johnno has just reported that on SdlBasic the new algo takes 3 times longer! I must check that, I do seem to remember getting worse results as well, maybe I still have my test code.
I do want to make clear we are NOT filling circles with PAINT because that coloring method fails when overlapping filled circles over all sorts of previous drawn items.
Of course SB's built-in circle fill blows away these numbers but some BASIC's do not have built-in Circle fills Naalaa and QB64 for example.
-
I have now translated to SdlBasic the SmallBASIC test code and I get same fine results!
' New circle algo test.sdlbas (B+=MGA) 2017-05-26
' Johnno has reported 3 times slower not faster than SmallBASIC results
' Here is my code check from
' new circle algo test.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-05-25 post
' MIT license info below for fCirc2 algo
option qbasic
const xmax = 1200
const ymax = 700
setdisplay(xmax, ymax, 32, 1)
setcaption("New circle algo test For SdlBasic")
const sqr12 = sqr(.5)
radius = 350
ox = xmax/2
oy = ymax/2
t0 = ticks
for i = 1 to 100
ink(rgb(rnd(255), rnd(255), rnd(255)))
fCirc( ox, oy, radius)
next
t = ticks - t0
text(10, 20, 16, Str( t) + " ms to draw 100 of these filled circles (r =350) my old fastest algo.")
wait( 4000)
t0 = ticks
for i = 1 to 100
ink(rgb(rnd(255), rnd(255), rnd(255)))
fCirc2(ox, oy, radius)
next
t = ticks - t0
text(10, 40, 16, str(t) + " ms for same circle test with new fastest algo.")
waitkey(32)
end
sub fCirc(xx, yy, r)
r2 = r * r
for x = 0 to r
y = sqr(r2-x*x)
line( xx-x, yy+y, xx-x, yy-y)
line( xx+x, yy+y, xx+x, yy-y)
next
end sub
sub fCirc2(xx, yy, r)
'const sqr12 = sqr(.5) 'in main const section
r2 = r * r
sqr12r = sqr12*r
bar( xx-sqr12r, yy-sqr12r, xx + sqr12r, yy+sqr12r)
for x = 0 to sqr12r
y = sqr(r2-x*x)
line( xx-x, yy+sqr12r, xx-x, yy+y)
line( xx-x, yy-sqr12r, xx-x, yy-y)
line( xx+x, yy+sqr12r, xx+x, yy+y)
line( xx+x, yy-sqr12r, xx+x, yy-y)
next
for x = sqr12*r to r
y = sqr(r2-x*x)
line(xx-x, yy+y, xx-x, yy-y)
line( xx+x, yy+y, xx+x, yy-y)
next
end sub
'##################################################################################
'
'# The MIT License (MIT)
'# Copyright (c) 2016-2017 B+=MGA
'#
'# Permission is hereby granted, free of charge, to any person obtaining a copy
'# of this software and associated documentation files (the "Software"), to deal
'# in the Software without restriction, including without limitation the rights
'# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'# copies of the Software, and to permit persons to whom the Software is
'# furnished to do so, subject to the following conditions:
'#
'# The above copyright notice and this permission notice shall be included in all
'# copies or substantial portions of the Software.
'#
'# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
'# SOFTWARE.
'
'##################################################################################
I have to say, in most cases my graphics translations to SdlBasic run faster than in SmallBASIC which is why I am a fan of SdlBasic (plus you can do allot more with sound and graphics!) So here we have an unusual case where SmallBASIC is running faster than SdlBasic. Believe me this is rare.
-
Andy Amaya has brought to my attention Bresenham which saves time by avoiding SQR so here are 3 circle algo's and results in SmallBASIC.
'3 fill circle tests.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-05-27 post
' MIT license info below for fCirc2 algo
' Andy Amaya has brought to my attention the Bresenham Circle Fill ago
' from Andy Amaya at The QB64 Edition post is in Blitz
';Source:
'; http://homepage.smc.edu/kennedy_john/papers.htm
'; http://homepage.smc.edu/kennedy_john/bcircle.pdf
'
'; A Fast Bresenham Type Algorithm For Drawing Circles
'; by
'; John Kennedy
'
'; Blitzplus/Blitz 3D port by Andy_A
' Thanks Andy! best one yet! see fCircB(x, y, r)
const sqr12 = sqr(.5)
radius = 350
ox = xmax/2
oy = ymax/2
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc ox, oy, radius
next
t = ticks - t0
? t;" ms to draw 100 of these filled circles (r =350) my old fastest algo."
delay 4000
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc2 ox, oy, radius
next
t = ticks - t0
? t;" ms for same circle test with new fastest algo."
delay 4000
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCircB ox, oy, radius
next
t = ticks - t0
? t;" ms for same circle test with Bresenham algo."
pause
sub fCirc(xx, yy, r)
local r2, x, y
r2 = r * r
for x = 0 to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
sub fCirc2(xx, yy, r)
local r2, sqr12r, x, y
'const sqr12 = sqr(.5) 'in main const section
r2 = r * r
sqr12r = sqr12*r
rect xx-sqr12r, yy-sqr12r, xx + sqr12r, yy+sqr12r filled
for x = 0 to sqr12r
y = sqr(r2-x*x)
line xx-x, yy+sqr12r, xx-x, yy+y
line xx-x, yy-sqr12r, xx-x, yy-y
line xx+x, yy+sqr12r, xx+x, yy+y
line xx+x, yy-sqr12r, xx+x, yy-y
next
for x = sqr12*r to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
'Bresenham see Source notes above
sub fCircB(CX, CY, R) 'thanks Andy Amaya for heads up
Local X, Y
Local XChange, YChange
Local RadiusError
X = R
Y = 0
XChange = 1 - (R Lshift 1)
YChange = 1
RadiusError = 0
While X >= Y
Line CX-X, CY+Y, CX+X, CY+Y ';used calc'd values to draw
Line CX-X, CY-Y, CX+X, CY-Y ';scan lines from points
Line CX-Y, CY+X, CX+Y, CY+X ';in opposite octants
Line CX-Y, CY-X, CX+Y, CY-X
Y = Y + 1
RadiusError = RadiusError + YChange
YChange = YChange + 2
if (RadiusError Lshift 1) + XChange > 0 then
X = X - 1
RadiusError = RadiusError + XChange
XChange = XChange + 2
End If
Wend
End
##################################################################################
# The MIT License (MIT)
# Copyright (c) 2016-2017 B+=MGA
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##################################################################################
Thanks Andy Amaya best time yet!
-
The speed of Small Basic for drawing circles, was unexpected.
-
The speed of Small Basic for drawing circles, was unexpected.
Your 156 ms on top of the image are realistic. This is roughly what I get on my core i5 with the attached code, which simply uses the built-in Windows function GdipAddPathEllipse. What is your cpu?
Note that GdipAddPathEllipse is a slow Gdi+ function. The standard GDI Ellipse (https://msdn.microsoft.com/en-us/library/windows/desktop/dd162510(v=vs.85).aspx) function is about ten times as fast.
-
Rick your numbers are shockingly weird to me, wow!
For me SdlBasic circle fill tests ran a bit slower which was surprising because usually SB graphics translations run faster in SdlBasic.
But Rick you have SB 10 times faster than I and SdlBasic many times slower??? yikes, that is crazy different and you use Windows 10 as I recall, maybe your much newer machine explains difference (but why would SdlBasic be so much slower than my results?)
BTW the Bresenham algo in Sdlbasic did not show improved results over my new circle algo but for me ran in between my old and new cilrcle algos. I posted code at SdlBasic forum to see if my translation was missing something.
Rick could I see your SdlBasic translation for the numbers you posted?
-
Hi JJ,
{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 System;}}
{\colortbl ;\red0\green0\blue0;\red0\green0\blue255;\red112\green112\blue112;\red255\green0\blue0;}
{\*\generator Riched20 5.50.99.2070;}\viewkind4\uc1\pard\sl360\slmult1\tx1000\tx1400\tx4800\tx5800\tx0\cf1\v\f0\fs24\lang1040\'b0B$;00FR00FR0G222b1i6212105Y001dA100034.errameeP2x4echoameeP2x7penNameeP2x5isArrneeP2x4tmp$eneeP2x6gdiPeneeP205argC$seeP207ellipseeP2x8MyCircleP20n000Bb020D00Dh000A00DG000A00C7000E00DA000G00Ak000Gu00zc0Vn#\cf0\protect\'b0B5\cf2\protect0\v0 GuiParas\cf1 equ "Fast circles", w700, h720\par
include \\masm32\\MasmBasic\\Res\\MbGui.asm\tab\cf3 ; \cf0\protect\v \protect0\v0 MasmBasic\protect\v (http://masm32.com/board/index.php?topic=94.0)\cf1\protect0\v0\par
\pard\sl240\slmult1\tx1000\tx1400\tx4800\tx5800\tx0 \cf2 Dim\cf1 Pens() As DWORD\par
\cf2 Dim\cf1 Brushes() As DWORD\par
\cf2 For_\cf1 ct=0 To 99\par
\tab\cf2 MakePen\cf1 Pens(ct), \cf2 Rand\cf1(-1), width 5\tab\cf3 ; use random colours\cf1\par
\tab\cf2 MakeBrush\cf1 Brushes(ct), \cf2 Rand\cf1(-1)\tab\cf3 ; also for the fill\cf1\par
\cf2 Next\cf1\par
\pard\sl360\slmult1\tx1000\tx1400\tx4800\tx5800\tx0 \cf2 MakePath\cf1\tab 123, Circle(500)\cf3\tab ; ID, type circle: radius 50%, i.e. n/1000 of window rect\cf0\par
\pard\tx1000\tx1400\tx4800\tx5800\tx0\protect\v\'b0B8\cf2\protect0\v0 Event\cf1 Key\par
\pard\sl360\slmult1\tx1000\tx1400\tx4800\tx5800\tx0 \cf2 GuiCls\cf1\par
\pard\tx1000\tx1400\tx4800\tx5800\tx0\cf0\protect\v\'b0B8\cf2\protect0\v0 Event\f1 cPaint\par
\cf2 NanoTimer\cf1()\par
\pard\tx600\tx1000\tx1400\tx1800\tx2133\tx2466\tx2800\tx3050\tx3300\tx3550\tx3800\tx4800\tx0 \cf2 For_\cf1 ct=0 \cf2 To\cf1 99\tab\cf3 ; ID\tab\tab pen/brush\tab\tab\tab x\tab\tab y\tab\tab(\cf4 no\cf3 scaleX\tab scaleY)\cf1\par
\pard\tx1000\tx1400\tx4800\tx5800\tx0\cf2\tab GuiDraw\cf1 123, <Pens(ct)/Brushes(ct)>, <\cf2 Rand\cf1(500).>, <\cf2 Rand\cf1(500).>\tab\cf3 ; , eax, <Rand(1000)>\tab ; ScaleX is eax, same as scaleY\par
\cf1 \cf2 Next\cf1\par
\cf2 GuiText\cf1 100.0-205, 100.0-24, \cf2 Str$\cf1("%i ms (hit any key to refresh)", \cf2 NanoTimer\cf1(ms))\tab\cf3 ; ca 150 ms on a Core i5\cf1\par
\cf0\protect\v\lang1036\'b0B3\cf2\protect0\v0 GuiEnd\cf1\par
\par
}
Are you just using Paint to fill the circle?
-
Are you just using Paint to fill the circle?
No, it's GdipAddPathEllipse, a Windows Gdi+ function. As mentioned above, Ellipse is an even faster option, if you just want simple low quality circles.
The file is RTF, it opens in RichMasm, WordPad, MS Word, LibreOffice, ...
-
Rick your numbers are shockingly weird to me, wow!
For me SdlBasic circle fill tests ran a bit slower which was surprising because usually SB graphics translations run faster in SdlBasic.
But Rick you have SB 10 times faster than I and SdlBasic many times slower??? yikes, that is crazy different and you use Windows 10 as I recall, maybe your much newer machine explains difference (but why would SdlBasic be so much slower than my results?)
BTW the Bresenham algo in Sdlbasic did not show improved results over my new circle algo but for me ran in between my old and new cilrcle algos. I posted code at SdlBasic forum to see if my translation was missing something.
Rick could I see your SdlBasic translation for the numbers you posted?
' New circle algo test.sdlbas (B+=MGA) 2017-05-26
' Johnno has reported 3 times slower not faster than SmallBASIC results
' Here is my code check from
' new circle algo test.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-05-25 post
' MIT license info below for fCirc2 algo
option qbasic
const xmax = 1200
const ymax = 700
setdisplay(xmax, ymax, 32, 1)
setcaption("New circle algo test For SdlBasic")
const sqr12 = sqr(.5)
radius = 350
ox = xmax/2
oy = ymax/2
t0 = ticks
for i = 1 to 100
ink(rgb(rnd(255), rnd(255), rnd(255)))
fCirc( ox, oy, radius)
next
t = ticks - t0
text(10, 20, 16, Str( t) + " ms to draw 100 of these filled circles (r =350) my old fastest algo.")
wait( 4000)
t0 = ticks
for i = 1 to 100
ink(rgb(rnd(255), rnd(255), rnd(255)))
fCirc2(ox, oy, radius)
next
t = ticks - t0
text(10, 40, 16, str(t) + " ms for same circle test with new fastest algo.")
waitkey(32)
end
sub fCirc(xx, yy, r)
r2 = r * r
for x = 0 to r
y = sqr(r2-x*x)
line( xx-x, yy+y, xx-x, yy-y)
line( xx+x, yy+y, xx+x, yy-y)
next
end sub
sub fCirc2(xx, yy, r)
'const sqr12 = sqr(.5) 'in main const section
r2 = r * r
sqr12r = sqr12*r
bar( xx-sqr12r, yy-sqr12r, xx + sqr12r, yy+sqr12r)
for x = 0 to sqr12r
y = sqr(r2-x*x)
line( xx-x, yy+sqr12r, xx-x, yy+y)
line( xx-x, yy-sqr12r, xx-x, yy-y)
line( xx+x, yy+sqr12r, xx+x, yy+y)
line( xx+x, yy-sqr12r, xx+x, yy-y)
next
for x = sqr12*r to r
y = sqr(r2-x*x)
line(xx-x, yy+y, xx-x, yy-y)
line( xx+x, yy+y, xx+x, yy-y)
next
end sub
'##################################################################################
'
'# The MIT License (MIT)
'# Copyright (c) 2016-2017 B+=MGA
'#
'# Permission is hereby granted, free of charge, to any person obtaining a copy
'# of this software and associated documentation files (the "Software"), to deal
'# in the Software without restriction, including without limitation the rights
'# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'# copies of the Software, and to permit persons to whom the Software is
'# furnished to do so, subject to the following conditions:
'#
'# The above copyright notice and this permission notice shall be included in all
'# copies or substantial portions of the Software.
'#
'# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
'# SOFTWARE.
'
'##################################################################################
-
Thanks Rick, it is just my code!
Here are my results with same. You can see why I am shocked at your results.
-
It's not good and I sometimes wonder if their isn't some unknown programmers if the security field, taking shots at Basic. >:(
-
@B+: Which Windows version, which CPU, which graphics card?
I have a simple i5 with a standard Nvidia... and 100 circles take 20ms
-
There might be something about Windows10 that does not like Mark's SDL algorithms.
I tried it with the original fillcircle command and got 688 ms.
-
Rick, just to be clear I am comparing algorithms, NOT built-in fill circle which of course would be lightning fast! (which is why I don't think I need to know about Windows API calls. I don't know, I could be wrong.)
JJ, after some research, my graphics card is AMD Radeon HD 6319, CPU is AMD E-300 APU 1.3 GHz
How does this info help? I have junk, right?
So why are Ricks' SB times "kick ass" compared to mine but my SdlBasic 4342 ms runs rings around the 11222 ms time he gets?
eh, just another freaky thing with my system (that had it's hard drive replaced with a smaller one when I updated to Windows 10).
-
Here is a filled circle drawing example (512) with alpha channel support using Script BASIC and SDL.
(http://files.allbasic.info/ScriptBasic/gfx/sbgfxu64_alpha_circles.png) (http://files.allbasic.info/Win7_GUI/alpha_circles.png)
' ScriptBasic GFX - Alpha Circles
IMPORT gfx.inc
scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Circles")
' Random Value Arrays
RANDOMIZE(gfx::Time())
FOR i = 0 TO 512
rx[i] = RND() % 640
ry[i] = 60 + RND() % 480 - 80
rz[i] = RND() % 64
rr[i] = RND() AND 255
rg[i] = RND() AND 255
rb[i] = RND() AND 255
af = rx[i] / 640
ra[i] = INT(255 * af)
NEXT
ts = gfx::Time()
FOR i = 0 TO 512
gfx::filledCircleRGBA scrn, rx[i], ry[i], rz[i], rr[i], rg[i], rb[i], ra[i]
NEXT
te = gfx::Time()
gfx::stringColor scrn, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close
-
JJ, after some research, my graphics card is AMD Radeon HD 6319, CPU is AMD E-300 APU 1.3 GHz
How does this info help? I have junk, right?
No, you don't have junk. It's 399 (http://www.videocardbenchmark.net/gpu.php?gpu=GeForce+610M) points (mine) against 170 (http://www.videocardbenchmark.net/gpu.php?gpu=Radeon+HD+6310) (yours), but that is OK.
But I really wonder what you are measuring. The time it takes to calculate a Bresenham circle? I doubt it, because even with these values, you need to tell the graphics card what to do with it, via the line command. And that command might be a lot slower than the math...
To illustrate the problem, here a snippet that prints 360x the sinus and cosinus, in double precision. That is more than enough to get a precise 300 pixel circle. The second loop is identical, except that it doesn't print the values, i.e. you get the pure calculation time. And it does the second loop 10,000 times. Check yourself how much time it needs on your PC.
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
SetGlobals REAL8 px, py, REAL10 pi180=0.01745329251994329577
Init
For_ ecx=0 To 359
push ecx
fld pi180
fimul stack
fsincos
fstp py
fstp px
Print Str$(ecx), Str$("\t%Cf \t", py), Str$("%Cf\n", px)
pop eax
Next
NanoTimer()
push 9999
.Repeat
xor ecx, ecx
.Repeat
push ecx
fld pi180
fimul stack
fsincos
fstp py
fstp px
; no Print Str$(ecx), Str$("\t%f\t", py), Str$("%f\n", px)
pop eax
inc ecx
.Until ecx>=360
dec stack
.Until Sign?
pop edx
Inkey Str$("10000 calculations took %i ms", NanoTimer(ms))
EndOfCode
-
Hi John, I am alpha envious! very nice circles!
Hi JJ, Oh! I think I see what you are saying about graphics taking longer than calculations.
So minimize the number of lines being drawn... and get best times. So it's not about eliminating the Sqr Calc's, Bresenham (for SmallBASIC) is doing something better with line drawing, maybe?, that doesn't work (as well as starting with a filled square) for SdlBasic.