-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
67 lines (59 loc) · 1.58 KB
/
helpers.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Finds a point on a circle of a given radius
function pointOnCircle(posX, posY, radius, angle) {
const x = posX + radius * cos(angle);
const y = posY + radius * sin(angle);
return createVector(x, y);
}
// Draws a right triangle
function rightTriangle(posX, posY, length) {
beginShape();
const a = createVector(posX + length / 2, posY + length / 2);
const b = createVector(posX - length / 2, posY + length / 2);
const c = createVector(posX - length / 2, posY - length / 2);
vertex(a.x, a.y);
vertex(b.x, b.y);
vertex(c.x, c.y);
vertex(a.x, a.y);
endShape();
}
// Draws a hexagon
function hexagon(posX, posY, radius) {
const rotAngle = 360 / 6;
beginShape();
for (let i = 0; i < 6; i++) {
const thisVertex = pointOnCircle(posX, posY, radius, i * rotAngle);
vertex(thisVertex.x, thisVertex.y);
}
endShape(CLOSE);
}
// Randomly selects boolean value
function randomSelectTwo() {
// Number of Lines
const rand = random(1);
if (rand < 0.5) {
return true;
} else {
return false;
}
}
// Selects a color from PALETTE randomly
function getRandomFromPalette() {
const rand = floor(random(0, PALETTE.length - 1));
return PALETTE[rand];
}
// Applies a random rotation
function applyRotation() {
const angle = floor(random(4));
rotate(angle * 90);
}
// Handles logic for selecting shape to render
function renderShape(shape, shapeSize, transform) {
if (shape === 0) {
rect(0, 0, shapeSize);
} else if (shape === 1) {
ellipse(0, 0, shapeSize);
} else if (shape === 2) {
rotate(transform * 90);
rightTriangle(0, 0, shapeSize);
}
}