Created
November 19, 2018 04:17
-
-
Save floodcode/21f735d35efe38827ff956d81a19a23e to your computer and use it in GitHub Desktop.
Simple bitwise fractal
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 ( | |
"image" | |
"image/color" | |
"image/png" | |
"os" | |
) | |
const width = 512 | |
const height = 512 | |
func main() { | |
img := makeImage() | |
file, _ := os.Create("fract.png") | |
png.Encode(file, img) | |
} | |
func makeImage() *image.RGBA { | |
img := image.NewRGBA(image.Rectangle{ | |
image.Point{0, 0}, | |
image.Point{width, height}, | |
}) | |
for x := 0; x < width; x++ { | |
for y := 0; y < height; y++ { | |
pix := gen(uint8(x), uint8(y)) | |
img.SetRGBA(x, y, color.RGBA{0, pix, 0, 0xff}) | |
} | |
} | |
return img | |
} | |
func gen(x uint8, y uint8) uint8 { | |
return x ^ y | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment