Listen to QB64 Report!Our podcast on all things QB64 is out now. Listen athttp://podcast.qb64.org
0 Members and 1 Guest are viewing this topic.
deflng a-zdim shared sw, shsw = 1024sh = 600dim shared pi as doublepi = 4*atn(1)screen _newimage(sw, sh, 32) dim as long n, r, mx, my, mb, omx, omyn = 0redim x(n) as long, y(n) as long r = 5do getmouse mx, my, mb if mb = 1 then n = 1 redim _preserve x(n) redim _preserve y(n) x(0) = mx - sw/2 y(0) = sh/2 - my pset (mx, my) do while mb = 1 getmouse mx, my, mb line -(mx, my), _rgb(30,30,30) if (mx - omx)^2 + (my - omy)^2 > r^2 then circlef mx, my, 3, _rgb(30,30,30) omx = mx omy = my x(n) = mx - sw/2 y(n) = sh/2 - my n = n + 1 redim _preserve x(n) redim _preserve y(n) end if _display _limit 50 loop 'close the contour 'x(n) = x(0) 'y(n) = y(0) 'n = n + 1 'redim _preserve x(n) 'redim _preserve y(n) 'redraw spline 'pset (sw/2 + x(0), sh/2 - y(0)) 'for i=0 to n 'line -(sw/2 + x(i), sh/2 - y(i)), _rgb(255,0,0) 'circlef sw/2 + x(i), sh/2 - y(i), 3, _rgb(255,0,0) 'next dim as double bx, by, t, bin pset (sw/2 + x(0), sh/2 - y(0)) for t=0 to 1 step 0.0001 bx = 0 by = 0 for i=0 to n bin = 1 for j=1 to i bin = bin*(n - j)/j next bx = bx + bin*((1 - t)^(n - 1 - i))*(t^i)*x(i) by = by + bin*((1 - t)^(n - 1 - i))*(t^i)*y(i) next line -(sw/2 + bx, sh/2 - by), _rgb(255,0,0) next end if _display _limit 50loop until _keyhit = 27systemsub getmouse (mx as long, my as long, mb as long) do mx = _mousex my = _mousey mb = -_mousebutton(1) loop while _mouseinputend sub sub circlef(x as long, y as long, r as long, c as long) dim as long x0, y0, e x0 = r y0 = 0 e = -r do while y0 < x0 if e <=0 then y0 = y0 + 1 line (x - x0, y + y0)-(x + x0, y + y0), c, bf line (x - x0, y - y0)-(x + x0, y - y0), c, bf e = e + 2*y0 else line (x - y0, y - x0)-(x + y0, y - x0), c, bf line (x - y0, y + x0)-(x + y0, y + x0), c, bf x0 = x0 - 1 e = e - 2*x0 end if loop line (x - r, y)-(x + r, y), c, bfend sub