Created
November 5, 2014 09:27
-
-
Save denkspuren/312e594c954ed9fd4def to your computer and use it in GitHub Desktop.
Snake goes OO
This file contains 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
class Position { | |
int x; | |
int y; | |
Position(int x, int y) { // new Position(3,0); | |
this.x = x; | |
this.y = y; | |
} | |
void display(int radius) { | |
ellipse(x,y,2*radius,2*radius); | |
} | |
} | |
Position[] position = new Position[16]; | |
// int[] xPosition = new int[16]; | |
// int[] yPosition = new int[16]; | |
void setup() { | |
size(400,300); | |
noStroke(); | |
for(int i=0; i<position.length; i++) { | |
position[i] = new Position(mouseX, mouseY); | |
// xPosition[i] = mouseX; | |
// yPosition[i] = mouseY; | |
} | |
} | |
void draw() { | |
background(color(74,92,102)); | |
if (dist(pmouseX,pmouseY,mouseX,mouseY) > 1) { | |
for(int i=position.length-1; i>=1; i--) { | |
position[i] = position[i-1]; | |
// xPosition[i] = xPosition[i-1]; | |
// yPosition[i] = yPosition[i-1]; | |
} | |
position[0] = new Position(mouseX,mouseY); | |
// xPosition[0] = mouseX; | |
// yPosition[0] = mouseY; | |
} | |
for(int i=0; i<position.length; i++) { | |
fill(color(128,186,36,i*20)); | |
position[i].display(20); | |
// ellipse(xPosition[i], yPosition[i], 40, 40); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment