Skip to content

Instantly share code, notes, and snippets.

@AaronMeyers
Last active December 26, 2015 17:58
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 AaronMeyers/ffc1b52f524349c3de7f to your computer and use it in GitHub Desktop.
Save AaronMeyers/ffc1b52f524349c3de7f to your computer and use it in GitHub Desktop.
processing sketch inspired by a shot from the music video for Simian Mobile Disco's Cerulean by Jack Featherstone and Will Samuel
int lineSpacing = 15;
float circleX = 0.0;
float threshold = 250.0;
float circleSpeed;
int numFrames = 60;
boolean saveFrames = false;
void setup() {
size( 500, 500 );
frameRate( 15 );
circleSpeed = width / (float)numFrames;
}
void draw() {
background( 255 );
stroke( 0 );
circleX += circleSpeed;
if ( circleX > width )
circleX = 0;
noStroke();
fill( 0 );
// draw the circle 3 times
// once at its position and a screen width to the left and right for when its looping
ellipse( circleX, height * .25, 32.0, 32.0 );
ellipse( circleX + width, height * .25, 32.0, 32.0 );
ellipse( circleX - width, height * .25, 32.0, 32.0 );
stroke( 0 );
strokeWeight( 2 );
// draw lines, starting and finishing a safe distance offscreen
for ( int i=-100; i<width+100; i+=lineSpacing ) {
PVector linePos = new PVector( i, height );
// substitute mouseX for circleX here for interactivity!
PVector target = new PVector( circleX, height * .5 );
// move the target in certain cases for wraparound effect
if ( target.x - linePos.x > threshold )
target.x -= width;
else if ( target.x - linePos.x < -threshold )
target.x += width;
// if the x distance is within the threshold, calculate a sinusoidally attenuated angle to rotate it towards the target with
float xDist = abs( target.x - linePos.x );
float attenuation = sin( ( 1.0 - xDist / threshold ) * PI * .5 );
float angle = xDist < threshold ? ( PVector.sub( target, linePos ).heading() + radians( 90 ) ) * attenuation : 0;
// apply transforms and draw
pushMatrix();
translate( linePos.x, linePos.y );
rotate( angle );
line( 0, 0, 0, -height * .5 );
popMatrix();
}
if ( saveFrames ) {
saveFrame( "data/frames/frame_" + nf( frameCount, 3 ) + ".png" );
if ( frameCount == numFrames )
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment