We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm trying to create a code that will play a song and have a bar created across the campus in relation to the player's position in the song. Right now I am able to create a line that moves across the screen, but I would like to be able to have a new line created every time the player moves, so it will eventually draw a bar. However, the drawing the bar part has me stumped. Would someone be able to help in how to make it so the line does not disappear?
Here is the code I have so far:
import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*;
Minim minim; AudioPlayer player;
void setup() { size( 800, 600 );
minim = new Minim( this );
player = minim.loadFile("Little Secrets.mp3");
player.play();
}
void draw() { background( 255 );
float x = map( player.position(), 0, player.length(), 0, width );
stroke( 0 );
strokeWeight (5);
line( x, 0, x, height );
}
void stop() { player.close(); minim.stop(); super.stop(); }
Answers
Two approaches:
Just stop calling
background()
-- that is clearing the screen each draw. Instead, let those lines build up. That works -- as long as nothing else on the screen needs to be refreshedYou are moving two points and drawing a line. What if instead you move two corners of a rectangle and draw the rectangle each time with rect()?