Skip to content

Commit

Permalink
Update the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jan 4, 2024
1 parent f6073cd commit 39a6dcb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cmd/multicore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/rand"
"os"
"runtime"
"time"

"github.com/veandco/go-sdl2/sdl"
"github.com/xyproto/pixelpusher"
Expand Down Expand Up @@ -86,8 +85,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()
Expand Down
14 changes: 8 additions & 6 deletions cmd/redpixel/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"github.com/xyproto/pixelpusher"
pp "github.com/xyproto/pixelpusher"
)

func onDraw(gfx *pixelpusher.Config) error {
// x, y, r, g, b
return pixelpusher.Plot(gfx, 0, 0, 255, 0, 0)
func onDraw(canvas *pp.Canvas) error {
// x=0, y=0, red=255, green=0, blue=0
return pp.Plot(canvas, 0, 0, 255, 0, 0)
}

func main() {
gfx := pixelpusher.New("Red Pixel")
gfx.Run(onDraw, nil, nil, nil)
// The window title is "Red Pixel"
canvas := pp.New("Red Pixel")
// onDraw will be called whenever it is time to draw a frame
canvas.Run(onDraw, nil, nil, nil)
}
8 changes: 4 additions & 4 deletions cmd/simpledraw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"errors"

"github.com/xyproto/pixelpusher"
pp "github.com/xyproto/pixelpusher"
)

var x, y = 160, 100

func onDraw(gfx *pixelpusher.Config) error {
return pixelpusher.Plot(gfx, x, y, 255, 0, 0)
func onDraw(canvas *pp.Canvas) error {
return pp.Plot(canvas, x, y, 255, 0, 0)
}

func onPress(left, right, up, down, space, enter, esc bool) error {
Expand All @@ -30,5 +30,5 @@ func onPress(left, right, up, down, space, enter, esc bool) error {
}

func main() {
pixelpusher.New("Simple Draw").Run(onDraw, onPress, nil, nil)
pp.New("Simple Draw").Run(onDraw, onPress, nil, nil)
}

0 comments on commit 39a6dcb

Please sign in to comment.