Skip to content

Instantly share code, notes, and snippets.

@dimkouv
Created January 4, 2020 00:28
Show Gist options
  • Save dimkouv/0c176ccff9231bbd4ef8264935de605b to your computer and use it in GitHub Desktop.
Save dimkouv/0c176ccff9231bbd4ef8264935de605b to your computer and use it in GitHub Desktop.
package main
import (
"image"
"image/color"
"image/png"
"math/rand"
"os"
"time"
)
func symmetricDraw(img *image.RGBA, offX, offY, x, y int, color color.Color) {
pixels := [8][2]int{
{x, y}, {y, x}, {x, -y}, {-y, x}, {-x, y}, {y, -x}, {-x, -y}, {-y, -x},
}
for _, p := range pixels {
img.Set(offX+p[0], offY+p[1], color)
}
}
func drawCircle(img *image.RGBA, offX, offY, r int, color color.Color) {
x := 0
y := r
h := 1 - r
symmetricDraw(img, offX, offY, x, y, color)
for y >= x {
if h < 0 {
h += 2*x + 3
x++
} else {
h += 2*(x-y) + 5
x++
y--
}
symmetricDraw(img, offX, offY, x, y, color)
}
}
func main() {
width := 1000
height := 1000
rand.Seed(time.Now().Unix())
black := color.RGBA{0, 0, 0, 0xff}
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
for i := 0; i < width; i++ {
for j := 0; j < height; j++ {
img.Set(i, j, black)
}
}
for i := 0; i < 123; i++ {
radius := 10 + rand.Intn(70)
posX := rand.Intn(1000)
posY := rand.Intn(1000)
drawCircle(img, posX, posY, radius, color.RGBA{
uint8(rand.Intn(256)), uint8(rand.Intn(256)), uint8(rand.Intn(256)), 0xff,
})
}
f, _ := os.Create("image.png")
_ = png.Encode(f, img)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment