Exemplo n.º 1
0
func renderMandelbrot() (err error) {
	flag.Parse()

	c := canvas.NewCanvas(width, height)
	for x := 0; x < c.Bounds().Size().X; x++ {
		for y := 0; y < c.Bounds().Size().Y; y++ {
			c.Set(x, y, color.RGBA{0, 0, 0, 255})
		}
	}
	switch colorScheme {
	case "smooth":
		f := fractal.Fractal{
			Src:    c.RGBA,
			Iter:   iterations,
			Center: complex(centerReal, centerImag),
			Zoom:   zoom,
		}
		mandel.Smooth(&f)
	case "random":
		mandel.Draw(c.RGBA, zoom, complex(centerReal, centerImag), iterations, fractal.NewRandomGradient(iterations))
	case "pretty":
		mandel.Draw(c.RGBA, zoom, complex(centerReal, centerImag), iterations, fractal.NewPrettyGradient(iterations))
	case "pedagogical":
		mandel.Draw(c.RGBA, zoom, complex(centerReal, centerImag), iterations, fractal.PedagogicalGradient)
	case "orbit":
		// f, err := os.Open("z.png")
		// if err != nil {
		// 	return err
		// }
		// defer f.Close()
		// src, err := png.Decode(f)
		// if err != nil {
		// 	return err
		// }
		// mandel.DrawOrbit(src, c.RGBA, zoom, complex(centerReal, centerImag), iterations)
	case "julia":
		// mandel.DrawJulia(src, c.RGBA, zoom, complex(centerReal, centerImag), iterations)
	default:
		log.Fatalln(errutil.Newf("undefined color scheme: %s", colorScheme))
	}

	err = c.Save(filename)
	if err != nil {
		return errutil.Err(err)
	}

	return nil
}
Exemplo n.º 2
0
Arquivo: a.go Projeto: karlek/vanilj
// loadResources loads the background and foreground images.
func loadResources() (err error) {
	c := canvas.NewCanvas(width, height)
	for x := 0; x < c.Bounds().Size().X; x++ {
		for y := 0; y < c.Bounds().Size().Y; y++ {
			c.Set(x, y, color.RGBA{0, 0, 0, 255})
		}
	}

	f := fractal.Fractal{
		Src:    c.RGBA,
		Iter:   iterations,
		Center: complex(centerReal, centerImag),
		Zoom:   zoom,
	}
	mandel.Smooth(&f)

	// Load background image.
	fractalImg, err = win.ReadImage(f.Src)
	if err != nil {
		return err
	}
	return nil
}