-
-
Save mutoo/6029705 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
int total = 100; | |
int range = 10; | |
int player = 50; | |
void setup() { | |
size(640, 480); | |
frameRate(5); | |
} | |
void draw() { | |
background(200); | |
fill(0); | |
for (int i=0; i<total; i++) | |
ellipse(width/(float)total*i, height/2, 5, 5); | |
ellipse(width/(float)total*player, height/2, 10, 10); | |
int challenger = getChallenger(player, total, range); | |
fill(255); | |
ellipse(width/(float)total*challenger, height/2, 10, 10); | |
} | |
void mousePressed() { | |
player = (int)(mouseX/(width/(float)total)); | |
} | |
int getChallenger(int player, int total, int range) { | |
int left = min(player, range); | |
int right = min(total-(player+1), range); | |
int offset = (int)random(left+right)-left; | |
offset += offset<0?0:1; | |
return player+offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment