Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "github.com/hajimehoshi/ebiten"
- "github.com/peterhellberg/gfx"
- )
- var (
- w, h = 256, 256
- palette = gfx.PaletteEN4
- center = gfx.V(128, 128)
- pos = center
- p = gfx.Polygon{
- {-64, -64},
- {-32, -32},
- {-64, 64},
- {64, 64},
- {64, -64},
- }
- )
- func main() {
- ebiten.SetFullscreen(true)
- ebiten.Run(run, w, h, 1, "Ebiten GFX Moving Polygon")
- }
- func run(screen *ebiten.Image) error {
- if ebiten.IsKeyPressed(ebiten.KeyEscape) || ebiten.IsKeyPressed(ebiten.KeyQ) {
- return gfx.ErrDone
- }
- if ebiten.IsDrawingSkipped() {
- return nil
- }
- m := gfx.NewPaletted(w, h, palette, palette[3])
- d := float64(int(pos.X) % 360)
- matrix := gfx.IM.Moved(pos)
- tp := center
- touches := ebiten.Touches()
- switch {
- case len(touches) > 0:
- tp = gfx.IV(touches[0].Position())
- case ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft):
- tp = gfx.IV(ebiten.CursorPosition())
- }
- pos = gfx.Lerp(pos, tp, 0.2)
- gfx.DrawPolygon(m, p.Project(matrix), 0, palette[2])
- gfx.DrawPolygon(m, p.Project(matrix.Scaled(pos, 0.5).RotatedDegrees(pos, d)), 0, palette[1])
- gfx.DrawFastFilledCircle(m, pos, 4, palette[0])
- return screen.ReplacePixels(m.Pixels())
- }
Add Comment
Please, Sign In to add comment