-
Notifications
You must be signed in to change notification settings - Fork 20
/
sketch.js
executable file
·51 lines (47 loc) · 1.28 KB
/
sketch.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Convert a circle into a square
// by using a 'superellipse' formula
// See: http://mathworld.wolfram.com/Superellipse.html
// Golan Levin, August 2016
var nPoints = 90;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255, 255, 255);
noFill();
push();
translate(width/2, height/2);
rotate(PI*0.25);
var radius = width / 2 * 0.75;
var frac = map(sin(millis() / 2000.0), -1,1, 1,2);
stroke(0);
strokeWeight(3);
strokeJoin(ROUND);
beginShape();
for (var i = 0; i <= nPoints; i++) {
var t = map(i, 0, nPoints, 0, HALF_PI);
var px = radius * pow(cos(t), frac);
var py = radius * pow(sin(t), frac);
vertex(px, py);
}
for (var i = 0; i <= nPoints; i++) {
var t = map(i, 0, nPoints, 0, HALF_PI);
var px = radius * pow(cos(t), frac);
var py = 0 - radius * pow(sin(t), frac);
vertex(py, px);
}
for (var i = 0; i <= nPoints; i++) {
var t = map(i, 0, nPoints, 0, HALF_PI);
var px = 0 - radius * pow(cos(t), frac);
var py = 0 - radius * pow(sin(t), frac);
vertex(px, py);
}
for (var i = 0; i <= nPoints; i++) {
var t = map(i, 0, nPoints, 0, HALF_PI);
var px = 0 - radius * pow(cos(t), frac);
var py = radius * pow(sin(t), frac);
vertex(py, px);
}
endShape(CLOSE);
pop();
}