fundamentals of programming sm1204 semester a 2012
TRANSCRIPT
![Page 1: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/1.jpg)
FUNDAMENTALSOF PROGRAMMING
SM1204 SEMESTER A 2012
![Page 2: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/2.jpg)
ASSIGNMENT 3
DUE DATE 21 DEC 2012
COLLECTION VIA ACS
![Page 3: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/3.jpg)
REQUIREMENTS
oCreate your own music visualization (20%)oSelect your audio / musicoDesign your visualization
oUse of Minim audio library (30%)
oProgram complexity (20%)
oCreative graphics (30%)
![Page 4: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/4.jpg)
EXAMPLE
http://www.youtube.com/watch?v=KW5D9IVfb1k&feature=related
![Page 5: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/5.jpg)
EXAMPLE
http://www.youtube.com/watch?v=1JkN3Uwgqi4&feature=related
![Page 6: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/6.jpg)
EXAMPLE
http://www.youtube.com/watch?v=0AVyhytUy7k&feature=related
![Page 7: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/7.jpg)
SAMPLE PROGRAM
![Page 8: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/8.jpg)
SAMPLE PROGRAM
Import library
Define player and beat detector objects
import ddf.minim.*;import ddf.minim.analysis.*;
Minim minim;AudioPlayer player;BeatDetect beat;int n = 5;float[][] a = new float[n][n];
![Page 9: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/9.jpg)
SAMPLE PROGRAMCreate objects & Initialize array elementsvoid setup() { size(400, 400); minim = new Minim(this); player = minim.loadFile("test2.mp3"); beat = new BeatDetect( player.bufferSize(), player.sampleRate() ); player.play();
// initialize item size for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { a[i][j] = 40; } }}
![Page 10: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/10.jpg)
SAMPLE PROGRAMBeat detection and renderingvoid draw() { beat.detect(player.mix); background(0);
strokeWeight(4); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { // enlarge corresponding circle if onset if (beat.isOnset(i*5+j)) { a[i][j] = 80; }
float s = a[i][j]; float c = map(s, 40, 80, 200, 255); noFill(); stroke(c); ellipse(i*80+40, j*80+40, s, s); fill(c); noStroke(); ellipse(i*80+40, j*80+40, s / 2, s / 2); // decrease circle sizes if (a[i][j] > 40) { a[i][j] *= 0.95; } } }}
![Page 11: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/11.jpg)
SAMPLE PROGRAM
Do not forget to add the stop( ) function
void stop() { player.close(); minim.stop(); super.stop();}
![Page 12: FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649f4e5503460f94c6f975/html5/thumbnails/12.jpg)
USEFUL FUNCTIONS & REFERENCES
omap (value, low1, high1, low2, high2)
oRe-maps a number from one range to another
oconstrain(value, min, max)
oConstrains a value to not exceed a maximum and minimum value.
oabs(value)
oCalculates the absolute value (always position) of a number.