Skip to content

Instantly share code, notes, and snippets.

@tehsis
Created May 4, 2020 02:29
Show Gist options
  • Save tehsis/df6ecb74cbefc3dafff70bd23a9ba521 to your computer and use it in GitHub Desktop.
Save tehsis/df6ecb74cbefc3dafff70bd23a9ba521 to your computer and use it in GitHub Desktop.
package main
import (
"image"
"image/color"
"image/png"
"math/cmplx"
"math/rand"
"os"
)
func main() {
const (
xmin, ymin, xmax, ymax = -2, -2, +2, +2
width, height = 1024, 1024
)
var points [width][height]color.Color
img := image.NewRGBA(image.Rect(0, 0, width, height))
for py := range points {
y := float64(py)/height*(ymax-ymin) + ymin
for px := range points[py] {
x := float64(px)/width*(xmax-xmin) + xmin
z := complex(x, y)
points[px][py] = mandelbrot(z)
img.Set(px, py, points[px][py])
}
}
for py := 0; py < 1024/4; py += 4 {
for px := 0; px < 1024/4; px += 4 {
}
}
png.Encode(os.Stdout, img)
}
func mandelbrot(z complex128) color.Color {
const iterations = 200
const constrast = 15
var v complex128
for n := uint8(0); n < iterations; n++ {
v = v*v + z
if cmplx.Abs(v) > 2 {
return color.RGBA{255 - constrast*n, 255 - constrast*n, 255 - constrast*n, 255}
}
}
return color.RGBA{uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255))}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment