Skip to content

Instantly share code, notes, and snippets.

@slambert
Created April 14, 2020 21:46
Show Gist options
  • Save slambert/837567e104635a88dc3db9401ff51cbe to your computer and use it in GitHub Desktop.
Save slambert/837567e104635a88dc3db9401ff51cbe to your computer and use it in GitHub Desktop.
Get your own fonts.
// Steve Lambert 2020-04-14
// Modulo sound
// v0.1
import processing.sound.*;
SinOsc sine;
int interval; // how often changes
int xPos; // circle location
int yPos;
int circleW = 50; // circle width
int stage = 0;
// sound variables
float sineFreq = 220; // sound frequency
float sineAmp = .75; // sound amplitude
// FONT SETUP
PFont LeagueGothicBig;
PFont LeagueGothicSmall;
int fSizeBig = 34; // size of big font
int fSizeSml = 24; // size of small font
int textHeight = height/2;
String line1 = "PRESS ENTER TO START";
void setup() {
frameRate(8);
size(600,600);
smooth();
noStroke();
background(255);
LeagueGothicBig = createFont("LeagueGothic-Regular", fSizeBig, true);
LeagueGothicSmall = createFont("LeagueGothic-Regular", fSizeSml, true);
sine = new SinOsc(this);
sine.play();
} // end setup
void draw(){
background(255);
if (stage == 0){
startScreen();
} else if (stage == 1) {
moduloSketch();
}
}
void keyReleased() {
if (key == RETURN || key == ENTER) {
println("Hit Return stage 0");
if (stage == 0){ // if on the start screen
stage = 1; // advance to the next stage
} else { // otherwise do nothing
} // end else
} // end CODED
else if (key == '0') { // if it's not coded, and it's 0
stage = 0; // reset
}
}
void startScreen() {
sine.amp(0); // turn off sound
fill(255);
background(255, 0, 0);
textAlign(CENTER, CENTER);
textFont(LeagueGothicBig);
//textLeading(80); // Set leading to 10
text(line1, width/2, height/2);
}
void moduloSketch() {
sine.freq(sineFreq);
ellipseMode(TOP);
if (interval % 16 == 0) {
sine.freq(220);
fill(51);
ellipse(xPos,yPos+(circleW*1),circleW,circleW);
sine.amp(sineAmp);
} else if (interval % 4 == 0) {
sine.freq(440);
fill(200,10,10);
ellipse(xPos,yPos+(circleW*2),circleW,circleW);
sine.amp(sineAmp);
} else if (interval % 1.5 == 0) {
sine.freq(random(125,2000));
fill(10,10,random(0,255));
ellipse(xPos+200,yPos+(circleW*2),circleW,circleW);
sine.amp(sineAmp);
} else {
sine.amp(0);
}
interval = interval+ 1; // count each loop!
println("interval: "+interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment