-
-
Save azyobuzin/5583710949115e4df11175ea11567f86 to your computer and use it in GitHub Desktop.
おせえよ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math/cmplx" | |
"image" | |
"image/color" | |
"image/png" | |
"os" | |
"fmt" | |
"time" | |
) | |
func square(c complex128) complex128 { | |
a := real(c) | |
b := imag(c) | |
return complex(a * a - b * b, 2.0 * a * b) | |
} | |
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 = square(z) + c | |
if cmplx.Abs(z) > 2 { | |
return true, n | |
} | |
z = z1 | |
} | |
return false, n; | |
} | |
func main() { | |
t := time.Now() | |
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.SetRGBA(imx, imy, color.RGBA{0, 0, 0, 0xFF}) | |
} else { | |
img.SetRGBA(imx, imy, color.RGBA{speed, speed, speed, 0xFF}) | |
} | |
} | |
} | |
f, _ := os.Create("out2.png") | |
defer f.Close() | |
png.Encode(f, img) | |
fmt.Println(time.Now().Sub(t)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment