# Generate a 5-pointed star [closed]

Your challenge is generate a 5 pointed star like below. The star doesn't need to be filled. Shortest code wins.

• Your image shows a Five-pointed-star, a pentagram has the connecting lines. Dec 2 '13 at 9:06
• @Iszi Looks like shortest question wins. Dec 2 '13 at 18:05
• wingdings, 1: « (character 0xAB), or unicode: Pentagram: ⛤ U+26E4 &#9956; New in Unicode 6 Dec 2 '13 at 19:40
• @SeanC They're standard. That means you don't have to specifically state they are disallowed. Mar 29 '17 at 15:32
• So? Meta discussions are often applied retroactively. The entire site is held to the same standards and cleaned up after the fact, rather than only new questions having to abide by new rules. This is because old questions can always be answered later. Mar 30 '17 at 16:35

# PHP, 1 character

Although very short it will probably not become the accepted answer.

☆


(this is U+2606). May work also in other languages (untested).

• Also, this answer is invalid, because the challenge is [graphical-output], not [ascii-art]. Mar 29 '17 at 15:45
• @mbomb007 Character glyphs are hardly ASCII art. Mar 29 '17 at 16:00
• So it's unicode. Either way, it's not valid. Mar 29 '17 at 16:03
• @mbomb007 I'm not nitpicking because you said ASCII. ASCII art uses several characters to resemble a shape; this is different. Provided that a proper font is used, this prints the desired output in a terminal or a web browser, so I fail to see why it would be invalid. Mar 29 '17 at 16:49
• Because that's not in the spirit of the challenge. If every answer used print"☆" or some variant because it's the shortest, this wouldn't be a challenge. Mar 29 '17 at 17:36

## LOGO, 32 29 bytes

REPEAT 5[FW 9LT 144FW 9RT 72]


Run at logo.twentygototen.org

• Actually you don't need spaces after the numbers (3 chars) Dec 2 '13 at 9:01
• @Howard: thanks for the tip. Dec 2 '13 at 10:26
• Can be shorter if you make the pentagram defined in the OP's link: REPEAT 5[FW 9LT 144] Dec 2 '13 at 17:24

# VBA PowerPoint, 92 bytes

Sub s()
ActivePresentation.Slides(1).Shapes.AddShape msoShape5pointStar, 0, 0, 99, 99
End Sub


Because everything looks better in PowerPoint:

• If you convert this to an immediates window function, convert msoShape5pointStar to its constant value (92) and remove the whitespace between the commas and values (ActivePresentation.Slides(1).Shapes.AddShape 92,0,0,99,99) you can condense the byte count to 57 bytes Mar 28 '17 at 21:55

# Mathematica, 19 18 bytes

This is easy, using CirculantGraph.

I drew a pentagram as defined in the link the OP used.

5~CirculantGraph~2


A slightly longer way, but equally straightforward, is to use the curated "Lamina" entity. This returns a filled pentagram.

 "FilledPentagram"~LaminaData~"Image"


or

 EntityValue[Entity["Lamina","FilledPentagram"],"Image"]


• Is the space actually necessary? I don't speak Mathematica, but I know many other languages would be forgiving of omitting the space in a circumstance such as this.
– Iszi
Dec 2 '13 at 17:18
• No, the space is not necessary. That's why I didn't count the space. Just about the only time space matters is inside a string and in the case of implicit multiplication (e.g. 3 5 == 15). "==" is equals in Mathematica. Dec 2 '13 at 17:28
• One char less 5~CirculantGraph~2 Dec 3 '13 at 16:58

# Python 3, 137 bytes

Polar plot.

import pylab as P,numpy as N
S=N.sin
p=N.pi
a=.9*p
d=8e-4*p
A=lambda t:N.arange(0,t,d)
P.polar(A(4*p),list(S(a)/S(a-A(.8*p)))*5)
P.show()


• import pylab as P,math as M;α=[4*M.pi*i/5for i in range(6)];A=[1]*6;P.polar(α,A);P.show() (89 chars) paints similar figure
– AMK
Dec 6 '13 at 21:00
• @AMK nice, I see the trick. You could write it as a new answer.
– Ray
Dec 11 '13 at 1:27
• Non-ASCII characters are not a single byte. Edited to make ASCII-only in order for the byte count to be correct. Mar 29 '17 at 15:43

# Small Basic, 50 bytes

For i=1To 5
Turtle.Move(9)
Turtle.Turn(144)
EndFor


A verbose language, but it has built in turtle functionality. Slowly draws a very, very tiny pentagram.

# Scratch, 4-6 blocks (52-79 scratchblocks code)

This produces this

If anyone's interested, here's the project.
EDIT: To golf it, remove the pen down. You could remove the then flag clicked, too but it would only run if you clicked it. To golf the scratch blocks version, change "100" to "1", although you get a microscopic pentagram.

Nongolfed scratchblocks:

when gf clicked
clear
pen down
repeat (5
move (100) steps
turn cw (144) degrees

• If I was to be pedantic, I'd count the bytes of each block. Interesting choice, though. Oct 20 '15 at 9:25
• Consensus on meta is that Scratch answers be scored by the length of the corresponding scratchblocks code. Oct 24 '15 at 12:57
• @ev3commander: I wouldn't consider that question to be proper competitive code golf Oct 26 '15 at 0:44

# HTML & CSS: 270 269 bytes

<p id=a/><p id=b></p><p id=c></p><p id=d></p><p id=e></p><style>p{position:absolute;width:300px;border-top:solid #000;margin:100px;transform-origin:50% 1666%}#b{transform:rotate(72deg)}#c{transform:rotate(144deg)}#d{transform:rotate(216deg)}#e{transform:rotate(288deg)}


Sample run:

## HTML & CSS: 139 bytes

Impressing rewrite by Neil.

div{height:20px;width:300px;border-bottom:solid #000;margin:100px;transform-origin:33% 5%;transform:rotate(72deg)}
<div><div><div><div><div>

(Since first posted, all desktope browsers dropped vendor prefixes, so now one CSS code fits all.)

• I just get a single horizontal line... Chrome 31.0.1650.57 on Win7
– Doorknob
Dec 2 '13 at 21:50
• never mind, adding the -webkit- vendor prefix to transform-origin and transform fixed it. updated fiddle
– Doorknob
Dec 2 '13 at 21:53
• How do you do your syntax highlighting?
– Iszi
Dec 2 '13 at 22:08
• @lszi, not me, its Google Prettify. I just give it the language hint by adding a special HTML comment in front of the code block. See Syntax highlighting for code. Dec 3 '13 at 7:37
• You can save a bunch of bytes by nesting your tags. I came up with <div><div><div><div><div> and div{height:20px;width:300px;border-bottom:solid #000;margin:100px;transform-origin:33% 5%;transform:rotate(72deg)} just through trial and error.
– Neil
Apr 4 '17 at 7:51

# HTML5, 37 bytes

<svg><path d="M4,0 7,8 0,3 8,3 1,8"/>

• HTML5, am I right? Oct 20 '15 at 9:07
• jsfiddle.net/790yyta6 Oct 20 '15 at 11:25

## Tcl/Tk, 57 bytes

pack [canvas .c]
.c cr po 72 0 114 130 3 49 140 49 29 130

• This actually draws a pentagram, but you don't see the connecting lines because it is filled with black. Dec 2 '13 at 9:42
• I feel like by that logic you could paint the whole canvas black, and say: "This paints the pentagram, but it's the same colour as the background". So long as we only care about the output in determining correctness, these are indistinguishable(painting the whole canvas vs. painting black pentagram on a black canvas). Dec 2 '13 at 13:49
• @Cruncher the star don't need filled -> but I can fill it. And the question asked for a pentagram, so I draw a filled pentagram that looks like the one in the question, only filled. Dec 2 '13 at 14:36

# TurtleGolf, 7024 22 bytes

Note: This is non-competing, as this language was made after this challenge was posted (though specifically for this challenge).

0;
aa*^aa*4b*+>1+:5=?;


Explaination:

0; - Initialize the loop counter and go to the next line.
aa* - Get the value 100
^ - Move forward by 100px
aa*4b*+ - Get the value 144
> - Rotate 144 degrees to the right
1+ - Increment the loop counter by 1
: - Duplicate it cause we need a copy of it.
5= - Check if the loop counter equals 5, push 1 if it is.
?; - If the top of the stack equals 1, terminate the line.


### Old, loopless version.

aa*^aa*4a*+4+>aa*^aa*4a*+4+>aa*^aa*4a*+4+>aa*^aa*4a*+4+>aa*^aa*4a*+4+>

I didn't add loops yet, so the code is kind of repetitive right now.

Explaination

aa*^              Move aa*(100) pixels forward
aa*4a*+a+         Get the value 144
>                 Turn 144 pixels to the right


EDIT: Shaved off lots of bytes.
EDIT2: Shaved off two more bytes.

• Can't wait for loops! Oct 19 '15 at 13:51
• @CᴏɴᴏʀO'Bʀɪᴇɴ I just added them :) Every single line is now a loop that executes until a ; is reached. Oct 20 '15 at 6:58
• What is the behaviour when the stack is not one? It just loops back to the beginning of the line? Oct 20 '15 at 10:39
• @CᴏɴᴏʀO'Bʀɪᴇɴ If the stack is exactly zero when you pass a zero, it skips the next instruction. It loops back to the beginning if there isnt any instruction to skip and skips the first instruction instead. Oct 20 '15 at 11:08
• @CᴏɴᴏʀO'Bʀɪᴇɴ When you pass a ?, not when you pass a zero. Sorry. Oct 20 '15 at 11:26

# Ruby with Shoes, 36 bytes

Shoes.app{star(points:5).move 99,99}


• What would happen if you used a smaller number like 9 instead of 99? Dec 2 '13 at 13:51
• @Cruncher The star would be off-screen and you would not be able to see it.
– Doorknob
Dec 2 '13 at 13:57
• Interesting concept. I should learn it. Dec 2 '13 at 18:08
• Is this valid? It's unclear what the angles have to be, but it doesn't match the image in the question. Mar 29 '17 at 16:05

# [C (msvc)], 88 bytes

#include<Windows.h>
main(){int p[]={50,1,20,91,97,35,2,35,79,91};Polygon(GetDC(0),p,5);}


# Desmos, 46 characters

r=\sec\left(.4\arccos\left(\cos2.5\theta\right)\right)


Here is a longer version that allows you to choose some n:

r=\sec\left(\frac{2}{n}\arccos\left(\cos\frac{n\theta}{2}\right)\right)

• Does this work the same way as the octave answer? Mar 28 '17 at 22:56
• @GenericDisplayName Frankly, I have no idea. Probably, yeah, they both use polar things Mar 28 '17 at 23:03

$hexdump -C pentagram_binary.ps 00000000 39 20 39 92 ad 30 20 39 92 6b 36 7b 30 20 39 92 |9 9..0 9.k6{0 9.| 00000010 63 31 34 34 92 88 7d 92 83 92 a7 |c144..}....| 0000001b  Output: Un-golfed ASCII version: 9 9 translate 0 9 moveto 6{ 0 9 lineto 144 rotate }repeat stroke  # Python, 47 bytes from turtle import* for i in[144]*5:fd(i);rt(i)  Try it online The following (42 bytes) also works (Python 2 only), but Trinket doesn't allow exec, so you can't run it online. Also, the result is much smaller. from turtle import* exec'fd(9);rt(144);'*5  # Google Blockly, 3 blocks In response to the Scratch answer Blockly turtle doesn't need "so much" boilerplate code. This "code" can be ran here and produces this pentagram # Five pointed star, 5 blocks The five pointed star can be tested here • Well, I didn't need "so much" code either, if you remove the flag block then it runs if you click it. Also, after the initialization, you wouldn't need "pen down", but whatever. – user46167 Oct 20 '15 at 20:07 # Shell, 60 bytes (Coordinates shamelessly stolen from user1455003's SVG answer. For artistic merits upvote his answer.) convert -size 9x9 xc: -draw 'polygon 4,0 7,8 0,3 8,3 1,8' x:  Sample output: # R, 50 54 bytes plot(1:9,t="n",as=1);polygon(c(5,8,1,9,2),c(1,9,4,4,9))  Output: • This is not symmetrical? Oct 20 '15 at 10:02 • @freekvd it's just a problem of aspect ratio. See edit Oct 20 '15 at 12:30 # R, 40 bytes symbols(1,st=cbind(8,3,8,3,8,3,8,3,8,3))  # Swift 3, 394 370 bytes import UIKit UIGraphicsBeginImageContextWithOptions(CGSize(width:2,height:2),false,100) let c1=0.3,c2=0.8,s1=1.0,s2=0.6,o=(0.0,1.0),p=[o,(s2,-c2),(-s1,c1),(s1,c1),(-s2,-c2),o].map{CGPoint( x:$0.0,y:$0.1)},c=UIGraphicsGetCurrentContext()! c.translateBy(x:1,y:1) c.setLineWidth(1/100) c.move(to:p[0]) p.forEach{c.addLine(to:$0)}
c.fillPath()
UIImage(cgImage:c.makeImage()!)


# Octave, 24 bytes

polar(t=[1:.8:5]*pi,~~t)


Output:

Or, for 36 bytes you can have just the outline:

polar(t=[0:.2:2]*pi,1-mod(t,pi/2.5))


• An alternative without polar (but same length) would be plot(e.^(i*pi*[0:.8:4])) Oct 19 '15 at 21:03
• @flawr Yes it would! I was actually working on the second plot first and couldn't figure out a good way to generate the rho vector, so the first plot here is really just a chopped down version of the second. Oct 19 '15 at 21:07

# Tikz, 126120 125 bytes

5 bytes saved thanks to Julian Wolf

\documentclass[tikz]{standalone}\usetikzlibrary{shapes}\begin{document}\tikz{\node[draw=red,star]{};}\end{document}


This draws a red star shaped node at (0,0).

• I think \node can be substituted for \draw node to save a few bytes Apr 18 '17 at 23:04
• Make it 110: \documentclass[tikz]{standalone}\usetikzlibrary{shapes}\def~{document}\begin~\tikz\node[draw=red,star]{};\end~ Nice approach! Jun 2 '20 at 13:54

# Excel VBA, 37 35 Bytes

Anonymous VBE immediates window function that takes no input and outputs a five pointed star to the top left of the Sheet1 (default sheet) object

Sheet1.Shapes.AddShape 92,0,0,99,99


# Python 2, 52 bytes

from turtle import*;exec('fd(99);rt(144);'*5);done()


# JavaFX / FXML, 138 bytes

<?import javafx.scene.layout.*?><?import javafx.scene.shape.*?><Pane><children><SVGPath content="M4,0 7,8 0,3 8,3 1,8"/></children></Pane>


I haven't tested it yet, though

<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>

<Pane>
<children>
<SVGPath content="M4,0 7,8 0,3 8,3 1,8" stroke="BLACK"/>
</children>
</Pane>


# Python + Pylab, 48-byte copout answer

from pylab import*
plot(0,0,marker=(5,1))
show()


Plots a single point using a five-pointed star as a marker.

# TI-83/84 Basic, 32 bytes

Line(0,1,1,1:Line(0,0,.5,1.5:Line(1,0,.5,1.5


Note I haven't actually tested this out but I'm assuming it's going to show up as a low resolution, distorted star-shaped object.

• Line( command is one byte
• You don't have to count the three instances of :, so your character count would be 42. Oct 19 '15 at 13:59
• Thanks for updating me on this @CᴏɴᴏʀO'Bʀɪᴇɴ since then we have agreed that TI-Basic is counted in bytes not chars anyway. Oct 20 '15 at 12:34
• -1; this prints a barely-visible A-shaped figure, not a star. Oct 26 '15 at 1:35