Created
February 17, 2019 10:23
-
-
Save timcowlishaw/70f982e43732c62746570916207b981e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
Minim minim; | |
AudioPlayer song; | |
BeatDetect beat; | |
float bottomSpeed = random(1.0); | |
float topSpeed = random(1.0); | |
int t = 0; | |
color[] COLORS = { | |
color(255, 0, 0), | |
color(255, 255, 0), | |
color(0, 255, 0), | |
color(0, 255, 255), | |
color(0, 0, 255), | |
color(255, 0, 255) | |
}; | |
boolean leftShape = true; | |
int leftOpacity = 0; | |
int leftTopPos = 0; | |
int leftBottomPos = 0; | |
color leftCurrentColor = COLORS[(int) random(COLORS.length)]; | |
int rightOpacity = 0; | |
int rightTopPos = 0; | |
int rightBottomPos = 0; | |
color rightCurrentColor = COLORS[(int) random(COLORS.length)]; | |
void setup() { | |
fullScreen(); | |
minim = new Minim(this); | |
song = minim.loadFile("/Users/timco/Music/The Necks - Body/The Necks - Body - 01 Body.mp3", 2048); | |
song.play(); | |
beat = new BeatDetect(); | |
} | |
void draw() { | |
beat.detect(song.mix); | |
if(beat.isOnset()) { | |
if(leftShape) { | |
leftBottomPos = floor(width /2 + sin(bottomSpeed*t) * width / 2); | |
leftTopPos = floor(width / 2 + sin(topSpeed*t) * width / 2); | |
leftCurrentColor = COLORS[(int) random(COLORS.length)]; | |
leftOpacity = 255; | |
} else { | |
rightBottomPos = floor(width /2 + cos(bottomSpeed*t) * width / 2); | |
rightTopPos = floor(width / 2 + cos(topSpeed*t) * width / 2); | |
rightCurrentColor = COLORS[(int) random(COLORS.length)]; | |
rightOpacity = 255; | |
} | |
leftShape = !leftShape; | |
} | |
background(0); | |
fill(leftCurrentColor, leftOpacity); | |
beginShape(); | |
vertex(0, 0); | |
vertex(leftTopPos, 0); | |
vertex(leftBottomPos, height); | |
vertex(0, height); | |
endShape(CLOSE); | |
fill(rightCurrentColor, rightOpacity); | |
beginShape(); | |
vertex(rightTopPos, 0); | |
vertex(width, 0); | |
vertex(width, height); | |
vertex(rightBottomPos, height); | |
endShape(CLOSE); | |
t++; | |
leftOpacity *= 0.95; | |
rightOpacity *= 0.95; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment