Oxygen Basic

Programming => Example Code => Topic started by: Peter on December 20, 2013, 06:00:10 AM

Title: Peacock Butterfly
Post by: Peter on December 20, 2013, 06:00:10 AM
Deleted
Title: Re: Peacock Butterfly
Post by: JRS on December 20, 2013, 09:58:23 AM
Hi Peter,

I tried to convert your example to ScriptBasic but have a couple questions.

Code: [Select]
For i=v to <1
This syntax isn't supported in SB. Can you post a traditional BASIC equivalent?

The Line_Draw() function in SB requires a value generated by the RGB() function for color. When I printed c with the first iteration it was 1 (one).

Title: Re: Peacock Butterfly
Post by: JRS on December 20, 2013, 10:30:05 AM
Thanks!

I still can't get my Line_Draw() function to work with the values being used.

Sorry.  :'(
Title: Re: Peacock Butterfly
Post by: Charles Pegge on December 20, 2013, 10:49:22 AM
A fair substitute:
For i=v to .999999


c is an RGB composite: 1..0x00FFFFFF

Time: 21 secs
Title: Re: Peacock Butterfly
Post by: JRS on December 20, 2013, 11:03:10 AM
Bit in the ass again by uninitialized variables.  ::)

(http://files.allbasic.info/ScriptBasic/peacock.png)

Code: [Select]
' ScriptBasic Peacock

DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"
DECLARE SUB Draw_Line ALIAS "SB_Draw_Line" LIB "sdl"

Window 700, 500, "Peacock Plume"
q = 1
q1 = 0.9997
v = 0.01
vv = 0.0004
xs = 750
ys = 730
xm = 650
ym = 180
br = -0.7393
bi = 0.117
ar = 0.0
ai = 0.0
_cos = cos(0.01)
_sin = sin(0.01)
t1 = Ticks()
FOR d = 1 TO 15000
  tr = ar * ar - ai * ai + br
  ti = 2 * ar * ai + bi
  x  = tr * xs + xm
  y  = ti * ys + ym
  v  = v + vv
  q  = q * q1
  c  = d ^ 2.1
  Draw_Line x, y, x + (_cos * 50 * q), y + (_sin * 50 * q), c
  ar = tr
  ai = ti
NEXT
UpdateRect
t2 = Ticks()
t3 = (t2 - t1) / 1000
PRINT "Time:  ", FORMAT("%.4f", t3), " seconds.\n"
PRINT d-1, " Lines Drawn\n"
WaitKey

jrs@laptop:~/sb/sb22/sdl$ scriba peacock.sb
Time:  0.0880 seconds.
15000 Lines Drawn
jrs@laptop:~/sb/sb22/sdl$