Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created September 30, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ikr7/98160b283b667b187fc99d91c35d00b5 to your computer and use it in GitHub Desktop.
Save ikr7/98160b283b667b187fc99d91c35d00b5 to your computer and use it in GitHub Desktop.
おせえよ
package main
import (
"math/cmplx"
"image"
"image/color"
"image/png"
"os"
)
func mand (c complex128, max_iter uint8) (bool, uint8) {
z := 0 + 0i
z1 := 0 + 0i
var n uint8 = 0
for ; n < max_iter; n++ {
z1 = cmplx.Pow(z, 2) + c
if cmplx.Abs(z) > 2 {
return true, n
}
z = z1
}
return false, n;
}
func main() {
width := 640
height := 640
img := image.NewRGBA(image.Rect(0, 0, width, height))
for imy := 0; imy < height; imy++ {
for imx := 0; imx < width; imx++ {
vx := float64(imx - width / 2) / float64(width / 2) * 2.0
vy := float64(imy - height / 2) / float64(height / 2) * 2.0
c := complex(vx, vy)
divergence, speed := mand(c, 0xFF);
if (!divergence) {
img.Set(imx, imy, color.RGBA{0, 0, 0, 0xFF})
} else {
img.Set(imx, imy, color.RGBA{speed, speed, speed, 0xFF})
}
}
}
f, _ := os.Create("out.png")
defer f.Close()
png.Encode(f, img)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment