generated from drawwithcode/P5-empty-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch3.js
More file actions
69 lines (53 loc) · 1.26 KB
/
sketch3.js
File metadata and controls
69 lines (53 loc) · 1.26 KB
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
// this is the actual "translation" sketch
let mic;
let rectColorValueA;
let rectColorValueB;
let rectColorValueC;
let myFont;
let displayVolume;
function preload() {
myFont = loadFont("assets/nimbus.ttf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
//initialize the mic input
mic = new p5.AudioIn();
mic.start();
textAlign(CENTER);
textFont(myFont);
}
function draw() {
background(255);
noStroke();
//initialize mic
micLevel = mic.getLevel();
//NUMBER
push();
fill(0);
newmicLevelA = map(micLevel, 0, 1, 0, 255);
newmicLevelB = map(micLevel, 0, 1, 0, 0);
newmicLevelC = map(micLevel, 0, 1, 255, 0);
displayVolume = map(newmicLevelA, 0, 255, 0, 100);
displayVolume -= 1;
displayVolume = Math.abs(displayVolume);
displayVolume += 1;
textSize(100);
text(nfc(displayVolume, 0), width / 2, height / 5);
pop();
//SHAPE
push();
fill(0);
square(0, height / 3, width);
fill(255);
ellipse(width / 2, height / 2, width, displayVolume * 4.7);
pop();
//COLOUR
push();
rectColorValueA = newmicLevelA;
rectColorValueB = newmicLevelB;
rectColorValueC = newmicLevelC;
fill(rectColorValueA, rectColorValueB, rectColorValueC);
rect(0, height / 1.5, width, height / 1.5);
pop();
}