Created
November 1, 2016 12:44
-
-
Save ikr7/ab0121d960b153a447adde40d57cde62 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" | |
) | |
var a = 0.0 + 0.0i | |
var b = 0.0 + 0.0i | |
var c = 0.0 + 0.0i | |
var d = 0.0 + 0.0i | |
const im_w = 1440 | |
const im_h = 900 | |
const vi_w = 2.0 | |
const vi_h = vi_w / float64(im_w) * float64(im_h) | |
var img = image.NewRGBA(image.Rect(0, 0, im_w, im_h)) | |
func f1 (z complex128) (complex128) { | |
return a * z + b * cmplx.Conj(z) | |
} | |
func f2 (z complex128) (complex128) { | |
return c * (z - 1) + d * (cmplx.Conj(z) - 1) + 1 | |
} | |
func draw (z complex128, depth int) () { | |
if (depth > 15) { | |
return | |
} | |
z1 := f1(z) | |
z2 := f2(z) | |
x1 := int((real(z1) + (vi_w / 2)) / (vi_w / float64(im_w))) | |
y1 := int((imag(z1) + (vi_h / 2)) / (vi_h / float64(im_h))) | |
x2 := int((real(z2) + (vi_w / 2)) / (vi_w / float64(im_w))) | |
y2 := int((imag(z2) + (vi_h / 2)) / (vi_h / float64(im_h))) | |
img.Set(x1, y1, color.RGBA{0xFF, 0x00, 0x00, 0xFF}) | |
img.Set(x2, y2, color.RGBA{0xFF, 0x00, 0x00, 0xFF}) | |
draw(z1, depth + 1) | |
draw(z2, depth + 1) | |
} | |
func main() { | |
// Leaf | |
a = 0.7 + 0.2i | |
b = 0.0 + 0.0i | |
c = 0.0 + 0.0i | |
d = 0.67 + 0.0i | |
// Koch Curve | |
// a = 0.0 + 0.0i | |
// b = 0.5 + 0.25i | |
// c = 0.0 + 0.0i | |
// d = 0.5 - 0.25i | |
// C Curve | |
// a = 0.0 + 0.0i | |
// b = -0.5 - 0.5i | |
// c = 0.0 + 0.0i | |
// d = -0.5 + 0.5i | |
// Triangle | |
// a = 0.0 + 0.0i | |
// b = 0.5 + 0.5i | |
// c = 0.0 + 0.0i | |
// d = 0.5 - 0.5i | |
z := complex(1, 0) | |
for y := 0; y < im_h; y++ { | |
for x := 0; x < im_w; x++ { | |
img.Set(x, y, color.RGBA{0x00, 0x00, 0x00, 0xFF}) | |
} | |
} | |
draw(z, 0); | |
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