Jump to content

Pentagram: Difference between revisions

Added Go
m (→‎{{header|Ring}}: Remove vanity tags)
(Added Go)
Line 143:
}
</lang>
 
=={{header|Go}}==
{{libheader|Go Graphics}}
<lang go>package main
 
import (
"github.com/fogleman/gg"
"math"
)
 
func Pentagram(x, y, r float64) []gg.Point {
points := make([]gg.Point, 5)
for i := 0; i < 5; i++ {
fi := float64(i)
angle := 2*math.Pi*fi/5 - math.Pi/2
points[i] = gg.Point{x + r*math.Cos(angle), y + r*math.Sin(angle)}
}
return points
}
 
func main() {
points := Pentagram(320, 320, 250)
dc := gg.NewContext(640, 640)
dc.SetRGB(1, 1, 1) // White
dc.Clear()
for i := 0; i <= 5; i++ {
index := (i * 2) % 5
p := points[index]
dc.LineTo(p.X, p.Y)
}
dc.SetHexColor("#6495ED") // Cornflower Blue
dc.SetFillRule(gg.FillRuleWinding)
dc.FillPreserve()
dc.SetRGB(0, 0, 0) // Black
dc.SetLineWidth(5)
dc.Stroke()
dc.SavePNG("pentagram.png")
}</lang>
 
{{out}}
<pre>
The image produced is similar to that of the Java entry.
</pre>
 
=={{header|Haskell}}==
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.