Author Topic: Burning ship explorer  (Read 6656 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Burning ship explorer
« on: July 21, 2017, 07:41:07 pm »
left mouse, zoom in
right mouse, zoom out
mousewheel, zoom size
+, increase iterations
-, decrease iterations

(edit: added other variations commented out)
Code: QB64: [Select]
  1. defint a-z
  2.  
  3. const sw = 640
  4. const sh = 480
  5.  
  6. dim shared mx,my,mbl,mbr,mw
  7.  
  8. z = 0.01
  9. zz = 0.1
  10.  
  11. p1 = _newimage(sw, sh, 12)
  12. screen _newimage(sw, sh, 12)
  13.  
  14. redraw = -1
  15. iter = 100
  16.  
  17.         mw = 0
  18.         getMouse
  19.  
  20.         if redraw then
  21.                 for y = 0 to sh-1
  22.                 for x = 0 to sw-1
  23.                         u = 0
  24.                         v = 0
  25.  
  26.                         xx = (x - sw/2)*z + x0
  27.                         yy = (y - sh/2)*z + y0
  28.                         for i = 0 to iter
  29.                                 '''mandelbrot
  30.                                 'u = u
  31.                                 'v = v
  32.                                 'uu = u*u - v*v + xx
  33.                                 'vv = 2*u*v + yy
  34.                                 '''
  35.  
  36.                                 '''burning ship
  37.                                 u = abs(u)
  38.                                 v = abs(v)
  39.                                 uu = u*u - v*v + xx
  40.                                 vv = 2*u*v + yy
  41.                                 '''
  42.  
  43.                                 '''tricorn
  44.                                 'u = u
  45.                                 'v = -v
  46.                                 'uu = u*u - v*v + xx
  47.                                 'vv = 2*u*v + yy
  48.                                 '''
  49.  
  50.                                 '''tetration
  51.                                 'u = u
  52.                                 'v = v
  53.                                 'cexp uu, vv, u, v, u, v
  54.                                 'cexp uu, vv, uu, vv, xx, yy
  55.                                 '''
  56.  
  57.                                 '''other, the possibilities are infinite
  58.                                 'if u > v then
  59.                                 '       u = -abs(u)
  60.                                 '       v = v
  61.                                 'elseif -1 then
  62.                                 '       u = u
  63.                                 '       v = -abs(v)
  64.                                 'end if
  65.                                 'uu = u*u - v*v + xx
  66.                                 'vv = 2*u*v + yy
  67.                                 '''
  68.  
  69.                                 u = uu
  70.                                 v = vv
  71.  
  72.                                 if (u*u + v*v) > 4 then exit for
  73.                         next
  74.                         if i > iter then i = 0
  75.                         pset(x, y), i
  76.                 next
  77.                 next
  78.  
  79.                 locate 1,1
  80.                 print "iter =";iter
  81.  
  82.                 _dest p1
  83.                 _putimage , 0
  84.                 _dest 0
  85.  
  86.                 _putimage , p1
  87.                 _display
  88.  
  89.                 redraw = 0
  90.         end if
  91.  
  92.         if mw < 0 then
  93.                 zz = zz + 0.01
  94.         elseif mw > 0 then
  95.                 if zz > 0.01 then zz = zz - 0.01
  96.         end if
  97.  
  98.         'draw box
  99.         if omx <> mx or omy <> my or mw <> 0 then
  100.                 _putimage , p1
  101.                 line (mx - (sw*zz/2), my - (sh*zz/2))-step(sw*zz,sh*zz),14,b
  102.                 _display
  103.  
  104.                 omx = mx
  105.                 omy = my
  106.         end if
  107.  
  108.         if mbl then
  109.                 do
  110.                         getMouse
  111.                 loop while mbl
  112.  
  113.                 x0 = x0 + (mx - sw/2)*z
  114.                 y0 = y0 - (sh/2 - my)*z
  115.                 z = z*zz
  116.                 redraw = -1
  117.         elseif mbr then
  118.                 do
  119.                         getMouse
  120.                 loop while mbr
  121.  
  122.                 x0 = x0 + (mx - sw/2)*z
  123.                 y0 = y0 - (sh/2 - my)*z
  124.                 z = z/zz
  125.                 redraw = -1
  126.         end if
  127.  
  128.         k = _keyhit
  129.         if k = 43 then
  130.                 iter = iter + 50
  131.                 redraw = -1
  132.         elseif k = 45 then
  133.                 if iter > 50 then iter = iter - 50
  134.                 redraw = -1
  135.         end if
  136.  
  137. loop until k = 27
  138.  
  139. sub getMouse ()
  140.         do
  141.                 mx = _mousex
  142.                 my = _mousey
  143.                 mbl = _mousebutton(1)
  144.                 mbr = _mousebutton(2)
  145.                 mw = mw + _mousewheel
  146.         loop while _mouseinput
  147.  
  148. 'u + iv = (x + iy) ^ (a + ib)
  149. sub cexp (u as double, v as double, x as double, y as double, a as double, b as double)
  150.         dim mag as double, arg as double
  151.         dim lnz as double, argz as double
  152.  
  153.         lnz = 0.5*log((x*x + y*y)+0.00001)
  154.         argz = _atan2(y, x)
  155.  
  156.         mag = exp(a*lnz - b*argz)
  157.         arg = a*argz + b*lnz
  158.  
  159.         u = mag * cos(arg)
  160.         v = mag * sin(arg)
  161.  
« Last Edit: July 23, 2017, 06:28:53 pm by v »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Burning ship explorer
« Reply #1 on: July 21, 2017, 11:17:13 pm »
Nice, I've got some waves for your ship.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Burning ship explorer
« Reply #2 on: July 22, 2017, 04:07:47 am »
Beautiful. This deserves an entry at https://qb64.org/samples/. Let's hope that Odin gets around to it.
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Burning ship explorer
« Reply #3 on: July 22, 2017, 07:26:11 am »
Very nice!

FellippeHeitor

  • Guest
Re: Burning ship explorer
« Reply #4 on: July 22, 2017, 09:57:52 am »
I feel the time around me was going slower every time I zoomed in, and then suddenly I started hearing the initial chords of "Non je ne regrette rien" and decided to leave it.

Awesome job here, v.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Burning ship explorer
« Reply #5 on: July 23, 2017, 08:29:06 am »
Wow! It's Awesome! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline SkyCharger001

  • Newbie
  • Posts: 14
    • View Profile
Re: Burning ship explorer
« Reply #6 on: July 23, 2017, 11:55:07 am »
you only need to calculate the screen-center once
Code: QB64: [Select]
  1. CONST sw=640
  2. CONST sh=480
  3. CONST zw=sw/2
  4. CONST zh=sh/2
  5.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Burning ship explorer
« Reply #7 on: February 24, 2018, 02:03:33 am »
test