Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - _vince

Pages: 1 [2]
16
Programs / Floyd–Steinberg dithering
« on: July 16, 2018, 04:30:08 am »
implementation of https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering

Code: QB64: [Select]
  1. deflng a-z
  2.  
  3. img1 = _loadimage("img/zmago.jpg", 32)
  4.  
  5. w = _width(img1)
  6. h = _height(img1)
  7.  
  8. img2 = _newimage(w, h, 32)
  9. img3 = _newimage(w, h, 32)
  10. img4 = _newimage(w, h, 32)
  11.  
  12. screen _newimage(w*2, h*2, 32)
  13.  
  14. dither_bw img1, img2, 0.1
  15.  
  16. dither img1, img3, 2
  17. dither img1, img4, 4
  18.  
  19. _putimage (0, 0), img1
  20. _putimage (w, 0), img2
  21. _putimage (0, h), img3
  22. _putimage (w, h), img4
  23.  
  24.  
  25. 'colour dither
  26. 'source image, destination image, number of colours per channel
  27. sub dither(img1, img2, num)
  28.         w = _width(img1)
  29.         h = _height(img1)
  30.  
  31.         _dest img2
  32.         _source img2
  33.  
  34.         _putimage , img1
  35.  
  36.         for y=0 to h-1
  37.         for x=0 to w-1
  38.  
  39.                 z = point(x, y)
  40.  
  41.                 r = (_red(z)*num\255)*255\num
  42.                 g = (_green(z)*num\255)*255\num
  43.                 b = (_blue(z)*num\255)*255\num
  44.  
  45.                 pset (x, y), _rgb(r, g, b)
  46.  
  47.                 qr = _red(z) - r
  48.                 qg = _green(z) - g
  49.                 qb = _blue(z) - b
  50.  
  51.                 r = _red(point(x + 1, y)) +   qr*7/16
  52.                 g = _green(point(x + 1, y)) + qg*7/16
  53.                 b = _blue(point(x + 1, y)) +  qb*7/16
  54.                 pset (x + 1, y), _rgb(r, g, b)
  55.  
  56.                 r = _red(point(x - 1, y + 1)) +   qr*3/16
  57.                 g = _green(point(x - 1, y + 1)) + qg*3/16
  58.                 b = _blue(point(x - 1, y + 1)) +  qb*3/16
  59.                 pset (x - 1, y + 1), _rgb(r, g, b)
  60.  
  61.                 r = _red(point(x, y + 1)) +   qr*5/16
  62.                 g = _green(point(x, y + 1)) + qg*5/16
  63.                 b = _blue(point(x, y + 1)) +  qb*5/16
  64.                 pset (x, y + 1), _rgb(r, g, b)
  65.  
  66.                 r = _red(point(x + 1, y + 1)) +   qr*1/16
  67.                 g = _green(point(x + 1, y + 1)) + qg*1/16
  68.                 b = _blue(point(x + 1, y + 1)) +  qb*1/16
  69.                 pset (x + 1, y + 1), _rgb(r, g, b)
  70.         next
  71.         next
  72.  
  73. 'black and white dither
  74. 'source image, destination image, bw threshold percent
  75. sub dither_bw(img1, img2, t as double)
  76.         w = _width(img1)
  77.         h = _height(img1)
  78.  
  79.         _dest img2
  80.         _source img2
  81.  
  82.         _putimage , img1
  83.  
  84.         for y=0 to h-1
  85.         for x=0 to w-1
  86.  
  87.                 z = point(x, y)
  88.  
  89.                 c = -((_red(z)+_green(z)+_blue(z))/3 > 255*t)*255
  90.  
  91.                 pset (x, y), _rgb(c, c, c)
  92.  
  93.                 qr = _red(z) - c
  94.                 qg = _green(z) - c
  95.                 qb = _blue(z) - c
  96.  
  97.                 r = _red(point(x + 1, y)) +   qr*7/16
  98.                 g = _green(point(x + 1, y)) + qg*7/16
  99.                 b = _blue(point(x + 1, y)) +  qb*7/16
  100.                 pset (x + 1, y), _rgb(r, g, b)
  101.  
  102.                 r = _red(point(x - 1, y + 1)) +   qr*3/16
  103.                 g = _green(point(x - 1, y + 1)) + qg*3/16
  104.                 b = _blue(point(x - 1, y + 1)) +  qb*3/16
  105.                 pset (x - 1, y + 1), _rgb(r, g, b)
  106.  
  107.                 r = _red(point(x, y + 1)) +   qr*5/16
  108.                 g = _green(point(x, y + 1)) + qg*5/16
  109.                 b = _blue(point(x, y + 1)) +  qb*5/16
  110.                 pset (x, y + 1), _rgb(r, g, b)
  111.  
  112.                 r = _red(point(x + 1, y + 1)) +   qr*1/16
  113.                 g = _green(point(x + 1, y + 1)) + qg*1/16
  114.                 b = _blue(point(x + 1, y + 1)) +  qb*1/16
  115.                 pset (x + 1, y + 1), _rgb(r, g, b)
  116.         next
  117.         next
  118.  

17
Programs / Cosine Transform
« on: June 27, 2018, 07:03:36 pm »
Neat program I found:

Code: QB64: [Select]
  1. defint a-z
  2.  
  3. dim shared mx,my,mbl,mbr,mw
  4. pi = 3.141593
  5.  
  6. sw = 800
  7. sh = 600
  8.  
  9. dim xx(sw - 1), x(sw - 1)
  10.  
  11. screen _newimage(sw,sh,32)
  12.  
  13.         getmouse
  14.  
  15.         line(0, 0)-(sw, sh), _rgb(0,0,0), bf
  16.  
  17.         line(sw/2, 0)-(sw/2, sh), _rgb(255,0,0)
  18.         line(0, sh/4)-(sw, sh/4), _rgb(255,0,0)
  19.         line(0, 3*sh/4)-(sw, 3*sh/4), _rgb(255,0,0)
  20.  
  21.         ox = 0
  22.         oy = 3*sh/4 - x(0)
  23.         for i = 0 to ubound(xx)
  24.                 if xx(i) <> 0 then line(i, sh/4)-step(0,-xx(i))
  25.  
  26.                 line(ox, oy)-(i, 3*sh/4 - x(i))
  27.                 ox = i
  28.                 oy = 3*sh/4 - x(i)
  29.         next
  30.  
  31.         'if m = 0 then
  32.                 line(mx, sh/4)-(mx, my)
  33.         'end if
  34.  
  35.         if mbl then
  36.                 do
  37.                         getmouse
  38.                 loop until mbl = 0
  39.  
  40.                 xx(mx) =  sh/4 - my
  41.  
  42.                 for i = 0 to ubound(x)
  43.                         x(i) = x(i) + xx(mx) * cos(2*pi*i*(mx - sw/2)*(sw))
  44.                 next
  45.         end if
  46.  
  47.         _display
  48.  
  49.  
  50. sub getmouse ()
  51.         do
  52.                 mx = _mousex
  53.                 my = _mousey
  54.                 mbl = _mousebutton(1)
  55.                 mbr = _mousebutton(2)
  56.                 mw = mw + _mousewheel
  57.         loop while _mouseinput
  58.  
  59.  

18
Programs / Lemon explorer
« on: March 19, 2018, 07:01:44 am »
Implementation of http://paulbourke.net/fractals/lemon/

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. dim uuu as double, vvv as double
  9. z = 0.01
  10. zz = 0.1
  11.  
  12. p1 = _newimage(sw, sh, 32)
  13. screen _newimage(sw, sh, 32)
  14.  
  15. redraw = -1
  16. iter = 100
  17.  
  18.         mw = 0
  19.         getMouse
  20.  
  21.         if redraw then
  22.                 line(0,0)-(sw,sh),_rgb(0,0,0),bf
  23.                 for y = 0 to sh-1
  24.                 for x = 0 to sw-1
  25.  
  26.                         xx = (x - sw/2)*z + x0
  27.                         yy = (y - sh/2)*z + y0
  28.                         u = yy
  29.                         v = xx
  30.                         j=0
  31.                         for i = 0 to iter
  32.                                 cmul uuu,vvv,u,v,u,v
  33.                                 cmul uu,vv,uuu,vvv,yy,xx
  34.                                 cmul uu,vv,uu,vv,uuu+1,vvv
  35.                                 uuu=uuu-1
  36.                                 cmul uuu,vvv,uuu,vvv,uuu,vvv
  37.                                 cdiv uu,vv,uu,vv,uuu,vvv
  38.  
  39.                                 if uu*uu + vv*vv > 10^10 then
  40.                                         i = iter
  41.                                         exit for
  42.                                 end if
  43.                                 if abs(u-uu)<0.00001 and abs(v-vv)<0.00001 then
  44.                                         j = j + 1
  45.                                 else
  46.                                         j = 0
  47.                                 end if
  48.                                 if j > 4 then exit for
  49.  
  50.                                 u = uu
  51.                                 v = vv
  52.                         next
  53.                         if i < iter then
  54.                                 c = 255-10*i
  55.                                 pset(x, y), _rgb(c,c,c)
  56.                         end if
  57.                 next
  58.                 next
  59.  
  60.                 'locate 1,1
  61.                 'print "iter =";iter
  62.  
  63.                 _dest p1
  64.                 _putimage , 0
  65.                 _dest 0
  66.  
  67.                 _putimage , p1
  68.                 _autodisplay
  69.  
  70.                 redraw = 0
  71.         end if
  72.  
  73.         if mw < 0 then
  74.                 zz = zz + 0.01
  75.         elseif mw > 0 then
  76.                 if zz > 0.01 then zz = zz - 0.01
  77.         end if
  78.  
  79.         'draw box
  80.         if omx <> mx or omy <> my or mw <> 0 then
  81.                 _putimage , p1
  82.                 line (mx - (sw*zz/2), my - (sh*zz/2))-step(sw*zz,sh*zz),_rgb(255,255,255),b
  83.                 _autodisplay
  84.  
  85.                 omx = mx
  86.                 omy = my
  87.         end if
  88.  
  89.         if mbl then
  90.                 do
  91.                         getMouse
  92.                 loop while mbl
  93.  
  94.                 x0 = x0 + (mx - sw/2)*z
  95.                 y0 = y0 - (sh/2 - my)*z
  96.                 z = z*zz
  97.                 redraw = -1
  98.         elseif mbr then
  99.                 do
  100.                         getMouse
  101.                 loop while mbr
  102.  
  103.                 x0 = x0 + (mx - sw/2)*z
  104.                 y0 = y0 - (sh/2 - my)*z
  105.                 z = z/zz
  106.                 redraw = -1
  107.         end if
  108.  
  109.         k = _keyhit
  110.         if k = 43 then
  111.                 iter = iter + 50
  112.                 redraw = -1
  113.         elseif k = 45 then
  114.                 if iter > 50 then iter = iter - 50
  115.                 redraw = -1
  116.         end if
  117.  
  118. loop until k = 27
  119.  
  120. sub getMouse ()
  121.         do
  122.                 mx = _mousex
  123.                 my = _mousey
  124.                 mbl = _mousebutton(1)
  125.                 mbr = _mousebutton(2)
  126.                 mw = mw + _mousewheel
  127.         loop while _mouseinput
  128.  
  129. sub cmul (u as double, v as double, x as double, y as double, a as double, b as double)
  130.         uu# = x*a - y*b
  131.         vv# = x*b + y*a
  132.         u = uu#
  133.         v = vv#
  134.  
  135. sub cdiv (u as double, v as double, x as double, y as double, a as double, b as double)
  136.         d# = a*a + b*b
  137.         uu# = (x*a + y*b)/d#
  138.         vv# = (y*a - x*b)/d#
  139.         u = uu#
  140.         v = vv#
  141.  

19
Programs / Chaotic scattering
« on: February 15, 2018, 06:52:14 pm »
https://en.wikipedia.org/wiki/Chaotic_scattering

Demo of the Gaspard-Rice system as described above.  Left-click to change location.

Code: QB64: [Select]
  1. defint a-z
  2. sw = 640
  3. sh = 480
  4.  
  5.  
  6. pi = 3.141593
  7.  
  8. screen _newimage(sw,sh,12)
  9.  
  10. r = 150
  11. rr = 100
  12.  
  13. 'line(0,0)-(sw,sh),0,bf
  14. 'for b=0 to 2*pi step 2*pi/3
  15. '       circle (r*cos(b)+sw/2, r*sin(b)+sh/2),rr
  16. 'next
  17. 'end
  18.  
  19. xx = sw/2
  20. yy = sh/2
  21.  
  22.         do
  23.                 mx=_mousex
  24.                 my=_mousey
  25.                 mb=_mousebutton(1)
  26.         loop while _mouseinput
  27.  
  28.         line(0,0)-(sw,sh),0,bf
  29.         for b=0 to 2*pi step 2*pi/3
  30.                 circle (r*cos(b)+sw/2, r*sin(b)+sh/2),rr
  31.         next
  32.  
  33.  
  34.         if mb then
  35.                 f = -1
  36.                 do while mb
  37.                         do
  38.                                 mb=_mousebutton(1)
  39.                         loop while _mouseinput
  40.                 loop
  41.                 for b=0 to 2*pi step 2*pi/3
  42.                         x1=r*cos(b)+sw/2
  43.                         y1=r*sin(b)+sh/2
  44.                         if (mx-x1)^2+(my-y1)^2 < rr*rr then f = 0
  45.                 next
  46.                 if f then
  47.                         xx = mx
  48.                         yy = my
  49.                         f = -1
  50.                 end if
  51.         end if
  52.  
  53.         x0 = xx
  54.         y0 = yy
  55.  
  56.         a = _atan2(my-yy,mx-xx)
  57.  
  58.         t=0
  59.         do
  60.                 t=t+1
  61.                 x = t*cos(a)+x0
  62.                 y = t*sin(a)+y0
  63.                 if x<0 or x>sw or y<0 or y>sh then exit do
  64.                 for b=0 to 2*pi step 2*pi/3
  65.                         x1=r*cos(b)+sw/2
  66.                         y1=r*sin(b)+sh/2
  67.                         if (x-x1)^2+(y-y1)^2 < rr*rr then
  68.                                 a1 = _atan2(y-y1,x-x1)
  69.                                 a2 = 2*a1-a-pi
  70.  
  71.                                 line(x0, y0)-(x,y),14
  72.  
  73.                                 x0 = x
  74.                                 y0 = y
  75.                                 a = a2
  76.                                 t=0
  77.                                 exit for
  78.                         end if
  79.                 next
  80.         loop
  81.  
  82.         line (x0,y0)-(x,y),14
  83.  
  84.         _display
  85.         _limit 50
  86.  

20
QB64 Discussion / 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.  

21
QB64 Discussion / Vince's Windowing System
« on: July 20, 2017, 02:11:30 am »
draggable scrollable windows, twm style resizing, and linked list powered textboxes in each window

Pages: 1 [2]