-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShape.cpp
73 lines (58 loc) · 1.64 KB
/
Shape.cpp
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
//
// Shape.cpp
// vjshader
//
// Created by Ecem Karaca on 23/05/2020.
//
#include "Shape.hpp"
void Shape::setup(){
sound.load("muziek.wav");
sound.play();
sound.setLoop(true);
// Setup shape positions
for (int i = 0; i < NUM_SHAPES; i++)
{
posShape.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-500, 500)));
colShape.push_back(ofColor::fromHsb(255 * i / (float)NUM_SHAPES, 255, 255, 255));
}
bands = 128;
fft = new float[bands];
for (int i = 0; i < bands; i++) {
fft[i] = 0;
}
ofSetLineWidth(10.0);
}
void Shape::update(){
ofSoundUpdate();
sound.setVolume(0.2);
soundSpectrum = ofSoundGetSpectrum(bands);
for (int i = 0; i < bands; i++) {
fft[i] *= decay;
if (fft[i] < soundSpectrum[i]) {
fft[i] = soundSpectrum[i];
}
}
rotate.x += rotateScene->x;
rotate.y += rotateScene->y;
rotate.z += rotateScene->z;
}
void Shape::draw(){
for (int i = 0; i < numberOfShapes; i++) {
ofSetColor(colShape[i]);
ofPushMatrix();
ofTranslate(posShape[i]);
for(int j = 0; j < bands; j++){
ofRotateXDeg(rotate.x);
ofRotateYDeg(rotate.y);
ofRotateZDeg(rotate.z);
if(drawBox){
ofFill();
ofDrawBox(fft[j] * 50);
}else{
ofNoFill();
ofDrawCircle(0, 0, fft[j] * 50);
}
}
ofPopMatrix();
}
}