Skip to content

Instantly share code, notes, and snippets.

@jamesbvaughan
Created March 16, 2019 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesbvaughan/f790a95e7167564e4d7c432a05ab903c to your computer and use it in GitHub Desktop.
Save jamesbvaughan/f790a95e7167564e4d7c432a05ab903c to your computer and use it in GitHub Desktop.
// ==================================================
// ====== James' line dot Perlin noise thing ========
// ========= (heavily inspired by Corbin) ===========
// ==================================================
import themidibus.*;
MidiBus myBus;
// ==================================================
// Mess with these variables
int lines = 20;
int dotsPerLine = 200;
int dotRadius = 2;
// Especially these ones
float waveSpeed = 0.004;
float lineSpread = 0.03;
float wavelength = 0.005;
float flowSpeed = -0.003;
// ==================================================
boolean isLooping = true;
int gapBetweenDots;
void setup() {
size(2400, 800);
gapBetweenDots = width / dotsPerLine;
MidiBus.list();
myBus = new MidiBus(this, "Pro [hw:1,0,0]", "Pro [hw:1,0,0]");
}
void controllerChange(int channel, int number, int value) {
switch(number) {
case 10:
waveSpeed = map(value, 0.0, 127.0, 0.0, 0.05);
break;
case 74:
lineSpread = map(value, 0.0, 127.0, 0.0, 0.5);
break;
case 71:
flowSpeed = map(value, 0.0, 127.0, 0.02, -0.02);
break;
case 76:
wavelength = map(value, 0.0, 127.0, 0.0, 0.02);
break;
case 77:
dotRadius = int(map(value, 0.0, 127.0, 0.0, 20.0));
break;
case 93:
lines = int(map(value, 0.0, 127.0, 0.0, 200.0));
break;
case 73:
dotsPerLine = int(map(value, 0.0, 127.0, 0.0, 300.0));
gapBetweenDots = (width / dotsPerLine) + 2;
break;
}
System.out.print("\033[2J");
println("Wave Speed:\t" + waveSpeed);
println("Line Spread:\t" + lineSpread);
println("Flow Speed:\t" + flowSpeed);
println("Wavelength:\t" + wavelength);
println("Dot Size:\t" + dotRadius);
println("Lines:\t\t" + lines);
println("Dots Per Line:\t" + dotsPerLine);
}
void noteOn(int channel, int pitch, int velocity) {
switch(pitch) {
case 36:
if (isLooping) {
noLoop();
isLooping = false;
} else {
loop();
isLooping = true;
}
break;
}
// Receive a noteOn
/* println(); */
/* println("Note On:"); */
/* println("--------"); */
/* println("Channel:"+channel); */
/* println("Pitch:"+pitch); */
/* println("Velocity:"+velocity); */
}
int frame = 0;
float noise;
void draw() {
background(255);
fill(0);
for (int dot = 0; dot < dotsPerLine; dot++) {
for (int line = 0; line < lines; line++) {
// This "noise" bit is the main interesting part of this program.
//
// It uses 3 dimensional Perlin noise, where the dimensions are:
// - time
// - index of line of dots being rendered
// - index of dot within a line
//
// Docs for the Perlin noise function: https://processing.org/reference/noise_.html
noise = noise(
waveSpeed * frame,
lineSpread * line,
wavelength * dot + flowSpeed * frame
);
ellipse(
dot * gapBetweenDots,
map(noise, 0, 1, 0, height),
dotRadius,
dotRadius
);
}
}
frame = frame + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment