|
Post by johnno56 on Nov 14, 2022 18:12:33 GMT -6
Here is a cool graphics demo... No. Not by myself. Originally coded for SpecBas then coded for Naalaa7. RCBasic now has a version.
It seems to do SO much but using so little code. Enjoy.
xmax = 512 ymax = 512 title$ = "Bubble Universe - ESC to exit" center_x = windowpos_centered center_y = windowpos_centered WindowOpen(1,title$,center_x,center_y,xmax,ymax,WindowMode(1,0,0,0,0),1) SetWindowAutoClose(1, 0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
' Bubble universe ' --------------- ' Paul Dunn posted this code but for SpecBAS in a facebook group. ' It looked so cool that I had to rewrite it in Naalaa 7. Marcus ' ' RCB version Johnno56
TAU = 6.283185307179586
n = 200 r = TAU / 235 x = 0 y = 0 v = 0 t = 0 hw = xmax / 2 hh = ymax / 2
do SetColor(rgb(0, 0, 0)) ClearCanvas for i = 0 to n for j = 0 to n u = sin(i + v) + sin(r*i + x) v = cos(i + v) + cos(r*i + x) x = u + t SetColor(rgb(i, j, 99)) Pset(hw + u * hw * 0.4, hh + v * hh * 0.4) next next t = t + 0.025 if Not WindowExists(1) Or WindowEvent_Close(1) Then end end if update() loop until key(27) = 1 ESC to exit...
J
|
|
|
Post by aurel on Nov 15, 2022 13:31:18 GMT -6
I was thinking that my micro(A) version is slow on my computer but this one is even slower i tried to speed up but nothing ..it is similar but not exactly the same effect ![](//storage.proboards.com/6314556/thumbnailer/kxRfXyisfcJQxsUhwjv0.png)
|
|
|
Post by n00b on Nov 18, 2022 8:24:45 GMT -6
johnno56 This is an awesome demo. aurel I would loke to see the micro(A) version if you can upload it. Also your sub-link does not work. I think you meant for it to be basic4all.epizy.com
|
|
|
Post by aurel on Nov 18, 2022 14:26:22 GMT -6
I don't know nOOb i expected more speed from SDL i use in microA float type of variables ..not double maybe that is a reason why is microA version not same and also slow or is slow just because is token interpreter... ok i will see and try to upload somewhere ..i will give a link
|
|
|
Post by rosy on Nov 19, 2022 8:09:46 GMT -6
If in RC there was a command to draw dots from the table in bulk, maybe it would work faster...
|
|
|
Post by n00b on Nov 19, 2022 10:26:40 GMT -6
rosy The dots aren't what is slowing this down. Its mostly the number of loops and the math operations. Admittedly, using double precision floats internally is both a strength and weakness of RCBasic. You could speed it up by reducing the number of loops per render. Try this: xmax = 512 ymax = 512 title$ = "Bubble Universe - ESC to exit" center_x = windowpos_centered center_y = windowpos_centered WindowOpen(1,title$,center_x,center_y,xmax,ymax,WindowMode(1,0,0,0,0),0) SetWindowAutoClose(1, 0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0) ' Bubble universe ' --------------- ' Paul Dunn posted this code but for SpecBAS in a facebook group. ' It looked so cool that I had to rewrite it in Naalaa 7. Marcus ' ' RCB version Johnno56 TAU = 6.283185307179586 n = 0 r = TAU / 235 x = 0 y = 0 v = 0 t = 0 hw = xmax / 2 hh = ymax / 2
do SetColor(rgb(0, 0, 0))
if n = 100 then ClearCanvas end if
for i = n to n+100 for j = n to n+100 u = sin(i + v) + sin(r*i + x) v = cos(i + v) + cos(r*i + x) x = u + t SetColor(rgb(i, j, 99)) Pset(hw + u * hw * 0.4, hh + v * hh * 0.4) next next
if n = 100 Then t = t + 0.025 end if
n = (n <> 100) * 100
if Not WindowExists(1) Or WindowEvent_Close(1) Then end end if
update() loop until key(27) = 1
|
|
|
Post by aurel on Nov 19, 2022 11:20:26 GMT -6
heh i don't use double than single or float but still is slow or too fast to see effect
|
|
|
Post by rosy on Nov 19, 2022 15:12:53 GMT -6
There, a few simple operations...
|
|
|
Post by aurel on Nov 20, 2022 0:55:20 GMT -6
a few simple operations ![???](//storage.proboards.com/forum/images/smiley/huh.png) what that means
|
|
|
Post by rosy on Nov 20, 2022 12:39:48 GMT -6
rosy The dots aren't what is slowing this down. Its mostly the number of loops and the math operations. Admittedly, using double precision floats internally is both a strength and weakness of RCBasic. You could speed it up by reducing the number of loops per render. Try this: But you didn't speed it up, you just did something else... ![:)](//storage.proboards.com/forum/images/smiley/smiley.png)
|
|
|
Post by n00b on Nov 20, 2022 13:09:05 GMT -6
But you didn't speed it up, you just did something else... ![:)](//storage.proboards.com/forum/images/smiley/smiley.png) It is faster. It is rendering half frames each update but its FPS is 4x what it was which means its double the speed of the original (the original is about 15 FPS and mine is almost 30 FPS). You can run them side by side and see it.
|
|
|
Post by aurel on Nov 20, 2022 13:23:45 GMT -6
it looks to me that i need win function sleep ms
|
|
|
Post by rosy on Nov 20, 2022 13:52:20 GMT -6
These programs do something else. You've removed half the calculations and are drawing 50% of the points.
|
|
|
Post by n00b on Nov 20, 2022 14:18:40 GMT -6
These programs do something else. You've removed half the calculations and are drawing 50% of the points. Yeah I see it now. You are right. I guess there is really no way to speed it up. It is the number of loops that is the biggest issue. 200x200 loops ( a total of 40,000 loops ) each frame. Its not much you can do to optimize this other than try to pre-calculate the output. I don't think you can with this simulation though.
|
|
|
Post by rosy on Nov 20, 2022 15:29:17 GMT -6
It doesn't have to be a calculation problem... In BasicC, frame rate is 57, after using SDL_RenderDrawPoints - frame rate is 94...
By the way... instead of n = (n <> 100) * 100, use n=100-n
|
|