Ejemplo n.º 1
0
func main() {
	const maxX = 1024
	const maxY = 800

	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)

	f, err := os.Create("mandel.png")
	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, 1024)
			c := getColor(iter)
			m.Set(x, maxY-y, c)
		}
	}

	if err = png.Encode(f, m); err != nil {
		panic(err)
	}
}
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 maxIter = 10 * 360
	var d = mandel.NewData(640, 400, -0.7435669, 0.1314023, 0.0022878)

	for colScale := 30; colScale < 120; colScale += 30 {

		n := fmt.Sprintf("mandel-hue-%04d.png", colScale)
		fmt.Println("Render:", n)
		pi := pngimage.NewPngimage(d.MaxX, d.MaxY, n)
		it := task.IterateTasks(d, pi)

		for t := range it {
			iter := mandel.Iterate(t.CRe, t.CIm, maxIter)
			pi.Img.Set(t.X, d.MaxY-t.Y, getColor(iter, colScale))
		}
		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 main() {
	const maxIter = 1024

	const maxX = 320
	const maxY = 200

	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)

	m := make(map[int]int)

	var maxV = 0
	for y := 0; y < maxY; y++ {
		for x := 0; x < maxX; x++ {
			dx := float64(x) * hdStepX
			dy := float64(y) * hdStepY
			iter := mandel.Iterate(upperLeftRe+dx, upperLeftIm+dy, maxIter)
			m[iter] = m[iter] + 1
			if m[iter] > maxV {
				maxV = m[iter]
			}
			fmt.Println(x, maxY-y, iter)
		}
	}
	for x := 1; x <= maxV; x++ {
		for k, v := range m {
			if x == v {
				fmt.Println("iter", k, " -> count", v)
			}
		}
	}
}