Pentagram: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(6 intermediate revisions by 5 users not shown)
Line 15:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
DEFINE REALPTR="CARD"
Line 198:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Pentagram.png Screenshot from Atari 8-bit computer]
Line 204:
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
Line 297:
Window.Finalize;
SDL.Finalise;
end Pentagram;</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
<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</lang>
 
=={{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 409 ⟶ 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 477 ⟶ 499:
closegraph();
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 483 ⟶ 505:
{{libheader| Vcl.Forms}}
{{libheader| System.Math}}
<syntaxhighlight lang="delphi">
<lang Delphi>
unit Main;
 
Line 591 ⟶ 613:
end;
 
end.</langsyntaxhighlight>
form code:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Form1: TForm1
OnCreate = FormCreate
OnPaint = FormPaint
end
</syntaxhighlight>
</lang>
 
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=VY7NCsJADITveYo5ebAoayn+gD6JeJBa24V1s7RiN29vsnrQSxLmYyaTE07YOBLbW0fBx272t+eAmh786pATJNE8+NDhGnudR+xqRwCyWhRXaHn6siX2BYkiMTT5iNU/sxfqFbvv5wsWmvJzFz1bnaKWYkX7pFRat2loTS0HHnFwjhIH6TlaAL0B Run it]
[https://easylang.online/apps/_pentagram.html Run it]
 
<syntaxhighlight lang="text">
<lang>xp = 10
ypxp = 4010
yp = 60
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
polygon f[]</lang>
</syntaxhighlight>
 
=={{header|Go}}==
{{libheader|Go Graphics}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 657 ⟶ 681:
dc.Stroke()
dc.SavePNG("pentagram.png")
}</langsyntaxhighlight>
 
{{out}}
Line 670 ⟶ 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 688 ⟶ 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 706 ⟶ 718:
Probably the simplest approach is:
 
<langsyntaxhighlight lang="j">require'plot'
plot j./2 1 o./180p_1 %~ 144*i. 6</langsyntaxhighlight>
 
This will give a pentagram with a blue border and a white interior.
Line 716 ⟶ 728:
[[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 778 ⟶ 790:
});
}
}</langsyntaxhighlight>
 
=={{header|jq}}==
Line 789 ⟶ 801:
Notice that the size of an appropriate SVG viewBox is computed.
 
<langsyntaxhighlight lang="jq"># Input: {svg, minx, miny, maxx, maxy}
def svg:
# viewBox = <min-x> <min-y> <width> <height>
Line 826 ⟶ 838:
 
pentagram(200)
| svg</langsyntaxhighlight>
{{out}}
<pre>
Line 840 ⟶ 852:
=={{header|Julia}}==
 
<langsyntaxhighlight lang="julia">using Luxor
 
function drawpentagram(path::AbstractString, w::Integer=1000, h::Integer=1000)
Line 858 ⟶ 870:
end
 
drawpentagram("data/pentagram.png")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.*
Line 921 ⟶ 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..
<langsyntaxhighlight lang="lua">local cos, sin, floor, pi = math.cos, math.sin, math.floor, math.pi
 
function Bitmap:render()
Line 952 ⟶ 964:
bitmap:clear(".")
bitmap:pentagram(20, 22, 20, -pi/2, "@", '+')
bitmap:render()</langsyntaxhighlight>
{{out}}
<pre style="font-size:50%">................................................................................
Line 996 ⟶ 1,008:
 
=={{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 1,029 ⟶ 1,041:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang="mathematica">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]]]}
]</langsyntaxhighlight>
 
=={{header|Nim}}==
{{works with|nim|1.4.4}}
{{libheader|nim-libgd}}
<langsyntaxhighlight lang="nim">
import libgd
from math import sin, cos, degToRad
Line 1,111 ⟶ 1,123:
 
main()
</syntaxhighlight>
</lang>
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 1,207 ⟶ 1,219:
end
Return
::requires RxMath Library</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use SVG;
 
my $tau = 2 * 4*atan2(1, 1);
Line 1,249 ⟶ 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)
 
Line 1,257 ⟶ 1,269:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Pentagram.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Pentagram.exw
Line 1,345 ⟶ 1,357:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
And a quick svg version, output identical to sidef
{{trans|Sidef}}
<!--<langsyntaxhighlight Phixlang="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;">"""
Line 1,390 ⟶ 1,402:
<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>
<!--</langsyntaxhighlight>-->
 
=={{header|PostScript}}==
<langsyntaxhighlight lang="postscript">%!PS-Adobe-3.0 EPSF
%%BoundingBox: 0 0 200 600
Line 1,413 ⟶ 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 1,442 ⟶ 1,454:
 
0 setlinewidth 2000 {star} repeat showpage
%%EOF</langsyntaxhighlight>
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">
//Aamrun, 29th June 2022
 
Line 1,460 ⟶ 1,472:
}
endShape(CLOSE);
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
{{works with|Python|3.4.1}}
 
<langsyntaxhighlight lang="python">import turtle
 
turtle.bgcolor("green")
Line 1,474 ⟶ 1,486:
t.forward(200)
t.right(144)
t.end_fill()</langsyntaxhighlight>
 
=={{header|Quackery}}==
<langsyntaxhighlight Quackerylang="quackery">[ $ "turtleduck.qky" loadfile ] now!
 
[ [ 1 1
Line 1,502 ⟶ 1,514:
-1 10 turn
200 1 phi v* phi v* pentagram
1 10 turn</langsyntaxhighlight>
 
{{output}}
 
[[File:Quackery pentagram.png]]
https://imgur.com/zPMYLTS
 
=={{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 1,521 ⟶ 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 1,574 ⟶ 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 1,589 ⟶ 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 1,608 ⟶ 1,620:
],
],
);</langsyntaxhighlight>
See [https://github.com/thundergnat/rc/blob/master/img/pentagram-perl6.svg Pentagram] (offsite svg image)
 
Line 1,615 ⟶ 1,627:
 
=={{header|Red}}==
<langsyntaxhighlight lang="red">Red [
Source: https://github.com/vazub/rosetta-red
Tabs: 4
Line 1,646 ⟶ 1,658:
]
]
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
{{trans|ooRexx}}
<langsyntaxhighlight lang="rexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 1,818 ⟶ 1,830:
End
Numeric Digits prec
Return r+0</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Pentagram
 
Line 1,884 ⟶ 1,896:
label1 { setpicture(p1) show() }
return
</syntaxhighlight>
</lang>
Output:
 
Line 1,891 ⟶ 1,903:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.geom.Path2D
 
Line 1,943 ⟶ 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,956 ⟶ 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,969 ⟶ 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,976 ⟶ 1,984:
}
 
say pentagram()</langsyntaxhighlight>
{{out}}
<pre><?xml version="1.0" standalone="no" ?>
Line 1,989 ⟶ 1,997:
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">mx,my = #.scrsize()
xc = mx/2
yc = my/2
Line 2,003 ⟶ 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 2,033 ⟶ 2,041:
;# a fun reader exercise is to make the shape respond to mouse events,
;# or animate it!
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<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</lang>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 2,081 ⟶ 2,080:
}
}
}</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="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
Line 2,137 ⟶ 2,136:
];
FillArea(0, 0, $F, 1); \replace white (F) with blue (1)
]</langsyntaxhighlight>
 
=={{header|zkl}}==
Line 2,143 ⟶ 2,142:
{{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 2,167 ⟶ 2,166:
);
}
println("</svg>");</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits