diff --git a/cmd/blending/main.go b/cmd/blending/main.go index 39b079c..c772918 100644 --- a/cmd/blending/main.go +++ b/cmd/blending/main.go @@ -6,10 +6,9 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -45,11 +44,11 @@ func DrawAll(pixels []uint32, cores int) { var opaqueness uint8 = 1 // Almost completely transparent // Draw a triangle, concurrently - pixelpusher.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaqueness}, pitch) + pp.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaqueness}, pitch) // Draw a line and a red pixel, without caring about which order they appear in, or if they will complete before the next frame is drawn - go pixelpusher.Line(pixels, rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaqueness}, pitch) - go pixelpusher.Pixel(pixels, rw(), rh(), color.RGBA{0xff, 0, 0, opaqueness}, pitch) + go pp.Line(pixels, rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaqueness}, pitch) + go pp.Pixel(pixels, rw(), rh(), color.RGBA{0xff, 0, 0, opaqueness}, pitch) } func run() int { @@ -89,8 +88,6 @@ func run() int { texture.SetBlendMode(sdl.BLENDMODE_ADD) - rand.Seed(time.Now().UnixNano()) - var ( pixels = make([]uint32, width*height) cores = runtime.NumCPU() @@ -136,7 +133,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) // Clear pixels at fullscreen toggle, because of blend mode and no double buffering renderer.Clear() for i := range pixels { @@ -155,7 +152,7 @@ func run() int { fallthrough case sdl.K_F12: // screenshot - pixelpusher.Screenshot(renderer, "screenshot.png", true) + pp.Screenshot(renderer, "screenshot.png", true) } } } diff --git a/cmd/butterfly/main.go b/cmd/butterfly/main.go index 166d608..1e276ca 100644 --- a/cmd/butterfly/main.go +++ b/cmd/butterfly/main.go @@ -7,10 +7,9 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -90,16 +89,16 @@ func convolution(time float32, pixels []uint32, width, height, pitch int32, enr above = pixels[(y-one2)*pitch+x*two1] } - lr, lg, lb, _ := pixelpusher.ColorValueToRGBA(left) - rr, rg, rb, _ := pixelpusher.ColorValueToRGBA(right) - tr, tg, tb, _ := pixelpusher.ColorValueToRGBA(this) - ar, ag, ab, _ := pixelpusher.ColorValueToRGBA(above) + lr, lg, lb, _ := pp.ColorValueToRGBA(left) + rr, rg, rb, _ := pp.ColorValueToRGBA(right) + tr, tg, tb, _ := pp.ColorValueToRGBA(this) + ar, ag, ab, _ := pp.ColorValueToRGBA(above) averageR := uint8(float32(lr+rr+tr+ar) / float32(4.55-stime)) averageG := uint8(float32(lg+rg+tg+ag) / float32(4.55-stime)) averageB := uint8(float32(lb+rb+tb+ab) / float32(4.55-stime)) - pixels[y*pitch+x] = pixelpusher.RGBAToColorValue(averageR, averageG, averageB, 0xff) + pixels[y*pitch+x] = pp.RGBAToColorValue(averageR, averageG, averageB, 0xff) } } // Top row @@ -146,11 +145,11 @@ func clamp(v float32, max uint8) uint8 { // Every pixel that is light, decrease the intensity func darken(pixels []uint32) { for i := range pixels { - r, g, b, _ := pixelpusher.ColorValueToRGBA(pixels[i]) + r, g, b, _ := pp.ColorValueToRGBA(pixels[i]) if r < 20 && g < 20 && b < 20 { continue } - pixels[i] = pixelpusher.RGBAToColorValue(clamp(float32(r)*0.99, 255), clamp(float32(g)*0.99, 255), clamp(float32(b)*0.99, 255), 255) + pixels[i] = pp.RGBAToColorValue(clamp(float32(r)*0.99, 255), clamp(float32(g)*0.99, 255), clamp(float32(b)*0.99, 255), 255) } } @@ -164,24 +163,24 @@ func TriangleDance(time float32, pixels []uint32, width, height, pitch int32, co // The function is responsible for clearing the pixels, // it might want to reuse the pixels from the last time (flame effect) - //pixelpusher.FastClear(pixels, bgColorValue) + //pp.FastClear(pixels, bgColorValue) // Find a suitable placement and color var x int32 if xdirection > 0 { - x = pixelpusher.Clamp(int32(float32(width)*time), size, width-size) + x = pp.Clamp(int32(float32(width)*time), size, width-size) } else if xdirection == 0 { x = int32(width / 2) } else { - x = pixelpusher.Clamp(int32(float32(width)*(1.0-time)), size, width-size) + x = pp.Clamp(int32(float32(width)*(1.0-time)), size, width-size) } var y int32 if ydirection > 0 { - y = pixelpusher.Clamp(int32(float32(height)*time), size, height-size) + y = pp.Clamp(int32(float32(height)*time), size, height-size) } else if ydirection == 0 { y = int32(height / 2) } else { - y = pixelpusher.Clamp(int32(float32(height)*(1.0-time)), size, height-size) + y = pp.Clamp(int32(float32(height)*(1.0-time)), size, height-size) } // Make the center triangle red @@ -199,7 +198,7 @@ func TriangleDance(time float32, pixels []uint32, width, height, pitch int32, co x3 := x + rand.Int31n(int32(size)) - int32(size/2) y3 := y + rand.Int31n(int32(size)) - int32(size/2) - pixelpusher.Triangle(cores, pixels, x1, y1, x2, y2, x3, y3, c, pitch) + pp.Triangle(cores, pixels, x1, y1, x2, y2, x3, y3, c, pitch) return 0.0 } @@ -241,8 +240,6 @@ func run() int { //texture.SetBlendMode(sdl.BLENDMODE_BLEND) - rand.Seed(time.Now().UnixNano()) - var ( pixels = make([]uint32, width*height) cores = runtime.NumCPU() @@ -330,7 +327,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_p, sdl.K_SPACE: // pause toggle pause = !pause @@ -344,7 +341,7 @@ func run() int { fallthrough case sdl.K_F12: // screenshot - pixelpusher.Screenshot(renderer, "screenshot.png", true) + pp.Screenshot(renderer, "screenshot.png", true) } } } diff --git a/cmd/cube/main.go b/cmd/cube/main.go index 124996b..946b652 100644 --- a/cmd/cube/main.go +++ b/cmd/cube/main.go @@ -6,11 +6,10 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/fogleman/fauxgl" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -46,7 +45,7 @@ var ( // by launching the same number of goroutines. func DrawAll(pixels []uint32, cores int, mesh *fauxgl.Mesh, cameraAngle float32, meshHexColor string) { // Draw a triangle, concurrently - pixelpusher.WireTriangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) + pp.WireTriangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) // Draw a 3D object on top DrawMesh(pixels, pitch, mesh, cameraAngle, meshHexColor) @@ -84,8 +83,6 @@ func run() int { //texture.SetBlendMode(sdl.BLENDMODE_BLEND) // sdl.BLENDMODE_ADD is also possible - rand.Seed(time.Now().UnixNano()) - mesh, err := LoadMeshOBJ("bevelcube.obj") if err != nil { panic(err) @@ -143,7 +140,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_SPACE, sdl.K_p: pause = !pause case sdl.K_s: @@ -156,7 +153,7 @@ func run() int { fallthrough case sdl.K_F12: // save the image - pixelpusher.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) + pp.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) } } } diff --git a/cmd/glitchduck/main.go b/cmd/glitchduck/main.go index 8330809..9225b92 100644 --- a/cmd/glitchduck/main.go +++ b/cmd/glitchduck/main.go @@ -7,10 +7,9 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -58,52 +57,52 @@ func Convolution(time float32, pixels []uint32, width, height, pitch int32, enr switch enr { case 0: // "snow patterns" - left = pixelpusher.GetWrap(pixels, y*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, y*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, y*pitch+x, size) - above = pixelpusher.GetWrap(pixels, (y+1)*pitch+x, size) + left = pp.GetWrap(pixels, y*pitch+x-1, size) + right = pp.GetWrap(pixels, y*pitch+x+1, size) + this = pp.GetWrap(pixels, y*pitch+x, size) + above = pp.GetWrap(pixels, (y+1)*pitch+x, size) case 1: // "highway" - left = pixelpusher.GetWrap(pixels, (y-1)*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, (y-1)*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, y*pitch+x, size) - above = pixelpusher.GetWrap(pixels, (y-1)*pitch+x, size) + left = pp.GetWrap(pixels, (y-1)*pitch+x-1, size) + right = pp.GetWrap(pixels, (y-1)*pitch+x+1, size) + this = pp.GetWrap(pixels, y*pitch+x, size) + above = pp.GetWrap(pixels, (y-1)*pitch+x, size) case 2: // "dither highway" - left = pixelpusher.GetWrap(pixels, (y-1)*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, (y-1)*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, (y-1)*pitch+(x-1), size) - above = pixelpusher.GetWrap(pixels, (y+1)*pitch+(x+1), size) + left = pp.GetWrap(pixels, (y-1)*pitch+x-1, size) + right = pp.GetWrap(pixels, (y-1)*pitch+x+1, size) + this = pp.GetWrap(pixels, (y-1)*pitch+(x-1), size) + above = pp.GetWrap(pixels, (y+1)*pitch+(x+1), size) case 3: // "butterfly" - left = pixelpusher.GetWrap(pixels, y*pitch+(x-two1), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+two1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+x*two2, size) - above = pixelpusher.GetWrap(pixels, (y-two1)*pitch+x*two2, size) + left = pp.GetWrap(pixels, y*pitch+(x-two1), size) + right = pp.GetWrap(pixels, y*pitch+(x+two1), size) + this = pp.GetWrap(pixels, y*pitch+x*two2, size) + above = pp.GetWrap(pixels, (y-two1)*pitch+x*two2, size) case 4: // ? - left = pixelpusher.GetWrap(pixels, y*pitch+(x-two2), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+two1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+int32(float32(x)*stime), size) - above = pixelpusher.GetWrap(pixels, (y-two2)*pitch+int32(float32(x)*stime), size) + left = pp.GetWrap(pixels, y*pitch+(x-two2), size) + right = pp.GetWrap(pixels, y*pitch+(x+two1), size) + this = pp.GetWrap(pixels, y*pitch+int32(float32(x)*stime), size) + above = pp.GetWrap(pixels, (y-two2)*pitch+int32(float32(x)*stime), size) case 5: // "castle" - left = pixelpusher.GetWrap(pixels, y*pitch+(x-one1), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+one1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+x*two1, size) - above = pixelpusher.GetWrap(pixels, (y-one2)*pitch+x*two1, size) + left = pp.GetWrap(pixels, y*pitch+(x-one1), size) + right = pp.GetWrap(pixels, y*pitch+(x+one1), size) + this = pp.GetWrap(pixels, y*pitch+x*two1, size) + above = pp.GetWrap(pixels, (y-one2)*pitch+x*two1, size) } - lr, lg, lb, _ := pixelpusher.ColorValueToRGBA(left) - rr, rg, rb, _ := pixelpusher.ColorValueToRGBA(right) - tr, tg, tb, _ := pixelpusher.ColorValueToRGBA(this) - ar, ag, ab, _ := pixelpusher.ColorValueToRGBA(above) + lr, lg, lb, _ := pp.ColorValueToRGBA(left) + rr, rg, rb, _ := pp.ColorValueToRGBA(right) + tr, tg, tb, _ := pp.ColorValueToRGBA(this) + ar, ag, ab, _ := pp.ColorValueToRGBA(above) averageR := uint8(float32(lr+rr+tr+ar) / float32(4.8-stime)) averageG := uint8(float32(lg+rg+tg+ag) / float32(4.8-stime)) averageB := uint8(float32(lb+rb+tb+ab) / float32(4.8-stime)) - pixelpusher.SetWrap(pixels, y*pitch+x, width*height, pixelpusher.RGBAToColorValue(averageR, averageG, averageB, 0xff)) + pp.SetWrap(pixels, y*pitch+x, width*height, pp.RGBAToColorValue(averageR, averageG, averageB, 0xff)) } } } @@ -140,8 +139,6 @@ func run() int { //texture.SetBlendMode(sdl.BLENDMODE_BLEND) // sdl.BLENDMODE_ADD is also possible - rand.Seed(time.Now().UnixNano()) - mesh, err := LoadMeshOBJ("duck.obj") if err != nil { panic(err) @@ -165,12 +162,12 @@ func run() int { if !pause { // Clear the pixel buffer - pixelpusher.FastClear(pixels, 0xffffffff) + pp.FastClear(pixels, 0xffffffff) // Draw a triangle, concurrently if effect { yellow := rb() - pixelpusher.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{yellow, yellow, 0, 0x80}, pitch) + pp.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{yellow, yellow, 0, 0x80}, pitch) } // Draw a 3D object @@ -183,7 +180,7 @@ func run() int { Convolution(0.9, pixelCopy, width, height, pitch, enr) // Stretch contrast - pixelpusher.StretchContrast(cores, pixelCopy, pitch, 0.09) + pp.StretchContrast(cores, pixelCopy, pitch, 0.09) // Draw pixel buffer to screen texture.UpdateRGBA(nil, pixelCopy, width) @@ -200,7 +197,7 @@ func run() int { //} // Clear the pixel buffer - //pixelpusher.FastClear(pixels, 0) + //pp.FastClear(pixels, 0) renderer.Copy(texture, nil, nil) renderer.Present() @@ -231,7 +228,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_SPACE: effect = !effect case sdl.K_p: @@ -246,7 +243,7 @@ func run() int { fallthrough case sdl.K_F12: // save the image - pixelpusher.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) + pp.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) } } } diff --git a/cmd/multicore/main.go b/cmd/multicore/main.go index 626eaeb..aa50f41 100644 --- a/cmd/multicore/main.go +++ b/cmd/multicore/main.go @@ -1,4 +1,3 @@ -// Used as an example in the README.md file package main import ( @@ -9,7 +8,7 @@ import ( "runtime" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -43,11 +42,11 @@ var ( func DrawAll(pixels []uint32, cores int) { // Draw a triangle, concurrently - pixelpusher.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) + pp.Triangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) // Draw a line and a red pixel, without caring about which order they appear in, or if they will complete before the next frame is drawn - go pixelpusher.Line(pixels, rw(), rh(), rw(), rh(), color.RGBA{0xff, 0xff, 0, opaque}, pitch) - go pixelpusher.Pixel(pixels, rw(), rh(), color.RGBA{0xff, 0x0, 0x0, opaque}, pitch) + go pp.Line(pixels, rw(), rh(), rw(), rh(), color.RGBA{0xff, 0xff, 0, opaque}, pitch) + go pp.Pixel(pixels, rw(), rh(), color.RGBA{0xff, 0x0, 0x0, opaque}, pitch) } func run() int { @@ -133,7 +132,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_SPACE, sdl.K_p: pause = !pause case sdl.K_s: @@ -146,7 +145,7 @@ func run() int { fallthrough case sdl.K_F12: // screenshot - pixelpusher.Screenshot(renderer, "screenshot.png", true) + pp.Screenshot(renderer, "screenshot.png", true) } } } diff --git a/cmd/strobe/main.go b/cmd/strobe/main.go index d21e2bb..36b6af4 100644 --- a/cmd/strobe/main.go +++ b/cmd/strobe/main.go @@ -7,11 +7,10 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/veandco/go-sdl2/sdl" "github.com/xyproto/pf" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -32,10 +31,8 @@ const ( opaque = 255 ) -var ( - // Convenience function for returning a random byte - rb = func() uint8 { return uint8(rand.Intn(255)) } -) +// Convenience function for returning a random byte +func rb() uint8 { return uint8(rand.Intn(255)) } func Strobe(pixels []uint32, width, height, pitch int32) { for y := int32(1); y < int32(height-1); y++ { @@ -68,52 +65,52 @@ func Convolution(time float32, pixels []uint32, width, height, pitch int32, enr switch enr { case 0: // "snow patterns" - left = pixelpusher.GetWrap(pixels, y*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, y*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, y*pitch+x, size) - above = pixelpusher.GetWrap(pixels, (y+1)*pitch+x, size) + left = pp.GetWrap(pixels, y*pitch+x-1, size) + right = pp.GetWrap(pixels, y*pitch+x+1, size) + this = pp.GetWrap(pixels, y*pitch+x, size) + above = pp.GetWrap(pixels, (y+1)*pitch+x, size) case 1: // "highway" - left = pixelpusher.GetWrap(pixels, (y-1)*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, (y-1)*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, y*pitch+x, size) - above = pixelpusher.GetWrap(pixels, (y-1)*pitch+x, size) + left = pp.GetWrap(pixels, (y-1)*pitch+x-1, size) + right = pp.GetWrap(pixels, (y-1)*pitch+x+1, size) + this = pp.GetWrap(pixels, y*pitch+x, size) + above = pp.GetWrap(pixels, (y-1)*pitch+x, size) case 2: // "dither highway" - left = pixelpusher.GetWrap(pixels, (y-1)*pitch+x-1, size) - right = pixelpusher.GetWrap(pixels, (y-1)*pitch+x+1, size) - this = pixelpusher.GetWrap(pixels, (y-1)*pitch+(x-1), size) - above = pixelpusher.GetWrap(pixels, (y+1)*pitch+(x+1), size) + left = pp.GetWrap(pixels, (y-1)*pitch+x-1, size) + right = pp.GetWrap(pixels, (y-1)*pitch+x+1, size) + this = pp.GetWrap(pixels, (y-1)*pitch+(x-1), size) + above = pp.GetWrap(pixels, (y+1)*pitch+(x+1), size) case 3: // "butterfly" - left = pixelpusher.GetWrap(pixels, y*pitch+(x-two1), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+two1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+x*two2, size) - above = pixelpusher.GetWrap(pixels, (y-two1)*pitch+x*two2, size) + left = pp.GetWrap(pixels, y*pitch+(x-two1), size) + right = pp.GetWrap(pixels, y*pitch+(x+two1), size) + this = pp.GetWrap(pixels, y*pitch+x*two2, size) + above = pp.GetWrap(pixels, (y-two1)*pitch+x*two2, size) case 4: // ? - left = pixelpusher.GetWrap(pixels, y*pitch+(x-two2), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+two1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+int32(float32(x)*stime), size) - above = pixelpusher.GetWrap(pixels, (y-two2)*pitch+int32(float32(x)*stime), size) + left = pp.GetWrap(pixels, y*pitch+(x-two2), size) + right = pp.GetWrap(pixels, y*pitch+(x+two1), size) + this = pp.GetWrap(pixels, y*pitch+int32(float32(x)*stime), size) + above = pp.GetWrap(pixels, (y-two2)*pitch+int32(float32(x)*stime), size) case 5: // "castle" - left = pixelpusher.GetWrap(pixels, y*pitch+(x-one1), size) - right = pixelpusher.GetWrap(pixels, y*pitch+(x+one1), size) - this = pixelpusher.GetWrap(pixels, y*pitch+x*two1, size) - above = pixelpusher.GetWrap(pixels, (y-one2)*pitch+x*two1, size) + left = pp.GetWrap(pixels, y*pitch+(x-one1), size) + right = pp.GetWrap(pixels, y*pitch+(x+one1), size) + this = pp.GetWrap(pixels, y*pitch+x*two1, size) + above = pp.GetWrap(pixels, (y-one2)*pitch+x*two1, size) } - lr, lg, lb, _ := pixelpusher.ColorValueToRGBA(left) - rr, rg, rb, _ := pixelpusher.ColorValueToRGBA(right) - tr, tg, tb, _ := pixelpusher.ColorValueToRGBA(this) - ar, ag, ab, _ := pixelpusher.ColorValueToRGBA(above) + lr, lg, lb, _ := pp.ColorValueToRGBA(left) + rr, rg, rb, _ := pp.ColorValueToRGBA(right) + tr, tg, tb, _ := pp.ColorValueToRGBA(this) + ar, ag, ab, _ := pp.ColorValueToRGBA(above) averageR := uint8(float32(lr+rr+tr+ar) / float32(4.8-stime)) averageG := uint8(float32(lg+rg+tg+ag) / float32(4.8-stime)) averageB := uint8(float32(lb+rb+tb+ab) / float32(4.8-stime)) - pixelpusher.SetWrap(pixels, y*pitch+x, width*height, pixelpusher.RGBAToColorValue(averageR, averageG, averageB, 0xff)) + pp.SetWrap(pixels, y*pitch+x, width*height, pp.RGBAToColorValue(averageR, averageG, averageB, 0xff)) } } } @@ -138,24 +135,24 @@ func TriangleDance(cores int, time float32, pixels []uint32, width, height, pitc // The function is responsible for clearing the pixels, // it might want to reuse the pixels from the last time (flame effect) - //pixelpusher.FastClear(pixels, bgColorValue) + //pp.FastClear(pixels, bgColorValue) // Find a suitable placement and color var x int32 if xdirection > 0 { - x = pixelpusher.Clamp(int32(float32(width)*time), size, width-size) + x = pp.Clamp(int32(float32(width)*time), size, width-size) } else if xdirection == 0 { x = int32(width / 2) } else { - x = pixelpusher.Clamp(int32(float32(width)*(1.0-time)), size, width-size) + x = pp.Clamp(int32(float32(width)*(1.0-time)), size, width-size) } var y int32 if ydirection > 0 { - y = pixelpusher.Clamp(int32(float32(height)*time), size, height-size) + y = pp.Clamp(int32(float32(height)*time), size, height-size) } else if ydirection == 0 { y = int32(height / 2) } else { - y = pixelpusher.Clamp(int32(float32(height)*(1.0-time)), size, height-size) + y = pp.Clamp(int32(float32(height)*(1.0-time)), size, height-size) } // Make the center triangle red @@ -173,7 +170,7 @@ func TriangleDance(cores int, time float32, pixels []uint32, width, height, pitc x3 := x + rand.Int31n(int32(size)) - int32(size/2) y3 := y + rand.Int31n(int32(size)) - int32(size/2) - pixelpusher.Triangle(cores, pixels, x1, y1, x2, y2, x3, y3, c, pitch) + pp.Triangle(cores, pixels, x1, y1, x2, y2, x3, y3, c, pitch) return 0.0 } @@ -213,8 +210,6 @@ func run() int { return 1 } - rand.Seed(time.Now().UnixNano()) - var ( pixels = make([]uint32, width*height) pixelCopy = make([]uint32, width*height) @@ -294,9 +289,9 @@ func run() int { // Stretch the contrast on a copy of the pixels if glitch { - pixelpusher.GlitchyStretchContrast(cores, pixelCopy, pitch, cycleTime) + pp.GlitchyStretchContrast(cores, pixelCopy, pitch, cycleTime) } else { - pixelpusher.StretchContrast(cores, pixelCopy, pitch, cycleTime) + pp.StretchContrast(cores, pixelCopy, pitch, cycleTime) } texture.UpdateRGBA(nil, pixelCopy, pitch) @@ -305,7 +300,7 @@ func run() int { if recording { filename := fmt.Sprintf("frame%05d.png", frameCounter) - pixelpusher.SavePixelsToPNG(pixelCopy, pitch, filename, true) + pp.SavePixelsToPNG(pixelCopy, pitch, filename, true) frameCounter++ } @@ -334,7 +329,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_p: // pause toggle pause = !pause @@ -351,7 +346,7 @@ func run() int { glitch = !glitch case sdl.K_F12: // screenshot - pixelpusher.Screenshot(renderer, "screenshot.png", true) + pp.Screenshot(renderer, "screenshot.png", true) case sdl.K_r: // recording recording = !recording diff --git a/cmd/wiretri/main.go b/cmd/wiretri/main.go index de0b36a..a2a08c5 100644 --- a/cmd/wiretri/main.go +++ b/cmd/wiretri/main.go @@ -6,10 +6,9 @@ import ( "math/rand" "os" "runtime" - "time" "github.com/veandco/go-sdl2/sdl" - "github.com/xyproto/pixelpusher" + pp "github.com/xyproto/pixelpusher" ) const ( @@ -41,7 +40,7 @@ var ( // "cores" is how many CPU cores should be targeted when drawing triangles, // by launching the same number of goroutines. func DrawAll(pixels []uint32, cores int) { - pixelpusher.WireTriangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) + pp.WireTriangle(cores, pixels, rw(), rh(), rw(), rh(), rw(), rh(), color.RGBA{rb(), rb(), rb(), opaque}, pitch) } func run() int { @@ -76,8 +75,6 @@ func run() int { //texture.SetBlendMode(sdl.BLENDMODE_BLEND) // sdl.BLENDMODE_ADD is also possible - rand.Seed(time.Now().UnixNano()) - var ( pixels = make([]uint32, width*height) cores = runtime.NumCPU() @@ -124,7 +121,7 @@ func run() int { // alt+enter is pressed fallthrough case sdl.K_f, sdl.K_F11: - pixelpusher.ToggleFullscreen(window) + pp.ToggleFullscreen(window) case sdl.K_SPACE: nodelay = !nodelay case sdl.K_p: @@ -139,7 +136,7 @@ func run() int { fallthrough case sdl.K_F12: // save the image - pixelpusher.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) + pp.SavePixelsToPNG(pixels, pitch, "screenshot.png", true) } } }