Author Topic: Curlicue Fractal  (Read 10009 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Curlicue Fractal
« on: October 28, 2015, 12:31:07 PM »
I have been following the Curlicue Fractal posts and I can't seem to get a Script BASIC with SDL_gfx to work. I'm thinking it might be a RAD() issue with cos/sin functions.  :o

Code: Script BASIC
  1. ' ScriptBasic GFX - Curlicue Fractal
  2.  
  3. IMPORT gfx.inc
  4.  
  5. s = gfx::Window(1200,700,"Script BASIC SDL_gfx - Curlicue Fractal")
  6. ts = gfx::Time()
  7.  
  8. x = 0
  9. y = 0
  10. f = 0
  11. x1 = 0
  12. y1 = 0
  13. Ang = 0
  14. r = 500
  15.  
  16. FOR a = 0 TO 400000
  17.   Ang = Ang + .0001
  18.   IF Ang > 7 THEN Ang = 0
  19.   f = f - PI * PI
  20.   x = x + cos(f * f)
  21.   y = y + sin(f * f)
  22.   x1 = x + r + cos(Ang) * r / 8
  23.   y1 = y + r + sin(Ang) * r / 8
  24.   x3 = r - cos(Ang) * r / 8 - x
  25.   gfx::PixelRGBA s, x1, y1 - 500, a, x, y, a
  26.   gfx::PixelRGBA s, x3, y1 - 500, a, x, y, a
  27. NEXT
  28.  
  29. te = gfx::Time()
  30. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xFFFFFFFF
  31. gfx::Update
  32. WHILE gfx::KeyName(1) <> "+escape"
  33. WEND
  34. gfx::Close
  35.  


.
« Last Edit: October 28, 2015, 01:22:17 PM by John »

Aurel

  • Guest
Re: Curlicue Fractal
« Reply #1 on: October 29, 2015, 02:48:52 PM »
John dont use angles

f = f - PI * PI

f=f + 0.003

JRS

  • Guest
Re: Curlicue Fractal
« Reply #2 on: October 29, 2015, 03:00:50 PM »
Thanks for the reply but it causes a seg fault.  :o

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #3 on: October 29, 2015, 03:32:43 PM »
According to Item 5.4.4 of ECMA-116 BASIC Standard of June 1986, angle input to numeric functions (such as used in trigonometry) should be expressed in radians unless OPTION ANGLE DEGREES is in effect. This effectively unties the hands of such BASIC developers who don't support OPTION metacommands in their dialects at all, and allows them to decide themselves what units those dialects would assume as default since there's no way to toggle that OPTION in a particular dialect.

IMO any units would do as long as the dialect provides adequate conversion commands (functions). FBSL BASIC uses radians on default but provides Radians(deg) and Degrees(rad) functions for conversion at the user's option.

[UPD] When your render loop is used in FBSL BASIC with the following redundant param conversion:
Code: OxygenBasic
  1. ........
  2. For a = 0 To 400000
  3.   ang = ang + 0.0001
  4.   If ang > 7 Then ang = 0
  5.   f = f - PI * PI
  6.   x = x + Cos(f * f)
  7.   y = y + Sin(f * f)
  8.   x1 = x + r + Cos(Radians(ang)) * r / 8
  9.   y1 = y + r + Sin(Radians(ang)) * r / 8
  10.   x2 = r - Cos(Radians(ang)) * r / 8 - x
  11.   PSet(hDC, x1, y1 - 500, RGB(a, x, y))
  12.   PSet(hDC, x2, y1 - 500, RGB(a, x, y))
  13. Next
  14. ........
it generates such a simpatico ivy devil: :)

.
« Last Edit: October 29, 2015, 04:35:43 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Curlicue Fractal
« Reply #4 on: October 29, 2015, 05:40:31 PM »
Still seg faults for me.  :'(

Code: Script BASIC
  1. ' ScriptBasic GFX - Curlicue Fractal
  2.  
  3. IMPORT gfx.inc
  4.  
  5. s = gfx::Window(1200,700,"Script BASIC SDL_gfx - Curlicue Fractal")
  6. ts = gfx::Time()
  7.  
  8. a = 0
  9. f =0
  10. y = 0
  11. f = 0
  12. x1 = 0
  13. x2 = 0
  14. y1 = 0
  15. ang = 0
  16. r = 500
  17.  
  18. FOR a = 0 TO 400000
  19.   ang = ang + 0.0001
  20.   If ang > 7 Then ang = 0
  21.   f = f - PI * PI
  22.   x = x + Cos(f * f)
  23.   y = y + Sin(f * f)
  24.   x1 = x + r + Cos(RAD(ang)) * r / 8
  25.   y1 = y + r + Sin(RAD(ang)) * r / 8
  26.   x2 = r - Cos(RAD(ang)) * r / 8 - x
  27.   gfx::PixelRGBA s, INT(x1), INT(y1 - 500), INT(a), INT(x), INT(y), 255
  28.   gfx::PixelRGBA s, INT(x2), INT(y1 - 500), INT(a), INT(x), INT(y), 255
  29. NEXT
  30.  
  31. te = gfx::Time()
  32. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xFFFFFFFF
  33. gfx::Update
  34. WHILE gfx::KeyName(1) <> "+escape"
  35. WEND
  36. gfx::Close
  37.  

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #5 on: October 29, 2015, 06:11:57 PM »
Try remming out the lines from bottom to top within the loop to see which one exactly causes the segfault. If the offending lines are those two gfx commands at the bottom, try and substitute them with other gfx calls with the same x and y. If those segfault as well, try them with some fixed x and y that would certainly fit within the specified canvas size. Do you remember you had some problems with SDL canvas cropping when you were developing your SDL gfx proxy library/module a couple years ago or so?

JRS

  • Guest
Re: Curlicue Fractal
« Reply #6 on: October 29, 2015, 09:59:50 PM »
Thanks for the hint. My first problem was that x wasn't initialized and that was passed along onto the x1 result which ended up undef. The problem now is I'm generating numbers (negative & out of range) that SDL_gfx PixelRGBA doesn't like. As far as the old problem of putting pixels outside the window goes, (clipping) that was resolved long ago and not related to this issue. I'm thinking the color values for RGB is the issue.

Code: Script BASIC
  1. ' ScriptBasic GFX - Curlicue Fractal
  2.  
  3. IMPORT gfx.inc
  4.  
  5. s = gfx::Window(1200,700,"Script BASIC SDL_gfx - Curlicue Fractal")
  6. ts = gfx::Time()
  7.  
  8. a = 0
  9. f =0
  10. x =0
  11. y = 0
  12. f = 0
  13. x1 = 0
  14. x2 = 0
  15. y1 = 0
  16. ang = 0
  17. r = 500
  18.  
  19. FOR a = 0 TO 400000
  20.   ang = ang + 0.0001
  21.   If ang > 7 Then ang = 0
  22.   f = f - PI * PI
  23.   x = x + Cos(f * f)
  24.   y = y + Sin(f * f)
  25.   x1 = x + r + Cos(RAD(ang)) * r / 8
  26.   y1 = y + r + Sin(RAD(ang)) * r / 8
  27.   x2 = r - Cos(RAD(ang)) * r / 8 - x
  28.  
  29. PRINT "x1: ",x1,"\n"
  30. PRINT "y1 - 500: ",y1 - 500,"\n"
  31. PRINT "a: ",a,"\n"
  32. PRINT "x: ",x,"\n"
  33. PRINT "y: ",y,"\n"
  34. LINE INPUT wait
  35.  
  36. ' gfx::PixelRGBA s, ABS(INT(x1)), ABS(INT(y1 - 500)), ABS(INT(a)), ABS(INT(x)), ABS(INT(y)), 255
  37. ' gfx::PixelRGBA s, INT(x2), INT(y1 - 500), INT(a), INT(x), INT(y), 255
  38. NEXT
  39.  
  40. te = gfx::Time()
  41. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xFFFFFFFF
  42. gfx::Update
  43. WHILE gfx::KeyName(1) <> "+escape"
  44. WEND
  45. gfx::Close
  46.  


jrs@laptop:~/sb/sb22/gfx$ scriba curlicue.sb
x1: 5.615002e+02
y1 - 500: -1.960177e-02
a: 0
x: -9.998057e-01
y: -1.971085e-02

x1: 5.624971e+02
y1 - 500: 5.927415e-02
a: 1
x: -2.912656e-03
y: 5.905598e-02

x1: 5.615128e+02
y1 - 500: -1.170967e-01
a: 2
x: -9.872169e-01
y: -1.174240e-01



.
« Last Edit: October 30, 2015, 01:52:37 AM by John »

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #7 on: October 30, 2015, 05:17:28 AM »
2. :D

1. Try AND-ing each of them with 0xFF (or 255).

JRS

  • Guest
Re: Curlicue Fractal
« Reply #8 on: October 30, 2015, 12:55:39 PM »
Code: Script BASIC
  1. gfx::PixelRGBA s, ABS(INT(x1)), ABS(INT(y1 - 500)), ABS(INT(a)) AND 255, ABS(INT(x)) AND 255, ABS(INT(y)) AND 255, 255
  2.  


jrs@laptop:~/sb/sb22/gfx$ scriba curlicue.sb
Segmentation fault (core dumped)
jrs@laptop:~/sb/sb22/gfx$


Strange why this is so difficult for SB.

Aurel

  • Guest
Re: Curlicue Fractal
« Reply #9 on: October 31, 2015, 01:34:48 PM »
Quote
Strange why this is so difficult for SB

Strange...Strange for me is why Peter scarab is fine when i compile
under o2 and i use same function like i do in my crappy interpreter
but i get freaking image... ;D
« Last Edit: November 01, 2015, 02:07:17 AM by Aurel »

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #10 on: October 31, 2015, 02:19:06 PM »
Code: Script BASIC
  1. gfx::PixelRGBA s, ABS(INT(x1)), ABS(INT(y1 - 500)), ABS(INT(a)) AND 255, ABS(INT(x)) AND 255, ABS(INT(y)) AND 255, 255
  2.  

And what happens if it is
Code: Script BASIC
  1. gfx::PixelRGBA s, INT(ABS(x1)), INT(ABS(y1 - 500)), INT(ABS(a)) AND 255, INT(ABS(x)) AND 255, INT(ABS(y)) AND 255, 255
  2.  
?

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #11 on: October 31, 2015, 02:27:00 PM »
Hehe Aurel, you raised much ado about that curlicue fractal of yours on BASIC forums, didn't you? :)

JRS

  • Guest
Re: Curlicue Fractal
« Reply #12 on: October 31, 2015, 02:39:49 PM »
Quote from: Mike
And what happens if it is
Code: Script BASIC
  1.     gfx::PixelRGBA s, INT(ABS(x1)), INT(ABS(y1 - 500)), INT(ABS(a)) AND 255, INT(ABS(x)) AND 255, INT(ABS(y)) AND 255, 255
  2.  
     

?


jrs@laptop:~/sb/sb22/gfx$ scriba curlicue.sb
Segmentation fault (core dumped)
jrs@laptop:~/sb/sb22/gfx$


Script BASIC SDL_gfx - Bitbucket

Mike Lobanovsky

  • Guest
Re: Curlicue Fractal
« Reply #13 on: October 31, 2015, 03:27:25 PM »
Hmmmm....

Quote
Script BASIC SDL_gfx - Bitbucket

And the full 32-bit scriba installation distro?

Will SB22_beta_windows_32.zip + scriba_Windows32_b2.zip suffice? Does the latter overwrite the former?

TIA
« Last Edit: October 31, 2015, 03:46:09 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Curlicue Fractal
« Reply #14 on: October 31, 2015, 05:28:07 PM »
Mike,

I think any of the SDL_gfx SB ext. modules would work for this problem. I think I added the Mandelbrot iterator in the last version.