|
Post by rick3137 on May 9, 2016 16:59:52 GMT -6
Basic is a good medium for making doodles with fractals. I couldn't get recursion to work so I used another method.
' by Rick3137 http://rb23.yolasite.com
red = 0 blue = 0 green = 0
time1 = ticks() time2 = 0
LoadFont(0,"FreeMono.ttf",16) windowOpen(0," Speed Test", 0, 0, 1200,700,0) window(0) CanvasOpen(0,1200,700,0,0,1200,700,1)
hideMouse() Canvas(0)
setcolor( rgb(20,40,60 ))
clearcanvas()
setcolor( rgb(245,200,255 ))
cls() Pi2=6.28318 Type = 3 Count = 0 Count2 = 0 Ang1 = Pi2/Type Ang = 0 x = 150 y = 500 setcolor (rgb(255,0,0))
function SetColor2( clr ) if( clr = 0 ) then red = 0 green = 0 blue = 0 end if if( clr = 1 ) then red = 255 green = 200 blue = 200 end if if( clr = 2 ) then red = 255 green = 0 blue = 0 end if if( clr = 3 ) then red = 255 green = 200 blue = 0 end if if( clr = 4 ) then red = 255 green = 255 blue = 0 end if if( clr = 5 ) then red = 0 green = 255 blue = 0 end if if( clr = 6 ) then red = 0 green = 0 blue = 255 end if if( clr = 7 ) then red = 255 green = 0 blue = 255 end if if( clr = 8 ) then red = 200 green = 200 blue = 200 end if if( clr = 9 ) then red = 255 green = 255 blue = 255 end if if( clr = 10 ) then red = 100 green = 100 blue = 100 end if if( clr = 11 ) then red = 200 green = 180 blue = 160 end if if( clr = 12 ) then red = 200 green = 0 blue = 0 end if if( clr = 13 ) then red = 200 green = 160 blue = 0 end if if( clr = 14 ) then red = 200 green = 200 blue = 0 end if if( clr = 15 ) then red = 0 green = 200 blue = 0 end if if( clr = 16 ) then red = 0 green = 0 blue = 200 end if if( clr = 17 ) then red = 200 green = 0 blue = 200 end if if( clr = 18 ) then red = 150 green = 0 blue = 0 end if if( clr = 19 ) then red = 0 green = 150 blue = 0 end if if( clr = 20 ) then red = 0 green = 0 blue = 150 end if if( clr = 21 ) then red = 100 green = 0 blue = 0 end if if( clr = 22 ) then red = 0 green = 100 blue = 0 end if if( clr = 23 ) then red = 0 green = 0 blue = 100 ' Jesus Is Comming end if setcolor ( rgb(red, green, blue)) end function function RotateLeft( angle ) Ang = Ang + angle if Ang > Pi2 then Ang = Ang - Pi2 end if end function function MoveSteps ( distance ) dx = cos(Ang) * distance dy = sin(Ang) * distance x2 = x + dx y2 = y - dy line( x,y,x2,y2) x = x2 y = y2 end function
function Fractal6(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 wend end function function Fractal5(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 Fractal6(size/2) wend end function function Fractal4(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 Fractal5(size/2) wend end function function Fractal3(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 Fractal4(size/2) wend end function function Fractal2(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 Fractal3(size/2) wend end function function Fractal1(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft(Pi2/3) cnt = cnt + 1 Fractal2(size/2) wend end function x = 400 y = 290 Ang = 0 Count2 = 0
setcolor (rgb(0,255,255 )) while ( Count2 < 20) Fractal1(250) Count2 = Count2 + 1 Ang = Count2 * 9 SetColor2( Count2 ) wend time2 = ticks() setcolor( rgb(255,255,255 )) Canvas(0) DrawText( "Press any key to exit ..", 10,0) DrawText( time2 - time1 ,10,30) DrawText( " ms. Drawing time ",60,30 ) update() waitkey() end
insert code here
|
|
|
Post by n00b on May 9, 2016 18:05:17 GMT -6
I will try this out when I get home. Recursive function calls should work. The function is given an address upon initial creation. I will make sure that recursion works in the next release.
|
|
|
Post by n00b on May 9, 2016 20:49:19 GMT -6
I tried out the demo and its pretty awesome. I love seeing cool patterns and effects like this. I also did some testing with recursion and I did not get any errors. Try this out:
n = 0 function f(fn) if n < 10 then print n n = n + fn f(n) end if return 200 end function
print f(1) print "n = " & n This code will also work in sdlBasic if you want to do a comparison.
I would really like to include this as a featured demo in future releases of rcbasic if you don't mind. I will give you full credit. The only demos I have so far are conversions of sdlBasic examples I did.
|
|
|
Post by rick3137 on May 11, 2016 8:49:34 GMT -6
Here is the code for the Recursive version. It is very similar to the sdlbasic version, that works fine. It seems that when you have multiple copys of Fractal() running at the same time, the variables interfere with each other.
insert code here ' by Rick3137 rb23.yolasite.com
red = 0 blue = 0 green = 0
time1 = ticks() time2 = 0
LoadFont(0,"FreeMono.ttf",16) windowOpen(0," Speed Test", 0, 0, 1200,700,0) window(0) CanvasOpen(0,1200,700,0,0,1200,700,1)
hideMouse() Canvas(0)
setcolor( rgb(20,40,60 ))
clearcanvas()
setcolor( rgb(245,200,255 ))
cls() Pi2=6.28318 Type = 3 Count = 0 Count2 = 0 Ang1 = Pi2/Type Ang = 0 x = 150 y = 500 setcolor (rgb(255,0,0))
function SetColor2( clr ) if( clr = 0 ) then red = 0 green = 0 blue = 0 end if if( clr = 1 ) then red = 255 green = 200 blue = 200 end if if( clr = 2 ) then red = 255 green = 0 blue = 0 end if if( clr = 3 ) then red = 255 green = 200 blue = 0 end if if( clr = 4 ) then red = 255 green = 255 blue = 0 end if if( clr = 5 ) then red = 0 green = 255 blue = 0 end if if( clr = 6 ) then red = 0 green = 0 blue = 255 end if if( clr = 7 ) then red = 255 green = 0 blue = 255 end if if( clr = 8 ) then red = 200 green = 200 blue = 200 end if if( clr = 9 ) then red = 255 green = 255 blue = 255 end if if( clr = 10 ) then red = 100 green = 100 blue = 100 end if if( clr = 11 ) then red = 200 green = 180 blue = 160 end if if( clr = 12 ) then red = 200 green = 0 blue = 0 end if if( clr = 13 ) then red = 200 green = 160 blue = 0 end if if( clr = 14 ) then red = 200 green = 200 blue = 0 end if if( clr = 15 ) then red = 0 green = 200 blue = 0 end if if( clr = 16 ) then red = 0 green = 0 blue = 200 end if if( clr = 17 ) then red = 200 green = 0 blue = 200 end if if( clr = 18 ) then red = 150 green = 0 blue = 0 end if if( clr = 19 ) then red = 0 green = 150 blue = 0 end if if( clr = 20 ) then red = 0 green = 0 blue = 150 end if if( clr = 21 ) then red = 100 green = 0 blue = 0 end if if( clr = 22 ) then red = 0 green = 100 blue = 0 end if if( clr = 23 ) then red = 0 green = 0 blue = 100 end if // Jesus Is Comming setcolor ( rgb(red, green, blue)) end function function RotateLeft( ) Ang = Ang + Ang1 if Ang > Pi2 then Ang = Ang - Pi2 end if end function function MoveSteps ( distance ) dx = cos(Ang) * distance dy = sin(Ang) * distance x2 = x + dx y2 = y - dy line( x,y,x2,y2) x = x2 y = y2 end function
sub Fractal(size) cnt = 0 Ang1 = Pi2/3 Count = Count + 1 while cnt < 3 MoveSteps ( size ) RotateLeft() cnt = cnt + 1 if size>10 then Fractal(size/2) end if wend end sub x = 400 y = 290 Ang = 0 Count2 = 0
setcolor (rgb(0,255,255 )) while ( Count2 < 20) Fractal(250) Count2 = Count2 + 1 Ang = Count2 * 9 SetColor2( Count2 ) wend time2 = ticks() - time1 setcolor( rgb(255,255,255 )) Canvas(0) DrawText( "Press any key to exit ..", 10,0) DrawText( time2 ,10,30) DrawText( " ms. Drawing time ",60,30 ) update() waitkey() end
|
|
|
Post by n00b on May 11, 2016 18:11:14 GMT -6
Could you post the sdlBasic version just so I can compare them. If this is truly a bug I would like to fix it as soon as possible. I can possibly have it fixed in time for the next release which I plan on uploading this Friday.
|
|
|
Post by rick3137 on May 12, 2016 8:09:01 GMT -6
option explicit
dim common red = rgb(255,0,0),blue = rgb(0,0,255),green = rgb(0,255,0),violet = rgb(255,0,255),yellow = rgb(255,255,0),bluegreen = rgb(0,255,255) dim common red2 = rgb(255,0,0),blue2 = rgb(255,0,0),green2 = rgb(255,0,0),violet2 = rgb(255,0,0),yellow2 = rgb(255,0,0),bluegreen2 = rgb(255,0,0) dim common black = rgb(0,0,0),white = rgb(255,255,255)
dim common time1 = ticks() dim common time2 = 0
autoback(-2)
setdisplay( 800,600,32,1)
ink ( black )
cls dim common Pi2=6.28318 , Type = 3 , Count = 0 , Count2 = 0 dim common Ang1 = Pi2/Type , Ang = 0 , x = 150 , y = 500 ink (rgb(255,0,0))
function SetColor( clr ) if( clr = 0 ) then red = 0 : green = 0 : blue = 0 end if if( clr = 1 ) then red = 255 : green = 200 : blue = 200 end if if( clr = 2 ) then red = 255 : green = 0 : blue = 0 end if if( clr = 3 ) then red = 255 : green = 200 : blue = 0 end if if( clr = 4 ) then red = 255 : green = 255 : blue = 0 end if if( clr = 5 ) then red = 0 : green = 255 : blue = 0 end if if( clr = 6 ) then red = 0 : green = 0 : blue = 255 end if if( clr = 7 ) then red = 255 : green = 0 : blue = 255 end if if( clr = 8 ) then red = 200 : green = 200 : blue = 200 end if if( clr = 9 ) then red = 255 : green = 255 : blue = 255 end if if( clr = 10 ) then red = 100 : green = 100 : blue = 100 end if if( clr = 11 ) then red = 200 : green = 180 : blue = 160 end if if( clr = 12 ) then red = 200 : green = 0 : blue = 0 end if if( clr = 13 ) then red = 200 : green = 160 : blue = 0 end if if( clr = 14 ) then red = 200 : green = 200 : blue = 0 end if if( clr = 15 ) then red = 0 : green = 200 : blue = 0 end if if( clr = 16 ) then red = 0 : green = 0 : blue = 200 end if if( clr = 17 ) then red = 200 : green = 0 : blue = 200 end if if( clr = 18 ) then red = 150 : green = 0 : blue = 0 end if if( clr = 19 ) then red = 0 : green = 150 : blue = 0 end if if( clr = 20 ) then red = 0 : green = 0 : blue = 150 end if if( clr = 21 ) then red = 100 : green = 0 : blue = 0 end if if( clr = 22 ) then red = 0 : green = 100 : blue = 0 end if if( clr = 23 ) then red = 0 : green = 0 : blue = 100 ' Jesus Is Comming end if ink ( rgb(red, green, blue)) end function function RotateLeft() Ang = Ang + Ang1 if Ang > Pi2 then Ang = Ang - Pi2 end if end function function MoveSteps ( distance ) dim dx = cos(Ang) * distance dim dy = sin(Ang) * distance dim x2 = x + dx dim y2 = y - dy line( x,y,x2,y2) x = x2 : y = y2 end function function Fractal(size) dim cnt = 0 Ang1 = Pi2/Type Count = Count + 1 while cnt < 3 MoveSteps ( size ) RotateLeft() cnt = cnt + 1 if size > 10 then Fractal(size/2) end if wend end function x = 400 : y = 290 : Ang = 0 Count2 = 0
ink (blue) while ( Count2 < 20) Fractal(250) Count2 = Count2 + 1 : Ang = Count2 * 9 SetColor( Count2 ) wend time2 = ticks() - time1 text( 10,0,16,"Press any key to exit .." ) text( 10,30,16,time2 ) text( 60,30,16," ms. Drawing time ") screenswap waitkey end
|
|
|
Post by n00b on May 15, 2016 17:35:23 GMT -6
If you have upgraded to v2.0.5 you can just push all the variables you use in the function before recursive call and pop them right after. That fixes the recursion problem. Just look at the documentation on the new stack api in the manual.
|
|
|
Post by rick3137 on May 18, 2016 9:30:21 GMT -6
I tried. Push and pull didn't fix it. I started over with SDLBasic and made a Smaller one and then translated to RCBasic.
' by Rick3137 http://rb23.yolasite.com LoadFont(0,"FreeMono.ttf",16) windowOpen(0," Speed Test", 0, 0, 1200,700,0) window(0) CanvasOpen(0,1200,700,0,0,1200,700,1) hideMouse() Canvas(0) setcolor( rgb(20,40,60 )) clearcanvas() setcolor( rgb(245,200,255 )) cls() Pi2=6.28318 Count = 0 Count2 = 0 Ang1 = Pi2/3 Ang = 0 x = 150 y = 500 setcolor (rgb(255,0,0))
function RotateLeft( ) Ang = Ang + Ang1 if Ang > Pi2 then Ang = Ang - Pi2 end if end function function MoveSteps ( distance ) dx = cos(Ang) * distance dy = sin(Ang) * distance x2 = x + dx y2 = y - dy line( x,y,x2,y2) x = x2 y = y2 end function
sub Fractal(size) cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft() cnt = cnt + 1 if size>10 then Push_N ( cnt ) Push_N ( Ang ) Push_N ( x ) Push_N ( y ) Fractal(size/2) y = Pop_N ( ) x = Pop_N ( ) Ang = Pop_N ( ) cnt = Pop_N ( ) end if wend end sub x = 400 y = 290 Ang = 0
setcolor (rgb(0,255,255 )) Ang1 = Pi2/3 Fractal(250) setcolor( rgb(255,255,255 )) Canvas(0) DrawText( "Press any key to exit ..", 10,0) update() waitkey() end
Here's the SDLBasic version:
option explicit
dim common red = rgb(255,0,0),blue = rgb(0,0,255),green = rgb(0,255,0),violet = rgb(255,0,255),yellow = rgb(255,255,0),bluegreen = rgb(0,255,255) dim common red2 = rgb(255,0,0),blue2 = rgb(255,0,0),green2 = rgb(255,0,0),violet2 = rgb(255,0,0),yellow2 = rgb(255,0,0),bluegreen2 = rgb(255,0,0) dim common black = rgb(0,0,0),white = rgb(255,255,255)
autoback(-2)
setdisplay( 800,600,32,1) ink ( black ) cls dim common Pi2=6.28318 , Type = 3 , Count = 0 , Count2 = 0 dim common Ang1 = Pi2/3 , Ang = 0 , x = 150 , y = 500 , Depth = 0 ink (rgb(255,0,0)) function RotateLeft() Ang = Ang + Ang1 if Ang > Pi2 then Ang = Ang - Pi2 end if end function function MoveSteps ( distance ) dim dx = cos(Ang) * distance dim dy = sin(Ang) * distance dim x2 = x + dx dim y2 = y - dy line( x,y,x2,y2) x = x2 : y = y2 end function function Fractal(size) dim cnt = 0 while cnt < 3 MoveSteps ( size ) RotateLeft() cnt = cnt + 1 if size > 30 then Fractal(size/2) end if wend end function x = 250 : y = 550 : Ang = 0 Type = 5 ink (blue) Ang1 = Pi2/3 Fractal(300) text( 10,0,16,"Press any key to exit .." )
screenswap waitkey end
|
|
|
Post by n00b on May 19, 2016 20:19:06 GMT -6
Here is your original recursive version with the change I suggested. Try it out.
' by Rick3137 rb23.yolasite.com
red = 0 blue = 0 green = 0
time1 = ticks() time2 = 0
LoadFont(0,"FreeMono.ttf",16) windowOpen(0," Speed Test", 0, 0, 1200,700,0) window(0) CanvasOpen(0,1200,700,0,0,1200,700,1)
hideMouse() Canvas(0)
setcolor( rgb(20,40,60 ))
clearcanvas()
setcolor( rgb(245,200,255 ))
cls() Pi2=6.28318 Type = 3 Count = 0 Count2 = 0 Ang1 = Pi2/Type Ang = 0 x = 150 y = 500
setcolor (rgb(255,0,0))
function SetColor2( clr ) if( clr = 0 ) then red = 0 green = 0 blue = 0 end if if( clr = 1 ) then red = 255 green = 200 blue = 200 end if if( clr = 2 ) then red = 255 green = 0 blue = 0 end if if( clr = 3 ) then red = 255 green = 200 blue = 0 end if if( clr = 4 ) then red = 255 green = 255 blue = 0 end if if( clr = 5 ) then red = 0 green = 255 blue = 0 end if if( clr = 6 ) then red = 0 green = 0 blue = 255 end if if( clr = 7 ) then red = 255 green = 0 blue = 255 end if if( clr = 8 ) then red = 200 green = 200 blue = 200 end if if( clr = 9 ) then red = 255 green = 255 blue = 255 end if if( clr = 10 ) then red = 100 green = 100 blue = 100 end if if( clr = 11 ) then red = 200 green = 180 blue = 160 end if if( clr = 12 ) then red = 200 green = 0 blue = 0 end if if( clr = 13 ) then red = 200 green = 160 blue = 0 end if if( clr = 14 ) then red = 200 green = 200 blue = 0 end if if( clr = 15 ) then red = 0 green = 200 blue = 0 end if if( clr = 16 ) then red = 0 green = 0 blue = 200 end if if( clr = 17 ) then red = 200 green = 0 blue = 200 end if if( clr = 18 ) then red = 150 green = 0 blue = 0 end if if( clr = 19 ) then red = 0 green = 150 blue = 0 end if if( clr = 20 ) then red = 0 green = 0 blue = 150 end if if( clr = 21 ) then red = 100 green = 0 blue = 0 end if if( clr = 22 ) then red = 0 green = 100 blue = 0 end if if( clr = 23 ) then red = 0 green = 0 blue = 100 end if // Jesus Is Comming setcolor ( rgb(red, green, blue))
end function
function RotateLeft( ) Ang = Ang + Ang1 if Ang > Pi2 then Ang = Ang - Pi2 end if
end function
function MoveSteps ( distance ) dx = cos(Ang) * distance dy = sin(Ang) * distance x2 = x + dx y2 = y - dy line( x,y,x2,y2) x = x2 y = y2 end function
sub Fractal(size)
cnt = 0 Ang1 = Pi2/3 Count = Count + 1 while cnt < 3 MoveSteps ( size ) RotateLeft() cnt = cnt + 1 if size>10 then
'------------------------------------- 'Pushing Variables on the Stack Here Push_N(size) Push_N(cnt) Push_N(Ang1) Push_N(Count)
Fractal(size/2)
'Pulling Variables off the Stack Here Count = Pop_N() Ang1 = Pop_N() cnt = Pop_N() size = Pop_N() '-------------------------------------
end if wend end sub
x = 400 y = 290 Ang = 0 Count2 = 0
setcolor (rgb(0,255,255 )) while ( Count2 < 20) Fractal(250) Count2 = Count2 + 1 Ang = Count2 * 9 SetColor2( Count2 ) wend
time2 = ticks() - time1 setcolor( rgb(255,255,255 )) Canvas(0) DrawText( "Press any key to exit ..", 10,0) DrawText( time2 ,10,30) DrawText( " ms. Drawing time ",60,30 ) update() waitkey() end
|
|
|
Post by rick3137 on May 20, 2016 16:01:02 GMT -6
Works good. Now I can go back to making demo's I wrote the original version to test speed of Basic. RCBasic- 247 ms draw time SDlBasic 75 ms draw time PulsarLua 198 ms draw time EGSL 43 ms draw time Small Basic and YaBasic- Slower I hope you can speed it up, but it's just fine for what I use it for. When I want speed, I use CodeBlocks. Basic provides me with fast creation time and is much more relaxing to use.
|
|
|
Post by n00b on May 20, 2016 22:40:41 GMT -6
There is actually a good explanation of why rcbasic is slow in this example. RCBasic is designed around the new rendering API in SDL 2.0. This allows it to use textures in GPU memory for faster acceleration of image rendering. However this has a drawback in that graphics primitives that are going to be slower because they usually require multiple calls to the GPU renderer from the CPU. I am working on making the compiled runtime code execute faster but the issue with the graphics primitives is something I still am working on a solution for.
|
|