html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<title>SVG/JS Star Generator</title>
</head>
<body>
<header>
<h1>SVG/JS Star Generator</h1>
<nav>
<input type='number' name='NBRANCH' value='5' min="3" max="12" placeholder='Branch count'>
<input type='number' name='INTRAD' value='40' min="0" max="100" placeholder='Internal radius'>
<input type='number' name='EXTRAD' value='100' min='0' max="100" placeholder='External radius'>
</nav>
</header>
<figure><svg width="200" height="200" viewport="0 0 200 200">
<polygon id="star" />
</svg></figure>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
html {
display:table;
table-layout:fixed;
width:100%;
}
html, body {
height:100%;
}
body {
display:table-cell; /*table-row;*/
vertical-align:middle;
font-family:sans-serif;
font-size:5vmin;
margin:0;
}
header {
padding:0 2.5vmin;
}
@media all and (orientation:landscape) {
body {
display:table-row;
}
header, figure {
display:table-cell;
vertical-align:middle;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var Dot = function(x,y) {
this.x = x;
this.y = y;
}
Dot.prototype.toString = function() {
return this.x+','+this.y;
}
function svg_star(branch_nb,int_radius,ext_radius) {
var dots = [];
var step = Math.PI/branch_nb;
var max = 2*branch_nb;
var r, a;
for (var i=0; i<=max; i++) {
r = (i&1)?ext_radius:int_radius;
a = i*step;
dots[i] = new Dot(r*Math.cos(a),r*Math.sin(a));
}
return dots;
}
function draw(target_id,x,y,d) {
var p = d.map((function(x,y) {
return function(v) {
return new Dot(x+v.x,y+v.y);
};
})(x,y));
document.getElementById(target_id).setAttribute('points',p.join(' '));
}
window.onload = function() {
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run