forked from felipecustodio/p5-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
78 lines (63 loc) · 1.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
let font;
let textLayer;
let container;
let w;
let h;
let border;
let angle = 0;
function updateContainer() {
container = select('#sketchContainer');
w = parseFloat(getComputedStyle(container.elt).getPropertyValue('width'));
h = parseFloat(getComputedStyle(container.elt).getPropertyValue('height'));
}
function windowResized() {
updateContainer();
resizeCanvas(w, h);
}
function setup() {
updateContainer();
canvas = createCanvas(w, h, WEBGL);
smooth();
canvas.parent("#sketchContainer");
}
function draw() {
translate(-width / 2, -height / 2);
background('#fffff8');
strokeWeight(1);
stroke('#222831');
fill('#222831');
stroke('#c7b198');
fill('#c7b198');
ellipse(mouseX, mouseY, 50, 50);
// drawings
push();
stroke('#c7b198');
strokeWeight(2);
translate(width / 2, height / 2);
noFill();
rotateY(angle);
rotateX(angle);
box(100, 100);
stroke('#321f28');
fill('#321f28');
// noFill();
sphere(25);
pop();
// border
stroke('#222831');
noFill();
strokeWeight(5);
rectMode("corners");
rect(0, 0, width, height);
angle += 0.01;
document.getElementById("fps").innerHTML = frameRate().toFixed(2);
}
function colorAlpha(aColor, alpha) {
// allows usage of HEX colors with alpha
const c = color(aColor);
let a = alpha;
if (alpha <= 0.1) {
a = 0.1;
}
return color('rgba(${[red(c), green(c), blue(c), a].join(', ')})');
}