func main() {
	const maxIter = 10 * 360

	const maxX = 600
	const maxY = 480

	var iteration [maxX][maxY]int

	const centerRe, centerIm float64 = -0.7435669, 0.1314023
	const hd float64 = 0.0022878
	const hv float64 = float64(maxY) / float64(maxX) * hd

	const hdStepX = hd / maxX
	const hdStepY = hv / maxY

	const upperLeftRe = centerRe - (float64(maxX/2) * hdStepX)
	const upperLeftIm = centerIm - (float64(maxY/2) * hdStepY)

	fmt.Println("Iterate")
	for y := 0; y < maxY; y++ {
		for x := 0; x < maxX; x++ {
			dx := float64(x) * hdStepX
			dy := float64(y) * hdStepY
			iteration[x][y] = mandel.Iterate(upperLeftRe+dx, upperLeftIm+dy, maxIter)
		}
	}

	m := image.NewRGBA(image.Rect(0, 0, maxX, maxY))
	b := m.Bounds()
	for colorShift := 0; colorShift < 36; colorShift++ {
		for y := b.Min.Y; y < b.Max.Y; y++ {
			for x := b.Min.X; x < b.Max.X; x++ {
				iter := iteration[x][y]
				c := hue.Color(float64((iter+colorShift*10)%360) / 360.0)
				m.Set(x, maxY-y, c)
			}
		}
		n := fmt.Sprintf("mandel-hue-colorshift-%02d.png", colorShift)
		fmt.Println("write file", n)
		f, err := os.Create(n)
		if err != nil {
			panic(err)
		}
		if err = png.Encode(f, m); err != nil {
			panic(err)
		}
	}
}
func main() {
	var err error
	var c color.Color
	maxX := 3 * 360
	pi := pngimage.NewPngimage(maxX-1, 240, "hue.png")
	b := pi.Img.Bounds()
	for y := b.Min.Y; y < b.Max.Y; y++ {
		for x := b.Min.X; x < b.Max.X; x++ {
			if c, err = hue.Color(float64(x) / float64(maxX)); err != nil {
				panic(err)
			}
			pi.Img.Set(x, y, c)
		}
	}
	pi.Save()
}
Exemple #3
0
func main() {
	var c color.Color
	var err error
	pi := pngimage.NewPngimage(360-1, 240, "use-hue.png")
	b := pi.Img.Bounds()
	for y := b.Min.Y; y < b.Max.Y; y++ {
		for x := b.Min.X; x < b.Max.X; x++ {
			h := float64(x) / 60.0
			h = h - math.Floor(h)
			if c, err = hue.Color(h); err != nil {
				panic(err)
			}
			pi.Img.Set(x, y, c)
		}
	}
	pi.Save()
}
func main() {
	const maxX = 640
	const maxY = 400

	const centerRe, centerIm float64 = -0.7435669, 0.1314023
	const hd float64 = 0.0022878
	const hv float64 = float64(maxY) / float64(maxX) * hd

	const hdStepX = hd / maxX
	const hdStepY = hv / maxY

	const upperLeftRe = centerRe - (float64(maxX/2) * hdStepX)
	const upperLeftIm = centerIm - (float64(maxY/2) * hdStepY)

	for colScale := 30; colScale < 360*2; colScale += 30 {
		n := fmt.Sprintf("mandel-hue-%04d.png", colScale)
		fmt.Println("Render n:", n)
		f, err := os.Create(n)
		if err != nil {
			panic(err)
		}
		m := image.NewRGBA(image.Rect(0, 0, maxX, maxY))
		b := m.Bounds()
		for y := b.Min.Y; y < b.Max.Y; y++ {
			for x := b.Min.X; x < b.Max.X; x++ {
				dx := float64(x) * hdStepX
				dy := float64(y) * hdStepY
				iter := mandel.Iterate(upperLeftRe+dx, upperLeftIm+dy, maxIter)
				c := float64(iter) / float64(colScale)
				c = c - math.Floor(c)
				m.Set(x, maxY-y, hue.Color(c))
			}
		}

		if err = png.Encode(f, m); err != nil {
			panic(err)
		}
	}
}
func TestErrorPositive(t *testing.T) {
	_, err := hue.Color(1.1)
	if err == nil {
		t.Errorf("No error with hue = %v", 1.1)
	}
}
func TestErrorNagative(t *testing.T) {
	_, err := hue.Color(-0.1)
	if err == nil {
		t.Errorf("No error with hue = %v", -0.1)
	}
}
func TestMagenta(t *testing.T) {
	color, _ := hue.Color(5 * step)
	if magenta != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 5*step, magenta, color)
	}
}
func TestBlue(t *testing.T) {
	color, _ := hue.Color(4 * step)
	if blue != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 4*step, blue, color)
	}
}
func TestCyan(t *testing.T) {
	color, _ := hue.Color(3 * step)
	if cyan != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 3*step, cyan, color)
	}
}
Exemple #10
0
func TestGreen(t *testing.T) {
	color, _ := hue.Color(2 * step)
	if green != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 2*step, green, color)
	}
}
Exemple #11
0
func TestYellow(t *testing.T) {
	color, _ := hue.Color(1 * step)
	if yellow != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 1*step, yellow, color)
	}
}
Exemple #12
0
func TestRed(t *testing.T) {
	color, _ := hue.Color(0 * step)
	if red != color {
		t.Errorf("hue.Color(%v) = %v, want %v", 0*step, red, color)
	}
}