Skip to content

Instantly share code, notes, and snippets.

@chasestarr
Created April 5, 2016 19:32
Show Gist options
  • Save chasestarr/aaad4776913433a342d8cf8f8110436d to your computer and use it in GitHub Desktop.
Save chasestarr/aaad4776913433a342d8cf8f8110436d to your computer and use it in GitHub Desktop.
class Geo {
PVector location, speed, acceleration;
Geo[] theArray;
Geo(PVector loc, PVector spd, Geo[] myArray) {
location = loc;
speed = spd;
theArray = myArray;
}
void run() {
display();
move();
bounds();
mouser();
collision();
}
void display() {
triangle(location.x-10, location.y-10, location.x+20, location.y-20, location.x+20, location.y+20);
}
void move() {
location.add(speed);
}
void bounds() {
if (location.x > width || location.x < 0) {
speed.x = speed.x * -1;
move();
}
if (location.y > height || location.y < 0) {
speed.y = speed.y * -1;
move();
}
}
void mouser() {
if (mousePressed == true) {
PVector mouse = new PVector(mouseX, mouseY);
PVector direction = PVector.sub(mouse, location);
direction.normalize();
direction.mult(.5);
acceleration = direction;
speed.add(acceleration);
speed.limit(2);
location.add(speed);
}
}
public PVector getLocation() {
return location;
}
void collision() {
for (int i = 0; i < theArray.length; i++) {
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation());
if (distance < 20 && theArray[i] != this) {
speed.x = speed.x * -1;
speed.y = speed.y * -1;
move();
move();
}
}
}
}
class Inch {
PVector location, speed, acceleration;
Inch[] theArray;
Inch(PVector loc, PVector spd, Inch[] myArray) {
location = loc;
speed = spd;
theArray = myArray;
}
void run() {
display();
move();
bounds();
mouser();
collision();
}
void display() {
rect(location.x, location.y, 70,5);
}
void move() {
location.add(speed);
}
void bounds() {
if (location.x > width || location.x < 0) {
speed.x = speed.x * -1;
move();
}
if (location.y > height || location.y < 0) {
speed.y = speed.y * -1;
move();
}
}
void mouser() {
if (mousePressed == true) {
PVector mouse = new PVector(mouseX, mouseY);
PVector direction = PVector.sub(mouse, location);
direction.normalize();
direction.mult(.5);
acceleration = direction;
speed.add(acceleration);
speed.limit(2);
location.add(speed);
}
}
public PVector getLocation() {
return location;
}
void collision() {
for (int i = 0; i < theArray.length; i++) {
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation());
if (distance < 20 && theArray[i] != this) {
speed.x = speed.x * -1;
speed.y = speed.y * -1;
move();
move();
}
}
}
}
class Jelly {
PVector location, speed, acceleration;
Jelly[] theArray;
Jelly(PVector loc, PVector spd, Jelly[] myArray) {
location = loc;
acceleration = new PVector(0,0);
speed = spd;
theArray = myArray;
}
void run() {
display();
move();
bounds();
mouser();
collision();
}
void display() {
ellipse(location.x, location.y, random(20,40),random(20,40));
}
void move() {
location.add(speed);
}
void applyForce(PVector force){
int mass = 1;
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void bounds() {
if (location.x > width || location.x < 0) {
speed.x = speed.x * -1;
move();
}
if (location.y > height || location.y < 0) {
speed.y = speed.y * -1;
move();
}
}
void mouser() {
if (mousePressed == true) {
PVector mouse = new PVector(mouseX, mouseY);
PVector direction = PVector.sub(mouse, location);
direction.normalize();
direction.mult(.5);
acceleration = direction;
speed.add(acceleration);
speed.limit(5);
location.add(speed);
}
}
public PVector getLocation() {
return location;
}
void collision() {
for (int i = 0; i < theArray.length; i++) {
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation());
if (distance < 20 && theArray[i] != this) {
speed.x = speed.x * -1;
speed.y = speed.y * -1;
move();
move();
}
}
}
}
Jelly[] theJelly = new Jelly[10];
Geo[] theGeo = new Geo [10];
Inch[] theInch = new Inch [5];
//Mover ball;
PVector wind = new PVector(1, 3);
void setup() {
size(900, 500);
for (int i = 0; i < theJelly.length; i++) {
PVector location = new PVector(random(width), random(height));
PVector speed = new PVector(random(2, 5), random(1.3));
theJelly[i] = new Jelly(location, speed, theJelly);
}
for (int i = 0; i < theGeo.length; i++) {
PVector location = new PVector(random(width), random(height));
PVector speed = new PVector(random(1.3), random(2, 5));
theGeo[i] = new Geo(location, speed, theGeo);
}
for (int i = 0; i < theInch.length; i++) {
PVector location = new PVector(random(width), random(height));
PVector speed = new PVector(random(3, 7), random(2, 4));
theInch[i] = new Inch(location, speed, theInch);
}
}
void draw() {
background(255);
fill(0);
//forces
for (int i =0; i<theJelly.length; i++) {
theJelly[i].applyForce(wind);
}
//mountains p
fill(#25B723);
noStroke();
rect(0, 0, 300, height);
fill(#797879);
noStroke();
triangle(1, 150, 300, 50, 300, 200);
fill(#1A9315);
triangle(1, 150, 150, 100, 150, 180);
fill(#FFFFFF);
triangle(1, 150, 85, 122, 85, 167);
fill(#797879);
triangle(1, 350, 300, 225, 300, 400);
fill(#1A9315);
triangle(1, 350, 150, 275, 150, 375);
fill(255);
triangle(1, 350, 85, 307, 85, 364);
fill(#797879);
triangle(1, 250, 300, 50, 300, 325);
fill(#1A9315);
triangle(1, 250, 150, 130, 150, 290);
fill(255);
triangle(1, 250, 85, 183, 85, 273);
//Beach
fill(#AF5A0B);
noStroke();
rect(300, 0, 300, 500);
float y=0;
float yPos=1;
while (yPos<height) {
strokeWeight(1);
stroke(#6C360A);
point(550 + 50* noise(yPos/5), yPos);
point(540 + 50* noise(yPos/5), yPos);
point(530 + 50* noise(yPos/5), yPos);
point(520 + 50* noise(yPos/5), yPos);
point(510 + 50* noise(yPos/5), yPos);
point(500 + 50* noise(yPos/5), yPos);
point(490 + 50* noise(yPos/5), yPos);
point(480 + 50* noise(yPos/5), yPos);
point(470 + 50* noise(yPos/5), yPos);
point(460 + 50* noise(yPos/5), yPos);
point(450 + 50* noise(yPos/5), yPos);
point(440 + 50* noise(yPos/5), yPos);
point(430 + 50* noise(yPos/5), yPos);
point(420 + 50* noise(yPos/5), yPos);
point(410 + 50* noise(yPos/5), yPos);
point(400 + 50* noise(yPos/5), yPos);
point(390 + 50* noise(yPos/5), yPos);
point(380 + 50* noise(yPos/5), yPos);
point(370 + 50* noise(yPos/5), yPos);
point(360 + 50* noise(yPos/5), yPos);
point(350 + 50* noise(yPos/5), yPos);
point(340 + 50* noise(yPos/5), yPos);
point(330 + 50* noise(yPos/5), yPos);
point(320 + 50* noise(yPos/5), yPos);
point(310 + 50* noise(yPos/5), yPos);
point(300 + 50* noise(yPos/5), yPos);
yPos=yPos+1;
}
//Ocean
fill(#0BA3D8);
noStroke();
rect(600, 0, width, height);
while (y<height) {
strokeWeight(25);
stroke(#0BA3D8);
point(570+ 88* noise(y/30), y);
strokeWeight(10);
stroke(255);
point(550+ 88* noise(y/30), y);
strokeWeight(4);
point(610+ 20* noise(y/10), y);
point(622+ 35* noise(y/10), y);
point(665+ 88* noise(y/30), y);
point(725+ 176* noise(y/40), y);
y=y+1;
}
while (y<height) {
strokeWeight(2);
stroke(#6C360A);
point(450 + noise(-10, 10), y);
y=y+1;
}
strokeWeight(1);
fill(#363636);
for (int i = 0; i < theJelly.length; i++) {
theJelly[i].run();
}
fill(#1FC133);
for (int i = 0; i < theGeo.length; i++) {
theGeo[i].run();
}
fill(#21E8CC);
for (int i = 0; i < theInch.length; i++) {
theInch[i].run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment