From d9f5b4e13af8b310e5711ede4302e8350413dc7d Mon Sep 17 00:00:00 2001 From: Lukas Werner Date: Tue, 3 May 2022 11:03:30 -0700 Subject: [PATCH] add art --- art/mandelbrot.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++ art/out.png | Bin 0 -> 6360 bytes 2 files changed, 64 insertions(+) create mode 100644 art/mandelbrot.go create mode 100644 art/out.png diff --git a/art/mandelbrot.go b/art/mandelbrot.go new file mode 100644 index 0000000..cec0bc9 --- /dev/null +++ b/art/mandelbrot.go @@ -0,0 +1,64 @@ +//NOT FINISHED + +package main + +import ( + "image" + "image/png" + "math/cmplx" + "os" +) + +type Color struct { + r uint32 + g uint32 + b uint32 + a uint32 +} + +func (c Color) RGBA() (r, g, b, a uint32) { + return c.r, c.g, c.b, c.a +} + +func green() Color { + return Color{0, 255, 0, 255} +} + +func blue() Color { + return Color{0, 0, 255, 255} +} + +func main() { + f, err := os.Create("out.png") + if err != nil { + os.Exit(1) + } + const ( + xmin, ymin, xmax, ymax = -2, -2, +2, +2 + width, height = 1024, 1024 + ) + img := image.NewRGBA(image.Rect(0, 0, width, height)) + for py := 0; py < height; py++ { + y := float64(py)/height*(ymax-ymin) + ymin + for px := 0; px < width; px++ { + x := float64(px)/width*(xmax-xmin) + xmin + z := complex(x, y) + img.Set(px, py, mandelbrot(z)) + } + } + png.Encode(f, img) + f.Close() +} + +func mandelbrot(z complex128) Color { + const iterations = 200 + const contrast = 15 + var v complex128 + for n := uint8(0); n < iterations; n++ { + v = v*v + z + if cmplx.Abs(v) > 2 { + return Color{0, uint32(255 - contrast*n), 0, 255} + } + } + return blue() +} diff --git a/art/out.png b/art/out.png new file mode 100644 index 0000000000000000000000000000000000000000..8e4c1a0a44970623ca95250ba5e0eea50a1d9c59 GIT binary patch literal 6360 zcmeI1F$%&!6hvnw$`S~~LXbcpVCflzC=pE)R6Ky4t)*aLFqL-@yn#m$k6>x(0W8GA zHtw9mX=bcO_$v5)%|&^_nbaJfCb9wq?nEm_z1 z?>nqw_u@G)PGK6<220^tstu`OLQPU?T2f1>fIi5jgf^%(lm|@>CPAaJqz&2++M+@S zCPBO;suW5y34%mHq9Bn;5G0ngL69g&6eKbUfop9ZlY$-eK`Pi-JV<1 Qx$Zt}gM3_Mm(l9*1Jd&q>;M1& literal 0 HcmV?d00001