### Author Topic: Voronoi Spiral Gem  (Read 391 times)

#### B+

• Full Member
• Posts: 215
##### Voronoi Spiral Gem
« on: August 27, 2016 »
Code: [Select]
`rem http://retrogamecoding.org/board/index.php?topic=486.0rem Re: Voronoi Spiral gemrem « Reply #9 on: 25. August 2016, 13:11:47 » Mopzrem 2016-08-27 mod B+=MGA, rem I'd rather see screen update and loose a second or 2rem than stare at black black screen and wonder ifrem new version download was working ;))rem I get 163 - 167 secs on 1.3GHz gem = 700gems = gem - 1set window 16, 16, gem, gemset redraw offpoints = 36*13cy = gem/2ga# = 10.0x[points]y[points]kl[points]s# = 0.7wln "Working, please wait ..."redrawt = time()ps = points - 1for n = 0 to ps   x[n] = cy + int(s*float(n)*cos(float(n)*ga))   y[n] = cy + int(s*float(n)*sin(float(n)*ga))   if x[n] < gem and x[n] > 0 and y[n] < gem and y[n] > 0     g = 127 - abs(cy - x[n])*127 / cy + 127 - abs(cy - y[n]) * 127 / cy   else     g = 0   endif   if x[n] < gem and x[n] > 0; r = 255 - x[n]*255/gem; else; r = 0; endif   if y[n] < gem and y[n] > 0; b = y[n]*255 / gem; else; b = 0; endif   kl[n] = (r SHL 16) + (g SHL 8) + b   set colori kl[n]   _DrawFilledCircle int(x[n]), int(y[n]), 2nextfor xx = 0 to gem for yy = 0 to gem d = gem*gem + 1 for i = 0 to points - 1 a = x[i] - xx; b = y[i] - yy q = a*a + b*b if q < d; d = q; kkl = i; endif next set colori kl[kkl] set pixel xx, yy next redrawnextset color 255, 255, 255set caret 0, 0wln "Time: ", (time() - t)/1000redrawwait keydownprocedure DrawCircle(x0, y0, radius) x = radius y = 0 err = 0 while x >= y draw pixel x0 + x, y0 + y draw pixel x0 - x, y0 + y draw pixel x0 + y, y0 + x draw pixel x0 - y, y0 + x draw pixel x0 - x, y0 - y draw pixel x0 + x, y0 - y draw pixel x0 - y, y0 - x draw pixel x0 + y, y0 - x y = y + 1 err = err + 1 + 2*y if 2*(err - x) + 1 > 0 x = x - 1 err = err + 1 - 2*x endif wendendprocprocedure DrawFilledCircle(x0, y0, radius) x = radius y = 0 err = 0 while x >= y x2 = x*2; y2 = y*2 draw rect x0 - x, y0 + y, x2, 1, true draw rect x0 - y, y0 + x, y2, 1, true draw rect x0 - x, y0 - y, x2, 1, true draw rect x0 - y, y0 - x, y2, 1, true y = y + 1 err = err + 1 + 2*y if 2*(err - x) + 1 > 0 x = x - 1 err = err + 1 - 2*x endif wendendproc`
PS I think this circle fill might be better than what Rick and I came up with!
« Last Edit: August 27, 2016 by B+ »
B+

#### Rick3137

• Sr. Member
• Posts: 347
• May the Force be with You
##### Re: Voronoi Spiral Gem
« Reply #1 on: August 27, 2016 »
NaaLaa shows a big improvement over SDLbasic.

I get 44 seconds on my 1.9 ghz System. SDLBasic was 3 minutes, 38 seconds.