7
\$\begingroup\$

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

enter image description here

\$\endgroup\$
14
  • 13
    \$\begingroup\$ Your image shows a Five-pointed-star, a pentagram has the connecting lines. \$\endgroup\$ Dec 2 '13 at 9:06
  • 2
    \$\begingroup\$ @Iszi Looks like shortest question wins. \$\endgroup\$ Dec 2 '13 at 18:05
  • 2
    \$\begingroup\$ wingdings, 1: « (character 0xAB), or unicode: Pentagram: ⛤ U+26E4 ⛤ New in Unicode 6 \$\endgroup\$
    – SeanC
    Dec 2 '13 at 19:40
  • 2
    \$\begingroup\$ @SeanC They're standard. That means you don't have to specifically state they are disallowed. \$\endgroup\$
    – mbomb007
    Mar 29 '17 at 15:32
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – mbomb007
    Mar 30 '17 at 16:35

28 Answers 28

30
\$\begingroup\$

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).

\$\endgroup\$
10
  • 3
    \$\begingroup\$ Also, this answer is invalid, because the challenge is [graphical-output], not [ascii-art]. \$\endgroup\$
    – mbomb007
    Mar 29 '17 at 15:45
  • 2
    \$\begingroup\$ @mbomb007 Character glyphs are hardly ASCII art. \$\endgroup\$
    – Dennis
    Mar 29 '17 at 16:00
  • 2
    \$\begingroup\$ So it's unicode. Either way, it's not valid. \$\endgroup\$
    – mbomb007
    Mar 29 '17 at 16:03
  • 2
    \$\begingroup\$ @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. \$\endgroup\$
    – Dennis
    Mar 29 '17 at 16:49
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – mbomb007
    Mar 29 '17 at 17:36
20
\$\begingroup\$

LOGO, 32 29 bytes

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

Run at logo.twentygototen.org

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

VBA PowerPoint, 92 bytes

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

Because everything looks better in PowerPoint:

enter image description here

\$\endgroup\$
1
  • 3
    \$\begingroup\$ 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 \$\endgroup\$ Mar 28 '17 at 21:55
11
\$\begingroup\$

Mathematica, 19 18 bytes

This is easy, using CirculantGraph.

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

5~CirculantGraph~2

pentagram


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"]

star

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Iszi
    Dec 2 '13 at 17:18
  • \$\begingroup\$ 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. \$\endgroup\$
    – DavidC
    Dec 2 '13 at 17:28
  • \$\begingroup\$ One char less 5~CirculantGraph~2 \$\endgroup\$ Dec 3 '13 at 16:58
10
\$\begingroup\$

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()

enter image description here

\$\endgroup\$
3
  • 4
    \$\begingroup\$ 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 \$\endgroup\$
    – AMK
    Dec 6 '13 at 21:00
  • \$\begingroup\$ @AMK nice, I see the trick. You could write it as a new answer. \$\endgroup\$
    – Ray
    Dec 11 '13 at 1:27
  • \$\begingroup\$ Non-ASCII characters are not a single byte. Edited to make ASCII-only in order for the byte count to be correct. \$\endgroup\$
    – mbomb007
    Mar 29 '17 at 15:43
8
\$\begingroup\$

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.

very tiny pentagram.

\$\endgroup\$
0
7
\$\begingroup\$

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

flagclearpendownrep5(move100turncw144)
This produces this
starbycat
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
\$\endgroup\$
3
  • \$\begingroup\$ If I was to be pedantic, I'd count the bytes of each block. Interesting choice, though. \$\endgroup\$
    – Wolfish
    Oct 20 '15 at 9:25
  • \$\begingroup\$ Consensus on meta is that Scratch answers be scored by the length of the corresponding scratchblocks code. \$\endgroup\$ Oct 24 '15 at 12:57
  • \$\begingroup\$ @ev3commander: I wouldn't consider that question to be proper competitive code golf \$\endgroup\$ Oct 26 '15 at 0:44
7
\$\begingroup\$

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.)

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I just get a single horizontal line... Chrome 31.0.1650.57 on Win7 \$\endgroup\$
    – Doorknob
    Dec 2 '13 at 21:50
  • 2
    \$\begingroup\$ never mind, adding the -webkit- vendor prefix to transform-origin and transform fixed it. updated fiddle \$\endgroup\$
    – Doorknob
    Dec 2 '13 at 21:53
  • \$\begingroup\$ How do you do your syntax highlighting? \$\endgroup\$
    – Iszi
    Dec 2 '13 at 22:08
  • \$\begingroup\$ @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. \$\endgroup\$
    – manatwork
    Dec 3 '13 at 7:37
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Neil
    Apr 4 '17 at 7:51
6
\$\begingroup\$

HTML5, 37 bytes

<svg><path d="M4,0 7,8 0,3 8,3 1,8"/>
\$\endgroup\$
2
4
\$\begingroup\$

Tcl/Tk, 57 bytes

pack [canvas .c]
.c cr po 72 0 114 130 3 49 140 49 29 130
\$\endgroup\$
3
  • \$\begingroup\$ This actually draws a pentagram, but you don't see the connecting lines because it is filled with black. \$\endgroup\$ Dec 2 '13 at 9:42
  • 1
    \$\begingroup\$ 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). \$\endgroup\$
    – Cruncher
    Dec 2 '13 at 13:49
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Dec 2 '13 at 14:36
4
\$\begingroup\$

TurtleGolf, 70 24 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.

\$\endgroup\$
6
  • \$\begingroup\$ Can't wait for loops! \$\endgroup\$ Oct 19 '15 at 13:51
  • 1
    \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ I just added them :) Every single line is now a loop that executes until a ; is reached. \$\endgroup\$ Oct 20 '15 at 6:58
  • \$\begingroup\$ What is the behaviour when the stack is not one? It just loops back to the beginning of the line? \$\endgroup\$ Oct 20 '15 at 10:39
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Oct 20 '15 at 11:08
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ When you pass a ?, not when you pass a zero. Sorry. \$\endgroup\$ Oct 20 '15 at 11:26
4
\$\begingroup\$

Ruby with Shoes, 36 bytes

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

screenshot

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

[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);}
\$\endgroup\$
3
\$\begingroup\$

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)
\$\endgroup\$
2
  • \$\begingroup\$ Does this work the same way as the octave answer? \$\endgroup\$ Mar 28 '17 at 22:56
  • \$\begingroup\$ @GenericDisplayName Frankly, I have no idea. Probably, yeah, they both use polar things \$\endgroup\$ Mar 28 '17 at 23:03
3
\$\begingroup\$

PostScript, 27 bytes

$ 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

Download to try.

Output:

Pentagram rendered by Ghostscript

Un-golfed ASCII version:

9 9 translate
0 9 moveto
6{
  0 9 lineto
  144 rotate
}repeat
stroke
\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

Google Blockly, 3 blocks

In response to the Scratch answer

Blockly turtle doesn't need "so much" boilerplate code.

Pentagram code

This "code" can be ran here and produces this pentagram

Pentagram output

Five pointed star, 5 blocks

The five pointed star can be tested here

Five pointed star codeFive pointed star output

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – user46167
    Oct 20 '15 at 20:07
2
\$\begingroup\$

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:

pentagram

\$\endgroup\$
2
\$\begingroup\$

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:

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is not symmetrical? \$\endgroup\$
    – freekvd
    Oct 20 '15 at 10:02
  • \$\begingroup\$ @freekvd it's just a problem of aspect ratio. See edit \$\endgroup\$
    – plannapus
    Oct 20 '15 at 12:30
2
\$\begingroup\$

R, 40 bytes

symbols(1,st=cbind(8,3,8,3,8,3,8,3,8,3))

enter image description here

\$\endgroup\$
2
\$\begingroup\$

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()!)

enter image description here

\$\endgroup\$
1
\$\begingroup\$

Octave, 24 bytes

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

Output:

enter image description here

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

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

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ An alternative without polar (but same length) would be plot(e.^(i*pi*[0:.8:4])) \$\endgroup\$
    – flawr
    Oct 19 '15 at 21:03
  • \$\begingroup\$ @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. \$\endgroup\$
    – beaker
    Oct 19 '15 at 21:07
1
\$\begingroup\$

Tikz, 126 120 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).

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

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

Sample Output

enter image description here

\$\endgroup\$
0
\$\begingroup\$

Python 2, 52 bytes

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

enter image description here

\$\endgroup\$
0
0
\$\begingroup\$

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>
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
-1
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\begingroup\$ You don't have to count the three instances of :, so your character count would be 42. \$\endgroup\$ Oct 19 '15 at 13:59
  • 1
    \$\begingroup\$ Thanks for updating me on this @CᴏɴᴏʀO'Bʀɪᴇɴ since then we have agreed that TI-Basic is counted in bytes not chars anyway. \$\endgroup\$
    – Timtech
    Oct 20 '15 at 12:34
  • 2
    \$\begingroup\$ -1; this prints a barely-visible A-shaped figure, not a star. \$\endgroup\$
    – lirtosiast
    Oct 26 '15 at 1:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.