Pentagram: Difference between revisions

43,088 bytes added ,  3 months ago
m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|zkl}}: Fix link: Perl 6 --> Raku)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(27 intermediate revisions by 17 users not shown)
Line 12:
* [http://proofsfromthebook.com/2013/08/04/angle-sum-of-a-pentagram/ Angle sum of a pentagram]
<br><br>
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
DEFINE REALPTR="CARD"
TYPE PointR=[REALPTR x,y]
 
INT ARRAY SinTab=[
0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
147 150 154 158 161 165 168 171 175 178 181 184 187 190
193 196 199 202 204 207 210 212 215 217 219 222 224 226
228 230 232 234 236 237 239 241 242 243 245 246 247 248
249 250 251 252 253 254 254 255 255 255 256 256 256 256]
 
INT FUNC Sin(INT a)
WHILE a<0 DO a==+360 OD
WHILE a>360 DO a==-360 OD
IF a<=90 THEN
RETURN (SinTab(a))
ELSEIF a<=180 THEN
RETURN (SinTab(180-a))
ELSEIF a<=270 THEN
RETURN (-SinTab(a-180))
ELSE
RETURN (-SinTab(360-a))
FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC Det(REAL POINTER x1,y1,x2,y2,res)
REAL tmp1,tmp2
 
RealMult(x1,y2,tmp1)
RealMult(y1,x2,tmp2)
RealSub(tmp1,tmp2,res)
RETURN
 
BYTE FUNC IsZero(REAL POINTER a)
CHAR ARRAY s(10)
 
StrR(a,s)
IF s(0)=1 AND s(1)='0 THEN
RETURN (1)
FI
RETURN (0)
 
BYTE FUNC Intersection(PointR POINTER p1,p2,p3,p4,res)
REAL det1,det2,dx1,dx2,dy1,dy2,nom,denom
 
Det(p1.x,p1.y,p2.x,p2.y,det1)
Det(p3.x,p3.y,p4.x,p4.y,det2)
RealSub(p1.x,p2.x,dx1)
RealSub(p1.y,p2.y,dy1)
RealSub(p3.x,p4.x,dx2)
RealSub(p3.y,p4.y,dy2)
Det(dx1,dy1,dx2,dy2,denom)
IF IsZero(denom) THEN
RETURN (0)
FI
Det(det1,dx1,det2,dx2,nom)
RealDiv(nom,denom,res.x)
Det(det1,dy1,det2,dy2,nom)
RealDiv(nom,denom,res.y)
RETURN (1)
 
PROC FloodFill(BYTE x0,y0)
BYTE ARRAY xs(300),ys(300)
INT first,last
 
first=0 last=0
xs(first)=x0
ys(first)=y0
 
WHILE first<=last
DO
x0=xs(first) y0=ys(first)
first==+1
IF Locate(x0,y0)=0 THEN
Plot(x0,y0)
IF Locate(x0-1,y0)=0 THEN
last==+1 xs(last)=x0-1 ys(last)=y0
FI
IF Locate(x0+1,y0)=0 THEN
last==+1 xs(last)=x0+1 ys(last)=y0
FI
IF Locate(x0,y0-1)=0 THEN
last==+1 xs(last)=x0 ys(last)=y0-1
FI
IF Locate(x0,y0+1)=0 THEN
last==+1 xs(last)=x0 ys(last)=y0+1
FI
FI
OD
RETURN
 
PROC Pentagram(INT x0,y0,r,a0 BYTE c1,c2)
INT ARRAY xs(16),ys(16)
INT angle
BYTE i
PointR p1,p2,p3,p4,p
REAL p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y,px,py
p1.x=p1x p1.y=p1y
p2.x=p2x p2.y=p2y
p3.x=p3x p3.y=p3y
p4.x=p4x p4.y=p4y
p.x=px p.y=py
 
;outer points
angle=a0
FOR i=0 TO 4
DO
xs(i)=r*Sin(angle)/256+x0
ys(i)=r*Cos(angle)/256+y0
angle==+144
OD
 
;intersection points
FOR i=0 TO 4
DO
IntToReal(xs(i MOD 5),p1x)
IntToReal(ys(i MOD 5),p1y)
IntToReal(xs((1+i) MOD 5),p2x)
IntToReal(ys((1+i) MOD 5),p2y)
IntToReal(xs((2+i) MOD 5),p3x)
IntToReal(ys((2+i) MOD 5),p3y)
IntToReal(xs((3+i) MOD 5),p4x)
IntToReal(ys((3+i) MOD 5),p4y)
Intersection(p1,p2,p3,p4,p)
xs(5+i)=RealToInt(px)
ys(5+i)=RealToInt(py)
OD
 
;centers of triangles
FOR i=0 TO 4
DO
xs(10+i)=(xs(i)+xs(5+i)+xs(5+(i+2) MOD 5))/3
ys(10+i)=(ys(i)+ys(5+i)+ys(5+(i+2) MOD 5))/3
OD
 
;center of pentagon
xs(15)=0 ys(15)=0
FOR i=5 TO 9
DO
xs(15)==+xs(i)
ys(15)==+ys(i)
OD
xs(15)==/5 ys(15)==/5
;draw lines
COLOR=c1
FOR i=0 TO 5
DO
IF i=0 THEN
Plot(xs(i MOD 5),ys(i MOD 5))
ELSE
DrawTo(xs(i MOD 5),ys(i MOD 5))
FI
OD
 
;fill
COLOR=c2
FOR i=10 TO 15
DO
FloodFill(xs(i),ys(i))
OD
RETURN
 
PROC Main()
BYTE CH=$02FC
 
Graphics(7+16)
SetColor(0,8,4)
SetColor(1,8,8)
SetColor(2,8,12)
Pentagram(40,48,40,0,1,2)
Pentagram(119,48,40,15,2,3)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Pentagram.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
Line 108 ⟶ 297:
Window.Finalize;
SDL.Finalise;
end Pentagram;</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
[[File:Pentagram Java.png|300px|thumb|right]]
<syntaxhighlight lang="autohotkey">
<lang AutoHotkey>
#Include Gdip.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=6517
Width :=A_ScreenWidth, Height := A_ScreenHeight
Line 173 ⟶ 362:
Gdip_Shutdown(pToken)
ExitApp
Return</langsyntaxhighlight>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="basic">100 XO = 140
110 YO = 96
120 S = 90
130 B = 7
140 F = 6
150 C = 4
200 POKE 230,64
210 HCOLOR= B
220 HPLOT 0,0
230 CALL 62454
240 A = 49232
250 I = PEEK (A + 7) + PEEK (A + 2)
260 I = PEEK (A + 5) + PEEK (A)
300 SX = S
310 SY = S
320 PI = 3.1415926535
330 E = PI * 4
340 S = PI / 1.25
350 X = SIN (0)
360 Y = COS (0)
370 HCOLOR= F
380 PX = XO + X * SX
390 PY = YO - Y * SY
400 FOR I = 0 TO E STEP S
410 X = SIN (I)
420 Y = COS (I)
430 FOR J = 0 TO SX
440 HPLOT PX,PY TO XO + X * J,YO - Y * J
450 NEXT J
460 PX = XO + X * SX
470 PY = YO - Y * SY
480 NEXT I
500 HCOLOR= C
510 PX = XO + X * SX
520 PY = YO - Y * SY
600 FOR I = S TO E STEP S
610 X = SIN (I)
620 Y = COS (I)
630 HPLOT PX,PY TO XO + X * SX,YO - Y * SY
640 HPLOT PX + 1,PY TO XO + X * SX + 1,YO - Y * SY
650 HPLOT PX,PY + 1 TO XO + X * SX,YO - Y * SY + 1
660 HPLOT PX + 1,PY + 1 TO XO + X * SX + 1,YO - Y * SY + 1
670 PX = XO + X * SX
680 PY = YO - Y * SY
690 NEXT I</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Pentagra.bas"
110 OPTION ANGLE DEGREES
120 GRAPHICS HIRES 4
130 SET PALETTE BLUE,CYAN,YELLOW,BLACK
140 PLOT 640,700,ANGLE 288;
150 FOR I=1 TO 5
160 PLOT FORWARD 700,RIGHT 144;
170 NEXT
180 SET INK 3
190 SET BEAM OFF:PLOT 0,0,PAINT</syntaxhighlight>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">Sub pentagram()
With ActiveSheet.Shapes.AddShape(msoShape5pointStar, 10, 10, 400, 400)
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 3
.Line.ForeColor.RGB = RGB(0, 0, 255)
End With
End Sub</syntaxhighlight>
 
=={{header|C}}==
Interactive program which takes the side lengths of the pentagram's core, it's arms and the colours for filling the background, drawing the figure and then filling it in. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
 
<langsyntaxhighlight Clang="c">#include<graphics.h>
#include<stdio.h>
#include<math.h>
Line 241 ⟶ 499:
closegraph();
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Forms}}
{{libheader| System.Math}}
<syntaxhighlight lang="delphi">
unit Main;
 
interface
 
uses
Winapi.Windows, Vcl.Graphics, Vcl.Forms, System.Math;
 
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
procedure DrawPentagram(len, x, y: Integer; fill, stoke: TColor);
{ Private declarations }
public
{ Public declarations }
end;
 
var
Form1: TForm1;
degrees144: double;
degrees72: double;
degrees18: double;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientHeight := 640;
ClientWidth := 640;
degrees144 := DegToRad(144);
degrees72 := DegToRad(72);
degrees18 := DegToRad(18);
end;
 
procedure CreatePolygon(len, x, y, n: integer; ang: double; var points: TArray<TPoint>);
var
angle: Double;
index, i, x2, y2: Integer;
begin
angle := 0;
index := 0;
SetLength(points, n + 1);
points[index].Create(x, y);
 
for i := 1 to n do
begin
x2 := x + round(len * cos(angle));
y2 := y + round(len * sin(-angle));
x := x2;
y := y2;
angle := angle - ang;
 
points[index].Create(x2, y2);
inc(index);
end;
points[index].Create(points[0]);
end;
 
procedure TForm1.DrawPentagram(len, x, y: Integer; fill, stoke: TColor);
var
points, points_internal: TArray<TPoint>;
L, H: Integer;
begin
// Calc of sides for draw internal pollygon
// 2H+L = len -> 2H = len - L
// L = 2H*sin(36/2) (Pythagorean theorem)
// L = (len-L)sin(18)
// L = len*sin(18)/[1+sin(18)]
 
L := round(len * sin(degrees18) / (1 + sin(degrees18)));
 
// H = (len - L)/2
 
H := (len - L) div 2;
 
CreatePolygon(L, x + H, y, 5, degrees72, points_internal);
CreatePolygon(len, x, y, 5, degrees144, points);
 
with Canvas, Canvas.Brush do
begin
with pen do
begin
Color := stoke;
Style := psSolid;
Width := 5;
end;
Color := fill;
Polygon(points_internal);
Polygon(points);
end;
end;
 
procedure TForm1.FormPaint(Sender: TObject);
begin
with Canvas, Brush do
begin
Style := bsSolid;
Color := clWhite;
// fill background with white
FillRect(ClientRect);
end;
drawPentagram(500, 70, 250, $ED9564, clDkGray);
end;
 
end.</syntaxhighlight>
form code:
<syntaxhighlight lang="delphi">
object Form1: TForm1
OnCreate = FormCreate
OnPaint = FormPaint
end
</syntaxhighlight>
 
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=VY7NCsJADITveYo5ebAoayn+gD6JeJBa24V1s7RiN29vsnrQSxLmYyaTE07YOBLbW0fBx272t+eAmh786pATJNE8+NDhGnudR+xqRwCyWhRXaHn6siX2BYkiMTT5iNU/sxfqFbvv5wsWmvJzFz1bnaKWYkX7pFRat2loTS0HHnFwjhIH6TlaAL0B Run it]
[https://easylang.online/ide/?run=floatvars%0Axp%3D10%0Ayp%3D40%0Alinewidth%202%0Amove%20xp%20yp%0Awhile%20angle%20%3E%20-720%0Ax%3Dxp%2Bcos%20angle%2A80%0Ay%3Dyp%2Bsin%20-angle%2A80%0Aline%20x%20y%0Af%5B%5D%26%3Dx%0Af%5B%5D%26%3Dy%0Axp%3Dx%0Ayp%3Dy%0Aangle-%3D144%0A.%0Acolor%20900%0Afill%20f%5B%5D Run it]
 
<syntaxhighlight lang="text">
<lang>floatvars
xp = 10
yp = 4060
linewidth 2
move xp yp
while angle >< -720
x = xp + cos angle * 80
y = yp + sin -angle * 80
line x y
f[] &= x
f[] &= y
xp = x
yp = y
angle -+= 144
.
color 900
fillpolygon f[]</lang>
</syntaxhighlight>
 
=={{header|Go}}==
{{libheader|Go Graphics}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 300 ⟶ 681:
dc.Stroke()
dc.SavePNG("pentagram.png")
}</langsyntaxhighlight>
 
{{out}}
Line 313 ⟶ 694:
</pre>
creates a 400x400 SVG file.
<langsyntaxhighlight lang="haskell">-- Extract the vertices of a pentagon, re-ordering them so that drawing lines
-- from one to the next forms a pentagram. Set the line's thickness and its
-- colour, as well as the fill and background colours. Make the background a
Line 331 ⟶ 712:
# bgFrame 0.2 bisque
 
main = mainWith (pentagram :: Diagram B)</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<lang IS-BASIC>100 PROGRAM "Pentagra.bas"
110 OPTION ANGLE DEGREES
120 GRAPHICS HIRES 4
130 SET PALETTE BLUE,CYAN,YELLOW,BLACK
140 PLOT 640,700,ANGLE 288;
150 FOR I=1 TO 5
160 PLOT FORWARD 700,RIGHT 144;
170 NEXT
180 SET INK 3
190 SET BEAM OFF:PLOT 0,0,PAINT</lang>
 
=={{header|J}}==
Line 349 ⟶ 718:
Probably the simplest approach is:
 
<langsyntaxhighlight lang="j">require'plot'
plot j./2 1 o./180p_1 %~ 72144*i. 6</langsyntaxhighlight>
 
This will give a pentagram with a blue border and a white interior.
 
[[j:File:Pentagram-plot.png|example]]
 
=={{header|Java}}==
[[File:Pentagram Java.png|300px|thumb|right]]
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.geom.Path2D;
import javax.swing.*;
Line 419 ⟶ 790:
});
}
}</langsyntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry produces SVG output which, if placed in a file with suffix
.svg, can be viewed directly in most browsers.
 
Notice that the size of an appropriate SVG viewBox is computed.
 
<syntaxhighlight lang="jq"># Input: {svg, minx, miny, maxx, maxy}
def svg:
# viewBox = <min-x> <min-y> <width> <height>
"<svg viewBox='\(.minx - 4|floor) \(.miny - 4 |floor) \(6 + .maxx - .minx|ceil) \(6 + .maxy - .miny|ceil)'",
" preserveAspectRatio='xMinYmin meet'",
" xmlns='http://www.w3.org/2000/svg' >",
.svg,
"</svg>" ;
 
# Input: an array of [x,y] points
def minmax:
{minx: (map(.[0])|min),
miny: (map(.[1])|min),
maxx: (map(.[0])|max),
maxy: (map(.[1])|max)} ;
 
# Input: an array of [x,y] points
def Polyline($fill; $stroke; $transform):
def rnd: 1000*.|round/1000;
def linearize: map( map(rnd) | join(" ") ) | join(", ");
 
"<polyline points='"
+ linearize
+ "'\n style='fill:\($fill); stroke: \($stroke); stroke-width:3;'"
+ "\n transform='\($transform)' />" ;
 
# Output: {minx, miny, maxx, maxy, svg}
def pentagram($dim):
(8 * (1|atan)) as $tau
| 5 as $sides
| [ (0, 2, 4, 1, 3, 0)
| [ 0.9 * $dim * (($tau * $v / $sides) | cos),
0.9 * $dim * (($tau * $v / $sides) | sin) ] ]
| minmax
+ {svg: Polyline("seashell"; "blue"; "rotate(-18)" )} ;
 
pentagram(200)
| svg</syntaxhighlight>
{{out}}
<pre>
<svg viewBox='-150 -176 332 349'
preserveAspectRatio='xMinYmin meet'
xmlns='http://www.w3.org/2000/svg' >
<polyline points='180 0, -145.623 105.801, 55.623 -171.19, 55.623 171.19, -145.623 -105.801, 180 0'
style='fill:seashell; stroke: blue; stroke-width:3;'
transform='rotate(-18)' />
</svg>
</pre>
 
=={{header|Julia}}==
 
<langsyntaxhighlight lang="julia">using Luxor
 
function drawpentagram(path::AbstractString, w::Integer=1000, h::Integer=1000)
Line 441 ⟶ 870:
end
 
drawpentagram("data/pentagram.png")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.*
Line 504 ⟶ 933:
}
}
}</langsyntaxhighlight>
 
=={{header|Lua}}==
Using the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending with <code>line()</code> as [[Bitmap/Bresenham%27s_line_algorithm#Lua|here]], then extending with <code>floodfill()</code> as [[Bitmap/Flood_fill#Lua|here]], then extending further..
<syntaxhighlight lang="lua">local cos, sin, floor, pi = math.cos, math.sin, math.floor, math.pi
 
function Bitmap:render()
for y = 1, self.height do
print(table.concat(self.pixels[y]))
end
end
 
function Bitmap:pentagram(x, y, radius, rotation, outlcolor, fillcolor)
local function pxy(i) return x+radius*cos(i*pi*2/5+rotation), y+radius*sin(i*pi*2/5+rotation) end
local x1, y1 = pxy(0)
for i = 1, 5 do
local x2, y2 = pxy(i*2) -- btw: pxy(i) ==> pentagon
self:line(floor(x1*2), floor(y1), floor(x2*2), floor(y2), outlcolor)
x1, y1 = x2, y2
end
self:floodfill(floor(x*2), floor(y), fillcolor)
radius = radius / 2
for i = 1, 5 do
x1, y1 = pxy(i)
self:floodfill(floor(x1*2), floor(y1), fillcolor)
end
end
 
bitmap = Bitmap(40*2,40)
bitmap:clear(".")
bitmap:pentagram(20, 22, 20, -pi/2, "@", '+')
bitmap:render()</syntaxhighlight>
{{out}}
<pre style="font-size:50%">................................................................................
................................................................................
.......................................@@.......................................
......................................@++@......................................
......................................@++@......................................
.....................................@++++@.....................................
....................................@++++++@....................................
....................................@++++++@....................................
...................................@++++++++@...................................
...................................@++++++++@...................................
..................................@++++++++++@..................................
.................................@++++++++++++@.................................
.................................@++++++++++++@.................................
................................@++++++++++++++@................................
...............................@++++++++++++++++@...............................
.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.
....@@@+++++++++++++++++++++++@++++++++++++++++++@+++++++++++++++++++++++++@@@..
.......@@++++++++++++++++++++@++++++++++++++++++++@++++++++++++++++++++++@@.....
.........@@@+++++++++++++++++@++++++++++++++++++++@+++++++++++++++++++@@@.......
............@@@+++++++++++++@++++++++++++++++++++++@+++++++++++++++@@@..........
...............@@++++++++++@+++++++++++++++++++++++@+++++++++++++@@.............
.................@@@+++++++@++++++++++++++++++++++++@+++++++++@@@...............
....................@@@+++@++++++++++++++++++++++++++@+++++@@@..................
.......................@@+@++++++++++++++++++++++++++@+++@@.....................
.........................@@@++++++++++++++++++++++++++@@@.......................
........................@+++@@@++++++++++++++++++++@@@+@........................
........................@++++++@@+++++++++++++++@@@++++@........................
.......................@+++++++++@@@++++++++++@@++++++++@.......................
......................@+++++++++++++@@@++++@@@+++++++++++@......................
......................@++++++++++++++++@@@@++++++++++++++@......................
.....................@++++++++++++++++@@..@@++++++++++++++@.....................
....................@++++++++++++++@@@......@@@++++++++++++@....................
....................@+++++++++++@@@............@@@+++++++++@....................
...................@++++++++++@@..................@@++++++++@...................
...................@+++++++@@@......................@@@+++++@...................
..................@+++++@@@............................@@@+++@..................
.................@++++@@..................................@@++@.................
.................@+@@@......................................@@@.................
................@@@............................................@................
................................................................................</pre>
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">with(geometry):
RegularStarPolygon(middle, 5/2, point(c, 0, 0), 1):
v := [seq(coordinates(i), i in DefinedAs(middle))]:
pentagram := plottools[rotate](plottools[polygon](v), Pi/2):
plots[display](pentagram, colour = yellow, axes = none);</langsyntaxhighlight>
{{out}}
Note: Plot shown below is generated using interface(plotdevice = char);
Line 539 ⟶ 1,040:
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang="mathematica">Graphics[{
Graphics[{
EdgeForm[Directive[Thickness[0.01], RGBColor[0, 0, 1]]],(*Edge coloring*)
RGBColor[0.5, 0.5, .50], (*Fill coloring*)
Polygon[AnglePath[Table[6 Pi/5, 5]]]}
]</syntaxhighlight>
 
</lang>
=={{header|Nim}}==
{{works with|nim|1.4.4}}
{{libheader|nim-libgd}}
<syntaxhighlight lang="nim">
import libgd
from math import sin, cos, degToRad
 
const
width = 500
height = width
outerRadius = 200
 
proc main() =
 
proc calcPosition(x: int, y: int, radius: int, posAngle: float): (cint, cint) =
var width = int(radius.float * sin(degToRad(posAngle)))
var height = int(radius.float * cos(degToRad(posAngle)))
return (cast[cint](x + width), cast[cint](y - height))
 
proc getPentagonPoints(startAngle = 0, radius: int): array[5, array[2, int]] =
let spacingAngle = 360 / 5
 
var posAngle = (90 - startAngle).float
 
var n = 0
var points: array[5, array[2, int]]
while n < 5:
(points[n][0], points[n][1]) = calcPosition(250, 250, radius, posAngle)
n += 1
posAngle -= spacingAngle
 
return points
 
let outerPentagon = getPentagonPoints(18, outerRadius) # rotate 18 degrees
let innerPentagon = getPentagonPoints(54, int((cos(degToRad(72.0))/cos(degToRad(36.0))) * outerRadius)) # rotate 54 degrees
 
var pentagram: array[10, array[2, int]]
var n = 0
for i in countup(0, 4):
pentagram[n] = outerPentagon[i]
inc(n)
pentagram[n] = innerPentagon[i]
inc(n)
 
withGd imageCreate(width, height) as img:
discard img.setColor(255, 255, 255)
 
let black = img.setColor(0x404040)
let blue = img.setColor(0x6495ed)
 
img.drawPolygon(
points=pentagram,
color=blue,
fill=true,
open=false)
 
img.setThickness(4)
 
img.drawPolygon(
points=pentagram,
color=black,
fill=false,
open=false)
 
img.drawPolygon(
points=innerPentagon,
color=black,
fill=false,
open=false)
 
let png_out = open("pentagram.png", fmWrite)
img.writePng(png_out)
 
png_out.close()
 
main()
</syntaxhighlight>
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 642 ⟶ 1,219:
end
Return
::requires RxMath Library</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use SVG;
 
my $tau = 2 * 4*atan2(1, 1);
Line 684 ⟶ 1,261:
open $fh, '>', 'pentagram.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</langsyntaxhighlight>
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/pentagram.svg Pentagram] (offsite image)
 
=={{header|Phix}}==
{{libheader|pGUI}}
Resizable and optionally rotating gui (desktop) version
{{libheader|Phix/pGUI}}
<lang Phix>-- demo\rosetta\Pentagram.exw
{{libheader|Phix/online}}
include pGUI.e
You can run this online [http://phix.x10.mx/p2js/Pentagram.htm here].
 
<!--<syntaxhighlight lang="phix">(phixonline)-->
Ihandle dlg, canvas, timer
<span style="color: #000080;font-style:italic;">--
cdCanvas cddbuffer, cdcanvas
-- demo\rosetta\Pentagram.exw
 
-- ==========================
integer rot = 0
--
enum FILL,BORDER
-- Start/stop rotation by pressing space. Resizeable.
constant colours = {CD_BLUE,CD_RED},
-- ZXYV stop any rotation and orient up/down/left/right.
modes = {CD_FILL,CD_CLOSED_LINES}
--</span>
 
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
integer {w, h} = IupGetIntInt(canvas, "DRAWSIZE"),
cx = floor(w/2),
cy = floor(h/2),
r = floor(min(cx,cy)*0.9)
cdCanvasActivate(cddbuffer)
cdCanvasClear(cddbuffer)
cdCanvasSetFillMode(cddbuffer, CD_WINDING)
cdCanvasSetLineWidth(cddbuffer, round(radius/100)+1)
for mode=FILL to BORDER do
cdCanvasSetForeground(cddbuffer,colours[mode])
cdCanvasBegin(cddbuffer,modes[mode])
for a=90 to 666 by 144 do
atom ra = (a+rot)*CD_DEG2RAD,
x = r*cos(ra)+cx,
y = r*sin(ra)+cy
cdCanvasVertex(cddbuffer, x, y)
end for
cdCanvasEnd(cddbuffer)
end for
cdCanvasFlush(cddbuffer)
return IUP_DEFAULT
end function
 
function map_cb(Ihandle ih)
cdcanvas = cdCreateCanvas(CD_IUP, ih)
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
cdCanvasSetBackground(cddbuffer, CD_WHITE)
cdCanvasSetForeground(cddbuffer, CD_GRAY)
return IUP_DEFAULT
end function
 
function timer_cb(Ihandle /*ih*/)
rot = mod(rot+359,360)
IupRedraw(canvas)
return IUP_IGNORE
end function
 
function esc_close(Ihandle /*ih*/, atom c)
if c=K_ESC then return IUP_CLOSE end if
if c=' ' then
IupSetInt(timer,"RUN",not IupGetInt(timer,"RUN"))
end if
return IUP_CONTINUE
end function
 
procedure main()
IupOpen()
 
canvas = IupCanvas(NULL)
IupSetAttribute(canvas, "RASTERSIZE", "640x640")
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
 
dlg = IupDialog(canvas)
IupSetAttribute(dlg, "TITLE", "Pentagram")
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
 
IupShow(dlg)
IupSetAttribute(canvas, "RASTERSIZE", NULL)
timer = IupTimer(Icallback("timer_cb"), 80, active:=false)
IupMainLoop()
IupClose()
end procedure
 
main()</lang>
And a quick svg version
{{trans|Sidef}}
<lang Phix>constant HDR = """
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
<svg height="%d" width="%d" style="" xmlns="http://www.w3.org/2000/svg">
<rect height="100%%" width="100%%" style="fill:black;" />
"""
constant LINE = """
<polyline points="%s"
style="fill:blue; stroke:white; stroke-width:3;"
transform="translate(%d, %d) rotate(-18)" />
"""
 
function pentagram(integer dim=200, sides=5)
 
sequence v = repeat(0,sides)
for i=1 to sides do
atom theta = PI*2*(i-1)/5,
x = cos(theta)*dim,
y = sin(theta)*dim
v[i] = {sprintf("%.3f",x),
sprintf("%.3f",y)}
end for
v = append(v,v[1])
sequence q = {}
for i=1 to length(v) by 2 do
q &= v[i]
end for
for i=2 to length(v) by 2 do
q &= v[i]
end for
string res = sprintf(HDR,dim*2)
res &= sprintf(LINE,{join(q),dim,dim})
res &= "</svg>\n"
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">timer</span>
return res
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cdcanvas</span>
end function
<span style="color: #004080;">integer</span> <span style="color: #000000;">rot</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
puts(1,pentagram())</lang>
<span style="color: #008080;">enum</span> <span style="color: #000000;">FILL</span><span style="color: #0000FF;">,</span><span style="color: #000000;">BORDER</span>
Output identical to sidef
<span style="color: #008080;">constant</span> <span style="color: #000000;">colours</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">CD_BLUE</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_RED</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">modes</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">CD_FILL</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_CLOSED_LINES</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*posx*/</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*posy*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">w</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">radius</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">0.9</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetFillMode</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WINDING</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetLineWidth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">round</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radius</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">mode</span><span style="color: #0000FF;">=</span><span style="color: #000000;">FILL</span> <span style="color: #008080;">to</span> <span style="color: #000000;">BORDER</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">colours</span><span style="color: #0000FF;">[</span><span style="color: #000000;">mode</span><span style="color: #0000FF;">])</span>
<span style="color: #7060A8;">cdCanvasBegin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">modes</span><span style="color: #0000FF;">[</span><span style="color: #000000;">mode</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">=</span><span style="color: #000000;">90</span> <span style="color: #008080;">to</span> <span style="color: #000000;">666</span> <span style="color: #008080;">by</span> <span style="color: #000000;">144</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #000000;">rot</span><span style="color: #0000FF;">)*</span><span style="color: #004600;">CD_DEG2RAD</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radius</span><span style="color: #0000FF;">*</span><span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radius</span><span style="color: #0000FF;">*</span><span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasVertex</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">cdCanvasEnd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_PARCHMENT</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">rot</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rot</span><span style="color: #0000FF;">+</span><span style="color: #000000;">359</span><span style="color: #0000FF;">,</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupRedraw</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">key_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_ESC</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CLOSE</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #008000;">' '</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #008080;">not</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ZYXV"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">rot</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">90</span>
<span style="color: #7060A8;">IupRedraw</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=640x640"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="Pentagram"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"KEY_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"key_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">timer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">80</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">active</span><span style="color: #0000FF;">:=</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
And a quick svg version, output identical to sidef
{{trans|Sidef}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">HDR</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
&lt;?xml version="1.0" standalone="no" ?&gt;
&lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd"&gt;
&lt;svg height="%d" width="%d" style="" xmlns="http://www.w3.org/2000/svg"&gt;
&lt;rect height="100%%" width="100%%" style="fill:black;" /&gt;
"""</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">LINE</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
&lt;polyline points="%s"
style="fill:blue; stroke:white; stroke-width:3;"
transform="translate(%d, %d) rotate(-18)" /&gt;
"""</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pentagram</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">dim</span><span style="color: #0000FF;">=</span><span style="color: #000000;">200</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">sides</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">v</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sides</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">sides</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">theta</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">PI</span><span style="color: #0000FF;">*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">theta</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">dim</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">theta</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">dim</span>
<span style="color: #000000;">v</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%.3f"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">x</span><span style="color: #0000FF;">),</span>
<span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%.3f"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">v</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v</span><span style="color: #0000FF;">,</span><span style="color: #000000;">v</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">q</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">q</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">q</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">HDR</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dim</span><span style="color: #0000FF;">*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">LINE</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">q</span><span style="color: #0000FF;">),</span><span style="color: #000000;">dim</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dim</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">"&lt;/svg&gt;\n"</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pentagram</span><span style="color: #0000FF;">())</span>
<!--</syntaxhighlight>-->
 
=={{header|PostScript}}==
<langsyntaxhighlight lang="postscript">%!PS-Adobe-3.0 EPSF
%%BoundingBox: 0 0 200 600
Line 831 ⟶ 1,425:
s 170 t p s 2 setlinewidth stroke r g fill r % non-zero, but hide inner strokes
 
%%EOF</langsyntaxhighlight>
 
The following isn't exactly what the task asks for, but it's kind of fun if you have a PS interpreter that progressively updates. The program draws a lot of stars, so it's extremely likely that some of them are pentagrams...
<langsyntaxhighlight lang="postscript">%!PS-Adobe-3.0 EPSF
%%BoundingBox: 0 0 400 400
 
Line 860 ⟶ 1,454:
 
0 setlinewidth 2000 {star} repeat showpage
%%EOF</langsyntaxhighlight>
 
=={{header|Processing}}==
<syntaxhighlight lang="java">
//Aamrun, 29th June 2022
 
size(1000,1000);
 
translate(width/2,height/2);
rotate(3*PI/2);
fill(#0000ff);
 
beginShape();
for(int i=0;i<10;i+=2){
 
vertex(450*cos(i*2*PI/5),450*sin(i*2*PI/5));
}
endShape(CLOSE);
</syntaxhighlight>
 
=={{header|Python}}==
{{works with|Python|3.4.1}}
 
<langsyntaxhighlight lang="python">import turtle
 
turtle.bgcolor("green")
Line 874 ⟶ 1,486:
t.forward(200)
t.right(144)
t.end_fill()</langsyntaxhighlight>
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">[ $ "turtleduck.qky" loadfile ] now!
 
[ [ 1 1
30 times
[ tuck + ]
swap join ] constant
do ] is phi ( --> n/d )
 
[ 5 times
[ 2dup walk
1 5 turn
2dup walk
3 5 turn ]
2drop ] is star ( n/d --> )
[ 5 times
[ 2dup walk
2 5 turn ]
2drop ] is pentagram ( n/d --> )
 
turtle
' [ 79 126 229 ] fill [ 200 1 star ]
10 wide
-1 10 turn
200 1 phi v* phi v* pentagram
1 10 turn</syntaxhighlight>
 
{{output}}
 
[[File:Quackery pentagram.png]]
 
=={{header|R}}==
Very simple approach,
<langsyntaxhighlight Rlang="r">p <- cbind(x = c(0, 1, 2,-0.5 , 2.5 ,0),
y = c(0, 1, 0,0.6, 0.6,0))
plot(p)
lines(p)</langsyntaxhighlight>
 
==={{header|Using circle equation}}===
Line 889 ⟶ 1,533:
each point on the circumference is 72 degrees apart,
5 points on the circles circumference are calculated and than plotted and line drawn in-between to produce pentagram
<langsyntaxhighlight lang="rsplus">#Circle equation
#x = r*cos(angle) + centre_x
#y = r*sin(angle) + centre_y
Line 942 ⟶ 1,586:
col = "#1b98e0",
border = "red",
lwd = 5)</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
(require 2htdp/image)
 
(overlay
(star-polygon 100 5 2 "outline" (make-pen "blue" 4 "solid" "round" "round"))
(star-polygon 100 5 2 "solid" "cyan"))</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 957 ⟶ 1,601:
{{works with|rakudo|2018.08}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<syntaxhighlight lang="raku" perl6line>use SVG;
 
constant $dim = 200;
Line 976 ⟶ 1,620:
],
],
);</langsyntaxhighlight>
See [https://github.com/thundergnat/rc/blob/master/img/pentagram-perl6.svg Pentagram] (offsite svg image)
 
Line 983 ⟶ 1,627:
 
=={{header|Red}}==
<langsyntaxhighlight lang="red">Red [
Source: https://github.com/vazub/rosetta-red
Tabs: 4
Line 1,014 ⟶ 1,658:
]
]
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
{{trans|ooRexx}}
<langsyntaxhighlight lang="rexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 1,186 ⟶ 1,830:
End
Numeric Digits prec
Return r+0</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Pentagram
 
Line 1,252 ⟶ 1,896:
label1 { setpicture(p1) show() }
return
</syntaxhighlight>
</lang>
Output:
 
Line 1,259 ⟶ 1,903:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.geom.Path2D
 
Line 1,311 ⟶ 1,955:
)
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
Generates a SVG image to STDOUT.
<langsyntaxhighlight lang="ruby">func pentagram(dim=200, sides=5) {
var pentagram = <<-EOT
<?xml version="1.0" standalone="no" ?>
Line 1,324 ⟶ 1,968:
<rect height="100%" width="100%" style="fill:black;" />
EOT
 
func cis(x) {
cos(x) + sin(x).i
}
 
func pline(q) {
<<-EOT
<polyline points="#{[q..., q[0], q[1]].map{|n| '%0.3f' % n }.map(q, q[0], q[1]).join(' ')}"
style="fill:blue; stroke:white; stroke-width:3;"
transform="translate(#{dim}, #{dim}) rotate(-18)" />
Line 1,337 ⟶ 1,977:
}
 
var v = sides.range.map {|k| 0.9 * dim * cis(k * Num.tau / sides) }.map(^sides)
pentagram += pline([v[range(0, v.end, 2)], v[range(1, v.end, 2)]].map{.reals})
pentagram += '</svg>'
Line 1,344 ⟶ 1,984:
}
 
say pentagram()</langsyntaxhighlight>
{{out}}
<pre><?xml version="1.0" standalone="no" ?>
Line 1,357 ⟶ 1,997:
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">mx,my = #.scrsize()
xc = mx/2
yc = my/2
Line 1,371 ⟶ 2,011:
#.drawcolor(1,1,0)
#.drawsize(1)
<</langsyntaxhighlight>
 
=={{header|Tcl}}==
This implementation draws a simple pentagram on a [http://wiki.tcl.tk/1415 Canvas] widget.
{{works with|Tcl|8.6}}
<syntaxhighlight lang="tcl">
<lang Tcl>
package require Tk 8.6 ;# lmap is new in Tcl/Tk 8.6
 
Line 1,401 ⟶ 2,041:
;# a fun reader exercise is to make the shape respond to mouse events,
;# or animate it!
</syntaxhighlight>
</lang>
 
=={{header|VBAWren}}==
{{trans|Go}}
<lang vb>Sub pentagram()
{{libheader|DOME}}
With ActiveSheet.Shapes.AddShape(msoShape5pointStar, 10, 10, 400, 400)
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color, Point
.Fill.ForeColor.RGB = RGB(255, 0, 0)
import "dome" for Window
.Line.Weight = 3
 
.Line.ForeColor.RGB = RGB(0, 0, 255)
class Game {
End With
static init() {
End Sub</lang>
Window.title = "Pentagram"
var width = 640
var height = 640
Window.resize(width, height)
Canvas.resize(width, height)
Canvas.cls(Color.white)
var col = Color.hex("#6495ed") // cornflower blue
for (i in 1..240) pentagram(320, 320, i, col)
for (i in 241..250) pentagram(320, 320, i, Color.black)
}
 
static update() {}
 
static draw(alpha) {}
 
static pentagram(x, y, r, col) {
var points = List.filled(5, null)
for (i in 0..4) {
var angle = 2*Num.pi*i/5 - Num.pi/2
points[i] = Point.new(x + r*angle.cos, y + r*angle.sin)
}
var prev = points[0]
for (i in 1..5) {
var index = (i * 2) % 5
var curr = points[index]
Canvas.line(prev.x, prev.y, curr.x, curr.y, col)
prev = curr
}
}
}</syntaxhighlight>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">proc FillArea(X, Y, C0, C); \Replace area colored C0 with color C
int X, Y, \starting coordinate for flood fill algorithm
C0, C; \initial color, and color to replace it with
def S=8000; \size of queue (must be an even number)
int Q(S), \queue (FIFO)
F, E; \fill and empty indexes
 
proc EnQ(X, Y); \Enqueue coordinate
int X, Y;
[Q(F):= X;
F:= F+1;
Q(F):= Y;
F:= F+1;
if F >= S then F:= 0;
]; \EnQ
 
proc DeQ; \Dequeue coordinate
[X:= Q(E);
E:= E+1;
Y:= Q(E);
E:= E+1;
if E >= S then E:= 0;
]; \DeQ
 
[if C0 = C then return;
F:= 0; E:= 0;
EnQ(X, Y);
while E # F do
[DeQ;
if ReadPix(X, Y) = C0 then
[Point(X, Y, C);
EnQ(X+1, Y); \enqueue adjacent pixels
EnQ(X-1, Y);
EnQ(X, Y+1);
EnQ(X, Y-1);
];
];
]; \FillArea
 
def Size = 200.;
def Pi = 3.141592654;
def Deg144 = 4.*Pi/5.;
int X, Y, N;
[SetVid($12); \set 640x480x4 VGA graphics
for Y:= 0 to 480-1 do \fill screen
[Move(0, Y); Line(640-1, Y, $F\white\)];
for N:= 0 to 5 do \draw pentagram
[X:= fix(Size*Sin(float(N)*Deg144));
Y:= fix(Size*Cos(float(N)*Deg144));
if N = 0 then Move(X+320, 240-Y)
else Line(X+320, 240-Y, 4\red\);
];
FillArea(0, 0, $F, 1); \replace white (F) with blue (1)
]</syntaxhighlight>
 
=={{header|zkl}}==
{{template:incorrect|The background and foreground colors are the same.}}
{{trans|Raku}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<langsyntaxhighlight lang="zkl">const DIM=200, SIDES=5, A=360/SIDES, R=DIM.toFloat();
vs:=[0.0..360-A,A].apply("toRad"); // angles of vertices
#<<<
Line 1,439 ⟶ 2,166:
);
}
println("</svg>");</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits