Oxygen Basic

Information => Open Forum => Topic started by: Charles Pegge on March 09, 2013, 05:49:00 AM

Title: For Gordon and Pancho Eliott
Post by: Charles Pegge on March 09, 2013, 05:49:00 AM
Attached is an animation which I thought hinted at some of the ideas in this paper, which Gordon kindly sent me. (need permission to post it):

Geoff Anderson Fractal Density Theory

This is an intriguing theory of everything, that requires little more than Newtonian dynamics and an understanding of fractals. It scales in concept from subatomic particles to galactic clusters.


Charles

X
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 09, 2013, 10:07:29 AM
Code: [Select]
/* by Peter Wirbelauer  */
include "sw.inc"
Window 320,320,1

Sub Trauma(single im,ii,st)
 single fx, fy, i
 sys r, g, b, c, x, y
 for x=0 to <320
   i =1
   fy=0
   for y=0 to < 320
     c=i*(1+cos(fx))+i*(1+cos(fy))
     SetPixel x,320-y,c
     i=i*im+ii
     fy +=st
    next
    fx +=st
 next
End Sub

while Key(27)=0
single m,n
m=1
n=1
for i=1 to 120
  Trauma (m,n, .01)
  n +=111
  Redraw
next

m=1.0100
n=.4
for i=1 to 120
  Trauma (m,n, .03)
  m +=.0005
  Redraw
next
wend

Quit()

X
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 09, 2013, 11:15:46 AM
Welcome back Peter Rabbit.  ;D

(http://2.bp.blogspot.com/-Ork4k3H4zK8/TexFwxsn5FI/AAAAAAAAAnE/hobRf3Id5D4/s1600/Peter_Rabbit_by_Winnie_Beatles.jpg)
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 09, 2013, 05:23:04 PM
Code: [Select]
for y=0 to < 320
What does this mean? What is the range of this FOR statement?
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 09, 2013, 05:27:57 PM
Art of programming  :D
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 09, 2013, 05:30:43 PM
Art of programming  :D

Seriously, I'm trying to get your example working in SB and this has me puzzled.

I'm going to assume that it's inline finger counting.

Code: [Select]
for y=0 to 319
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 09, 2013, 06:56:03 PM
(http://files.allbasic.info/ScriptBasic/swcos.png)    (http://files.allbasic.info/ScriptBasic/swcos2.png)

Code: OxygenBasic
  1. ' Geoff Anderson Fractal Density Theory
  2.  
  3. DECLARE SUB DLLC_File ALIAS "dllfile" LIB "DLLC"
  4. DECLARE SUB DLLC_Proc ALIAS "dllproc" LIB "DLLC"
  5. DECLARE SUB DLLC_Call ALIAS "dllcall" LIB "DLLC"
  6.  
  7. sw = DLLC_File("sw.dll")
  8.  
  9. Window = DLLC_Proc(sw, "Window i = (i width, i height, i mode)")
  10. SetCaption = DLLC_Proc(sw, "SetCaption i = (c*capText)")
  11. SetPixel = DLLC_Proc(sw, "SetPixel i = (i xPos, i yPos, i color)")
  12. Key = DLLC_Proc(sw, "Key i = (i mKey)")
  13. Redraw = DLLC_Proc(sw, "Redraw ( )")
  14. CloseWindow = DLLC_Proc(sw, "CloseWindow i = ( )")
  15.  
  16. DLLC_Call(Window, 320, 320, 1)
  17. DLLC_Call(SetCaption,"ScriptBasic Fractal Density")
  18.  
  19. SUB Trauma(im, ii, st)
  20.  LOCAL fx, fy, i
  21.  LOCAL r, g, b, c, x, y
  22.  FOR x = 0 TO 319
  23.    i = 1
  24.    fy = 0
  25.    FOR y = 0 TO 319
  26.      c = i * (1 + COS(fx)) + i * (1 + COS(fy))
  27.      IF c <> undef THEN
  28.        DLLC_Call(SetPixel, x, 320 - y, c)
  29.      END IF
  30.      i = i * im + ii
  31.      fy += st
  32.    NEXT
  33.    fx += st
  34.   NEXT
  35. END SUB
  36.  
  37. WHILE DLLC_Call(Key, 27) = 0
  38.   m = 1
  39.   n =1
  40.   FOR i = 1 TO 120
  41.     Trauma(m, n, .01)
  42.     n += 111
  43.     DLLC_Call(Redraw)
  44.   NEXT
  45.   m = 1.0100
  46.   n = .4
  47.   FOR i = 1 TO 120
  48.     Trauma(m, n, .03)
  49.     m += .0005
  50.     DLLC_Call(Redraw)
  51.   NEXT
  52. WEND
  53.  
  54. DLLC_Call(CloseWindow)
  55.  
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 10, 2013, 01:07:06 AM
Amazing, you got it. What about the speed?  
Runs the Animation fluidly?

Looks cool, trainee.
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 10, 2013, 05:34:13 AM
Another riddle Mathe thing.
Code: [Select]
include "sw.inc"         
Window 640,480,1

Sub MultiCircle(sys xc,yc,r, single m, sys color)
sys iter=2*pi*r : single theta : sys x, y
for i=0 to i <= iter
   theta = m*pi*i / iter
   x = xc + r * cos(theta)
   y = yc + r * sin(theta)
   Line xc, yc, x, y ,4, color
next
End Sub

Cls RGB(0,0,255)
MultiCircle 300,240,140, 1.5,RGB(255,230,155)
MultiCircle 300,240,100, 1.2,RGB(55,30,155)
MultiCircle 300,240, 40, 0.5,RGB(55,130,55)
MultiCircle 300,240, 10, 2.0,RGB(255,130,55)
MultiCircle 300,240,200,32.5,RGB(255,130,55)
MultiCircle 600, 50, 25, 2.0,RGB(255,0,0) 
MultiCircle 600,420, 25,62.5,RGB(0,255,0) 
MultiCircle 60,  50, 25, 9.5,RGB(255,0,0) 
MultiCircle 60, 420, 25, 1.0,RGB(0,255,0)
 
WaitKey
Quit
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 10, 2013, 07:42:17 AM
Amazing, you got it. What about the speed?  
Runs the Animation fluidly?

It actually runs faster than I would of liked. Trying to get screen shots was a challenge.  :o

Quote
Looks cool, trainee.

Other than the cryptic value of 319, the translation to SB went great. This is a good example of the vision behind DLLC. If your amazed, you need to thank Charles for both O2 and DLLC.
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 10, 2013, 09:06:14 AM
Peter,

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

Do you have something like THIS (http://www.fractal-recursions.com/anim.html) in your bag of tricks?

John
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 10, 2013, 10:20:01 AM
Wow, looks great these fractals animations.
No, not with OxygenBasic. Here is my bag empty.  ;D
Title: Re: For Gordon and Pancho Eliott
Post by: Peter on March 10, 2013, 10:58:26 AM
Here is another simple stuff.
Code: [Select]
include "sw.inc"
Window 640, 480, 1

sys x, y, z, single x1, y1, x2, y2, winkel2
single xMagnet[768]
single yMagnet[768]
single wMagnet[768]
single sinus[360]   
single cosin[360]   

Function Distance(single x1,y1,x2,y2) as single
  single dx, dy
  dx = x1-x2
  dy = y1-y2
  Return sqr(dx*dx+dy*dy)
End Function

Function xMove(single x,winkel,speed) as single
  single x2
  x2 = x + cosin[winkel]*speed
  return x2
End Function

Function yMove(single y,winkel,speed) as single
  single y2
  y2 = y + sinus[winkel]*speed
  return y2
End Function

Function winkel(single x1,y1,x2,y2) as single
  single xhypo, yhypo, abstand, xwinkel
  xhypo = x2 - x1
  yhypo = y2 - y1
  abstand = Distance x1,y1,x2,y2
  xwinkel = abs(acos(xhypo/abstand))
  if sgn(xhypo) = -1 and sgn(yhypo) = -1 then xwinkel =180 + (180 - xwinkel)
  if sgn(xhypo) =  1 and sgn(yhypo) = -1 then xwinkel =270 + ( 90 - xwinkel)
  return xwinkel
End Function

for x=0 to 31
  for y=0 to 23
    z=y*32+x
    xMagnet[z] = x*20
    yMagnet[z] = y*20
  next
next   

for x=0 to 360
  sinus[x] = sin(x)
  cosin[x] = cos(x)
next

while Key(27)=0
Cls RGB(205,205,205)
for x=1 to 31
  for y=1 to 23
    z=y*32+x
    wMagnet[z] = winkel(xMagnet[z],yMagnet[z],xMouse,yMouse)
    x1 = xMove(xMagnet[z], wMagnet[z], 8)
    y1 = yMove(yMagnet[z], wMagnet[z], 8)
    winkel2 = wMagnet[z] - 180
    if winkel2 < 0 then winkel2 =360 + winkel2
    x2 = xMove(xMagnet[z], winkel2, 8)
    y2 = yMove(yMagnet[z], winkel2, 8)
    Line x1, y1, xMagnet[z], yMagnet[z],4, RGB(255,0,0)
    Line x2, y2, xMagnet[z], yMagnet[z],4, RGB(0,0,255)
   next   
next   
Sync()
wend

Quit()

Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 10, 2013, 04:34:58 PM
(http://files.allbasic.info/ScriptBasic/line.png)

Code: [Select]
DECLARE SUB DLLC_File ALIAS "dllfile" LIB "DLLC"
DECLARE SUB DLLC_Proc ALIAS "dllproc" LIB "DLLC"
DECLARE SUB DLLC_Call ALIAS "dllcall" LIB "DLLC"

sw = DLLC_File("sw.dll")

Window = DLLC_Proc(sw, "Window i = (i width, i height, i mode)")
SetCaption = DLLC_Proc(sw, "SetCaption i = (c*capText)")
DrawLine = DLLC_Proc(sw, "Line i = (i xPos, i yPos, i a, i b, i thickness, i color)")
xMouse = DLLC_Proc(sw, "xMouse i = ( )")
yMouse = DLLC_Proc(sw, "yMouse i = ( )")
Key = DLLC_Proc(sw, "Key i = (i mKey)")
Cls = DLLC_Proc(sw, "Cls i = (i color)")
RGB = DLLC_Proc(sw, "RGB i = (i rValue, i gValue, i bValue)")
Sync = DLLC_Proc(sw, "Sync ( )")
Quit = DLLC_Proc( sw,"Quit i = ( )")

DLLC_Call(Window, 640, 480, 1)
DLLC_Call(SetCaption,"ScriptBasic")

FUNCTION Distance(x1,y1,x2,y2)
  LOCAL dx, dy
  dx = x1-x2
  dy = y1-y2
  Distance = SQR(dx*dx+dy*dy)
END FUNCTION

FUNCTION xMove(x, winkel, speed)
  LOCAL x2
  x2 = x + cosin[winkel] * speed
  xMove = x2
END FUNCTION

FUNCTION yMove(y,winkel,speed)
  LOCAL y2
  y2 = y + sinus[winkel] * speed
  yMove = y2
END FUNCTION

FUNCTION winkel(x1, y1, x2, y2)
  LOCAL xhypo, yhypo, abstand, xwinkel
  xhypo = x2 - x1
  yhypo = y2 - y1
  abstand = Distance(x1, y1, x2, y2)
  xwinkel = ABS(ACOS(xhypo / abstand))
  IF SGN(xhypo) = -1 AND SGN(yhypo) = -1 THEN xwinkel = 180 + (180 - xwinkel)
  IF SGN(xhypo) =  1 AND SGN(yhypo) = -1 THEN xwinkel = 270 + (90 - xwinkel)
  winkel =  xwinkel
END FUNCTION

FOR x = 0 TO 31
  FOR y = 0 TO 23
    z = y * 32 + x
    xMagnet[z] = x * 20
    yMagnet[z] = y * 20
  NEXT
NEXT

FOR x = 0 TO 360
  sinus[x] = SIN(x)
  cosin[x] = COS(x)
NEXT

WHILE DLLC_Call(Key,27) = 0
  DLLC_Call(Cls, DLLC_Call(RGB,205,205,205))
  FOR x = 1 TO 31
    FOR y = 1 TO 23
      z = y * 32 + x
      wMagnet[z] = winkel(xMagnet[z], yMagnet[z], DLLC_Call(xMouse), DLLC_Call(yMouse))
      x1 = xMove(xMagnet[z], wMagnet[z], 8)
      y1 = yMove(yMagnet[z], wMagnet[z], 8)
      winkel2 = wMagnet[z] - 180
      IF winkel2 < 0 THEN winkel2 = 360 + winkel2
      x2 = xMove(xMagnet[z], winkel2, 8)
      y2 = yMove(yMagnet[z], winkel2, 8)
      DLLC_Call(DrawLine, x1, y1, xMagnet[z], yMagnet[z], 4, DLLC_Call(RGB, 255, 0, 0))
      DLLC_Call(DrawLine, x2, y2, xMagnet[z], yMagnet[z], 4, DLLC_Call(RGB, 0, 0, 255))
    NEXT
  NEXT
  DLLC_Call(Sync)
WEND

DLLC_Call(Quit)
Title: Re: For Gordon and Pancho Eliott
Post by: JRS on March 10, 2013, 07:46:52 PM
This example is more CPU demanding than the SokoMouse game. On a positive note, there was no difference in CPU demand, memory usage or expected user interaction between SB and O2.  ;D