-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpictunes.pde
160 lines (142 loc) · 3.45 KB
/
pictunes.pde
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
MidiEngine midiEngine;
// image stuff here //
Renderer renderer;
ImageProcessor imageProcessor;
PImage img;
boolean imageSelected;
String imagePath;
CellGrid cellGrid;
int cellSize = 64;
// bugs //
ArrayList<Bug> bugs;
int fps = 60;
int bpm = 160;
int fp32;
int state;
GUI gui;
static ArrayList<Integer> theScale;
//String thePath = "image2.jpg";
String thePath = "oak.jpg";
void setup()
{
//selectInput("Select an image to process: ", "imageChosen");
setupImage();
//theScale = Scales.pentaMin;
theScale = Scales.aeolian;
fp32 = round(((1.0/bpm) * 60.0f * fps)/8.0f);
if(fp32 < 1)
{
print("bpm is too high\n");
exit();
}
midiEngine = new MidiEngine();
renderer = new Renderer();
gui = new GUI();
imageSelected = false;
frameRate(fps);
ellipseMode(CORNER);
noStroke();
state = STATE_PLAY;
bugs = new ArrayList<Bug>();
}
void draw()
{
switch(state)
{
case STATE_SPLASH:
background(20, 170, 100);
break;
case STATE_MENU:
background(80, 50, 100);
//renderer.renderMenuGUI(gui, imageSelected);
break;
case STATE_LOADING:
background(200, 170, 100);
break;
case STATE_PLAY:
image(img, 0, 0);
midiEngine.update();
renderer.renderCellGrid(cellGrid);
renderer.renderBugs(bugs, cellSize);
renderer.renderAnimations(cellSize);
for(int i = 0; i < bugs.size(); ++i)
{
bugs.get(i).move();
}
break;
}
}
void dispose()
{
midiEngine.silenceAll();
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}
void mouseClicked()
{
switch(state)
{
case STATE_SPLASH:
state++;
break;
case STATE_MENU:
if(imageSelected)
{
state++;
}
else
{
selectInput("Select an image to process: ", "imageChosen");
}
break;
case STATE_LOADING:
state++;
break;
case STATE_PLAY:
float x = (mouseX / cellSize);
float y = (mouseY / cellSize);
bugs.add(new Bug((new PVector(x, y)), renderer, midiEngine, cellGrid, WOOD_BASS, -1, RED, GREEN, BLUE, -1)); // bass
bugs.add(new Bug((new PVector(x, y)), renderer, midiEngine, cellGrid, RHODES, 0, GREEN, BLUE, RED, 0)); // mid
bugs.add(new Bug((new PVector(x, y)), renderer, midiEngine, cellGrid, JAZZ_GUITAR, +1, BLUE, RED, GREEN, +1)); // upper
break;
}
}
void setupImage()
{
img = loadImage(thePath);
int w = (img.width / cellSize) * cellSize; // cropping the image
int h = (img.height / cellSize) * cellSize;
//frame.setSize(w, h);
size(w, h);
imageProcessor = new ImageProcessor();
cellGrid = imageProcessor.gridifyImage(img, cellSize);
}
void imageChosen(File selection)
{
if(selection == null)
{
print("nothing selected\n");
}
else
{
print("User selected " + selection.getAbsolutePath() + "\n");
imagePath = selection.getAbsolutePath();
imageSelected = true;
}
setupImage();
state = STATE_PLAY;
}
void restartImage()
{
setupImage();
bugs.clear();
}
void keyPressed()
{
if(key == 'r' || key == 'R')
{
restartImage();
}
}