Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var threshold = 30;
- var accChangeX = 0;
- var accChangeY = 0;
- var accChangeT = 0;
- var max_shake = 0;
- var notes =
- {
- C:20,
- D:40,
- E:60,
- F:80,
- G:100,
- A:120,
- B:140
- };
- function setup() {
- createCanvas(displayWidth, displayHeight);
- frameRate(2);
- }
- function draw() {
- background(255);
- checkForShake();
- }
- function checkForShake() {
- // Calculate total change in accelerationX and accelerationY
- accChangeX = abs(accelerationX - pAccelerationX);
- accChangeY = abs(accelerationY - pAccelerationY);
- accChangeT = accChangeX + accChangeY;
- // If shake
- if(accChangeT > max_shake){
- max_shake = accChangeT;
- }
- textSize(32);
- fill(0);
- stroke(0);
- // text(max_shake,displayWidth/2,200);
- // text(accChangeT,displayWidth/2,displayHeight/2);
- if(accChangeT < notes.C){
- text("C",displayWidth/2,displayHeight/2);
- music("F4");
- }
- else if(accChangeT < notes.D){
- text("D",displayWidth/2,displayHeight/2);
- music("G4");
- }
- else if(accChangeT < notes.E){
- text("E",displayWidth/2,displayHeight/2);
- music("G4#");
- }
- else if(accChangeT < notes.F){
- text("F",displayWidth/2,displayHeight/2);
- music("A5#");
- }
- else if(accChangeT < notes.G){
- text("G",displayWidth/2,displayHeight/2);
- music("C5");
- }
- else if(accChangeT < notes.A){
- text("A",displayWidth/2,displayHeight/2);
- music("C5#");
- }
- else if(accChangeT < notes.B){
- text("B",displayWidth/2,displayHeight/2);
- music("D5#");
- }
- // if (accChangeT >= threshold) {
- // }
- // // If not shake
- // else {
- // // do something
- // }
- }
- function music(note){
- var synth = new Tone.Synth().toMaster();
- synth.triggerAttackRelease(note, "8n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement