pixel-examples/guide/06_drawing_shapes_with_imdraw/main.go

54 lines
1.0 KiB
Go
Raw Normal View History

2017-04-20 18:42:50 -05:00
package main
import (
"math"
"github.com/faiface/pixel"
"github.com/faiface/pixel/imdraw"
"github.com/faiface/pixel/pixelgl"
"golang.org/x/image/colornames"
)
func run() {
cfg := pixelgl.WindowConfig{
Title: "Pixel Rocks!",
Bounds: pixel.R(0, 0, 1024, 768),
VSync: true,
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
panic(err)
}
imd := imdraw.New(nil)
2017-05-26 14:26:06 -05:00
imd.Color = colornames.Blueviolet
imd.EndShape = imdraw.RoundEndShape
2017-04-20 18:42:50 -05:00
imd.Push(pixel.V(100, 100), pixel.V(700, 100))
2017-05-26 14:26:06 -05:00
imd.EndShape = imdraw.SharpEndShape
2017-04-20 18:42:50 -05:00
imd.Push(pixel.V(100, 500), pixel.V(700, 500))
imd.Line(30)
2017-05-26 14:26:06 -05:00
imd.Color = colornames.Limegreen
2017-04-20 18:42:50 -05:00
imd.Push(pixel.V(500, 500))
imd.Circle(300, 50)
2017-05-26 14:26:06 -05:00
imd.Color = colornames.Navy
2017-04-20 18:42:50 -05:00
imd.Push(pixel.V(200, 500), pixel.V(800, 500))
imd.Ellipse(pixel.V(120, 80), 0)
2017-05-26 14:26:06 -05:00
imd.Color = colornames.Red
imd.EndShape = imdraw.RoundEndShape
2017-04-20 18:42:50 -05:00
imd.Push(pixel.V(500, 350))
imd.CircleArc(150, -math.Pi, 0, 30)
for !win.Closed() {
win.Clear(colornames.Aliceblue)
imd.Draw(win)
win.Update()
}
}
func main() {
pixelgl.Run(run)
}