Skip to content

Instantly share code, notes, and snippets.

@vicapow
Created July 31, 2014 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vicapow/1dda87a0744d71bc0c24 to your computer and use it in GitHub Desktop.
Save vicapow/1dda87a0744d71bc0c24 to your computer and use it in GitHub Desktop.
noise in go lang
package main
import _ "image/png"
import (
"os"
"image"
"image/draw"
"image/color"
"image/png"
"math/rand"
"fmt"
)
func main() {
m := image.NewRGBA(image.Rect(0, 0, 640, 480))
black := color.RGBA{0, 0, 0, 255}
draw.Draw(m, m.Bounds(), &image.Uniform{black}, image.ZP, draw.Src)
toimg, _ := os.Create("new.png")
defer toimg.Close()
w := m.Bounds().Max.X
h := m.Bounds().Max.Y
fmt.Println("w", w, "h", h)
x := 0
y := 0
n := 1000000
prev := color.RGBA{0, 0, 0, 0}
for i := 0; i < n; i++ {
x = rand.Intn(w)
y = rand.Intn(h)
prev = m.At(x, y).(color.RGBA)
prev.R += 30
m.Set(x, y, prev)
}
png.Encode(toimg, m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment