Glaggle example draws glaggle as expected
This commit is contained in:
parent
5ca69d90e6
commit
1003203bb1
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
import "math"
|
||||||
import "image"
|
import "image"
|
||||||
import "image/png"
|
import "image/png"
|
||||||
import "git.tebibyte.media/tomo/ggfx"
|
import "git.tebibyte.media/tomo/ggfx"
|
||||||
@ -13,18 +14,21 @@ func main () {
|
|||||||
Bounds: img.Rect,
|
Bounds: img.Rect,
|
||||||
Width: 4,
|
Width: 4,
|
||||||
}
|
}
|
||||||
black := []uint8 { 0, 0, 0, 255 }
|
black := []uint8 { 0, 0, 0, 255 }
|
||||||
red := []uint8 { 255, 0, 0, 255 }
|
yellow := []uint8 { 255, 255, 0, 255 }
|
||||||
canvas.FillPolygon (
|
midpoint := image.Pt(canvas.Bounds.Dx() / 2, canvas.Bounds.Dy() / 2)
|
||||||
black,
|
|
||||||
image.Pt(10, 10),
|
face := circle(32, 100, midpoint)
|
||||||
image.Pt(70, 50),
|
canvas.FillPolygon(yellow, face...)
|
||||||
image.Pt(20, 70))
|
canvas.StrokePolygon(black, 2, face...)
|
||||||
canvas.StrokePolygon (
|
|
||||||
red, 1,
|
eye := circle(12, 16, midpoint.Add(image.Pt(-40, -30)))
|
||||||
image.Pt(10, 10),
|
canvas.FillPolygon(black, eye...)
|
||||||
image.Pt(70, 50),
|
eye = circle(12, 16, midpoint.Add(image.Pt(40, -30)))
|
||||||
image.Pt(20, 70))
|
canvas.FillPolygon(black, eye...)
|
||||||
|
|
||||||
|
mouth := circle(16, 70, midpoint)
|
||||||
|
canvas.StrokePolygon(black, 2, mouth[1:8]...)
|
||||||
|
|
||||||
file, err := os.Create("TEST.png")
|
file, err := os.Create("TEST.png")
|
||||||
if err != nil { panic(err.Error()) }
|
if err != nil { panic(err.Error()) }
|
||||||
@ -35,3 +39,14 @@ func main () {
|
|||||||
println("Open TEST.png to see the result.")
|
println("Open TEST.png to see the result.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func circle (resolution int, radius float64, center image.Point) []image.Point {
|
||||||
|
points := make([]image.Point, resolution)
|
||||||
|
for index := range points {
|
||||||
|
angle := float64(index) * ((2 * math.Pi) / float64(len(points)))
|
||||||
|
point := image.Pt (
|
||||||
|
int(math.Cos(angle) * radius),
|
||||||
|
int(math.Sin(angle) * radius))
|
||||||
|
points[index] = point.Add(center)
|
||||||
|
}
|
||||||
|
return points
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user