func Start(im *image.RGBA, num int, vpx, vpy, d float64, ch chan<- point) { share := im.Height() / num for i := 0; i < num; i += 1 { go Mandelbrot(im, i*share, (i+1)*share, vpx, vpy, d, ch) } }
func handleChans(im *image.RGBA, ch <-chan point) { counter := 0 pixCount := im.Height() * im.Width() for counter < pixCount { counter += 1 p := <-ch im.Pixel[p.x][p.y] = p.color } }
func Mandelbrot(im *image.RGBA, lineMin, lineMax int, vpx, vpy, d float64, ch chan<- point) { width := float64(im.Width()) height := float64(im.Height()) for i := lineMin; i < lineMax; i++ { for j := 0; j < im.Height(); j++ { x0 := float64(i)/(width/d) - d/2.0 + vpx y0 := float64(j)/(height/d) - d/2.0 + vpy ch <- point{i, j, getPixelAt(y0, x0)} } } }
func NewTile(r draw.Rectangle, calc Fractal, img *image.RGBA, wait bool) *Tile { t := new(Tile) t.r = r t.nrows = 0 if img == nil { img = image.NewRGBA(image.Rect(0, 0, r.Dx(), r.Dy())) } t.calc = calc t.image = img if wait { t.calculate(nil, nil) t.nrows = img.Height() } else { // choose some vaguely appropriate colour col := calc.At(centre(r)) draw.Draw(t.image, draw.Rect(0, 0, r.Dx(), r.Dy()), image.Uniform{col}, draw.ZP) } return t }