Last active
March 25, 2020 00:02
-
-
Save slambert/dc3ed7d479eafff29759462f246df9a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Steve Lambert | |
// Synare simulator v0.2 | |
// because I'm not gonna buy one on eBay. | |
// March 2018 and March 2020 | |
import processing.sound.*; | |
SinOsc sine; | |
// sound variables | |
float sineFreq = 1440; // sound frequency | |
float sineFreqPast = 1440; | |
float sineAmp = .5; // sound amplitude | |
boolean button = true; // initial state for start/stop switch | |
// setting up variables | |
float locX = 0; // location X | |
float locY = 100; // location Y | |
float xSpeed = 1; // Speed on X axis | |
float ySpeed = 4; // Speed on Y axis | |
//float gravity = 0.1; // gravity! | |
void setup() { | |
size(640,1200); | |
ellipseMode(CORNER); | |
smooth(); | |
println("sineAmp: " + sineAmp); | |
sine = new SinOsc(this); | |
sine.play(); | |
} | |
void draw() { | |
sine.freq(sineFreq); | |
sine.amp(sineAmp); | |
sineFreqPast = sineFreq; | |
background(255); | |
stroke(255); | |
fill(255,166,70); // orange! | |
// map the frequency to the height of the ball | |
// last two values are the low and high sound freq. | |
sineFreq = map(height-locY,0,height,0,2000); | |
println("locY = " + locY + "freq = " + sineFreq); | |
ySpeed = ySpeed; //+ gravity; // speed on y axis is affected by gravity, always pushing down | |
xSpeed = xSpeed *.995; // inertia | |
//// if object gets to the edge, go the other way. | |
//if ((locX > width-21) || (locX < 1)){ | |
// xSpeed = xSpeed * -1; | |
//} | |
//if ((locY > height-21) || (locY < 1)){ | |
// ySpeed = ySpeed; //* -.75; // ball bounces less each time | |
//} | |
display(); // display circle function | |
startstop(); // function for start and stop | |
locX = constrain(locX,0,width-20); | |
locY = constrain(locY,0,height-20); | |
} | |
void display() { | |
//draw the circle | |
ellipse(locX,locY,20,20); | |
} | |
void startstop(){ | |
// Increment x | |
if (button) { | |
locX = locX + xSpeed; | |
locY = locY + ySpeed; | |
} else { | |
locX = locX; | |
locY = locY; | |
} | |
} | |
void mousePressed() { | |
locX = mouseX; | |
locY = mouseY; | |
xSpeed = int(random(-3,3)); | |
ySpeed = int(map(mouseX,0,width,1,80)); | |
} | |
void keyPressed() { | |
button = !button; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment