func createNoise(win ui.Window, screen draw.Image) { var rnd, rnd2 uint64 var rnd16a, rnd16b, rnd16c, rnd16d uint16 var img [240 * 320 * 4]byte // Populate the image with pixel data for { for i := 0; i < len(img); i += 256 { rnd = uint64(rand.Int63()) if (i % 63) == 0 { rnd2 = uint64(rand.Int63()) } rnd |= rnd2 & 1 << 63 // we have to set the 64'th bit from the rand.Int63() manualy rnd16a = uint16(rnd & 0x000000000000FFFF) rnd16b = uint16((rnd >> 16) & 0x000000000000FFFF) rnd16c = uint16((rnd >> 32) & 0x000000000000FFFF) rnd16d = uint16((rnd >> 48) & 0x000000000000FFFF) copy(img[i:i+64], bw[rnd16a][:]) copy(img[i+64:i+128], bw[rnd16b][:]) copy(img[i+128:i+192], bw[rnd16c][:]) copy(img[i+192:i+256], bw[rnd16d][:]) rnd2 = rnd2 >> 1 // rotate to next random bit } // Copy pixel data to the screen copy(screen.(*image.RGBA).Pix, img[:]) frameCount <- 1 win.FlushImage() } }
func flushFunc(ctxt ui.Window) func(r image.Rectangle) { if fctxt, ok := ctxt.(RectFlusherContext); ok { return func(r image.Rectangle) { fctxt.FlushImageRect(r) } } return func(_ image.Rectangle) { ctxt.FlushImage() } }
func displayImage(buffer image.Image, window ui.Window) { draw.Draw(window.Screen(), window.Screen().Bounds(), buffer, image.ZP, draw.Src) window.FlushImage() }