Created
July 31, 2014 07:29
-
-
Save vicapow/1dda87a0744d71bc0c24 to your computer and use it in GitHub Desktop.
noise in go lang
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/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