// NewMandelbrot returns a mandelbrot-set calculator // that shows at least the area r within wr. // func NewMandelbrot(r crect, wr draw.Rectangle, julia bool, jpoint complex128, iterations int) *Mandelbrot { btall := float64(wr.Dy()) / float64(wr.Dx()) atall := (imag(r.min) - imag(r.min)) / (real(r.max) - real(r.min)) if btall > atall { // bitmap is taller than area, so expand area vertically excess := (real(r.max)-real(r.min))*btall - (imag(r.max) - imag(r.min)) r.min -= cmplx(0, excess/2.0) r.max += cmplx(0, excess/2.0) } else { // area is taller than bitmap, so expand area horizontally excess := (imag(r.max)-imag(r.min))/btall - (real(r.max) - real(r.min)) r.min -= cmplx(excess/2.0, 0) r.max += cmplx(excess/2.0, 0) } var m Mandelbrot m.iterations = iterations m.palette = makePalette(range0, iterations) m.origin = r.min m.julia = julia m.jpoint = jpoint m.cr = r m.delta = cmplx( (real(r.max)-real(r.min))/float64(wr.Dx()), (imag(r.max)-imag(r.min))/float64(wr.Dy()), ) m.r = wr return &m }
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 }