Pentagram: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
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}}==
<langsyntaxhighlight lang="basic">100 XO = 140
110 YO = 96
120 S = 90
Line 344:
670 PX = XO + X * SX
680 PY = YO - Y * SY
690 NEXT I</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 409:
Gdip_Shutdown(pToken)
ExitApp
Return</langsyntaxhighlight>
 
=={{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:
closegraph();
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 483:
{{libheader| Vcl.Forms}}
{{libheader| System.Math}}
<syntaxhighlight lang="delphi">
<lang Delphi>
unit Main;
 
Line 591:
end;
 
end.</langsyntaxhighlight>
form code:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Form1: TForm1
OnCreate = FormCreate
OnPaint = FormPaint
end
</syntaxhighlight>
</lang>
 
 
Line 604:
[https://easylang.online/apps/_pentagram.html Run it]
 
<syntaxhighlight lang="text">xp = 10
yp = 40
linewidth 2
Line 619:
.
color 900
polygon f[]</langsyntaxhighlight>
 
=={{header|Go}}==
{{libheader|Go Graphics}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 657:
dc.Stroke()
dc.SavePNG("pentagram.png")
}</langsyntaxhighlight>
 
{{out}}
Line 670:
</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:
# bgFrame 0.2 bisque
 
main = mainWith (pentagram :: Diagram B)</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Pentagra.bas"
110 OPTION ANGLE DEGREES
120 GRAPHICS HIRES 4
Line 700:
170 NEXT
180 SET INK 3
190 SET BEAM OFF:PLOT 0,0,PAINT</langsyntaxhighlight>
 
=={{header|J}}==
Line 706:
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:
[[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:
});
}
}</langsyntaxhighlight>
 
=={{header|jq}}==
Line 789:
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:
 
pentagram(200)
| svg</langsyntaxhighlight>
{{out}}
<pre>
Line 840:
=={{header|Julia}}==
 
<langsyntaxhighlight lang="julia">using Luxor
 
function drawpentagram(path::AbstractString, w::Integer=1000, h::Integer=1000)
Line 858:
end
 
drawpentagram("data/pentagram.png")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.*
Line 921:
}
}
}</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:
bitmap:clear(".")
bitmap:pentagram(20, 22, 20, -pi/2, "@", '+')
bitmap:render()</langsyntaxhighlight>
{{out}}
<pre style="font-size:50%">................................................................................
Line 996:
 
=={{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:
 
=={{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:
 
main()
</syntaxhighlight>
</lang>
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 1,207:
end
Return
::requires RxMath Library</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use SVG;
 
my $tau = 2 * 4*atan2(1, 1);
Line 1,249:
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:
{{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:
<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:
<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:
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:
 
0 setlinewidth 2000 {star} repeat showpage
%%EOF</langsyntaxhighlight>
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">
//Aamrun, 29th June 2022
 
Line 1,460:
}
endShape(CLOSE);
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
{{works with|Python|3.4.1}}
 
<langsyntaxhighlight lang="python">import turtle
 
turtle.bgcolor("green")
Line 1,474:
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 10 turn
200 1 phi v* phi v* pentagram
1 10 turn</langsyntaxhighlight>
 
{{output}}
Line 1,510:
=={{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:
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:
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:
{{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:
],
],
);</langsyntaxhighlight>
See [https://github.com/thundergnat/rc/blob/master/img/pentagram-perl6.svg Pentagram] (offsite svg image)
 
Line 1,615:
 
=={{header|Red}}==
<langsyntaxhighlight lang="red">Red [
Source: https://github.com/vazub/rosetta-red
Tabs: 4
Line 1,646:
]
]
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
{{trans|ooRexx}}
<langsyntaxhighlight lang="rexx">/* REXX ***************************************************************
* Create a BMP file showing a pentagram
**********************************************************************/
Line 1,818:
End
Numeric Digits prec
Return r+0</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Pentagram
 
Line 1,884:
label1 { setpicture(p1) show() }
return
</syntaxhighlight>
</lang>
Output:
 
Line 1,891:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.geom.Path2D
 
Line 1,943:
)
 
}</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,976:
}
 
say pentagram()</langsyntaxhighlight>
{{out}}
<pre><?xml version="1.0" standalone="no" ?>
Line 1,989:
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">mx,my = #.scrsize()
xc = mx/2
yc = my/2
Line 2,003:
#.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:
;# a fun reader exercise is to make the shape respond to mouse events,
;# or animate it!
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Sub pentagram()
With ActiveSheet.Shapes.AddShape(msoShape5pointStar, 10, 10, 400, 400)
.Fill.ForeColor.RGB = RGB(255, 0, 0)
Line 2,042:
.Line.ForeColor.RGB = RGB(0, 0, 255)
End With
End Sub</langsyntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 2,081:
}
}
}</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:
];
FillArea(0, 0, $F, 1); \replace white (F) with blue (1)
]</langsyntaxhighlight>
 
=={{header|zkl}}==
Line 2,143:
{{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:
);
}
println("</svg>");</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits