Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW #20 #45

Open
chasestarr opened this issue Mar 9, 2016 · 22 comments
Open

HW #20 #45

chasestarr opened this issue Mar 9, 2016 · 22 comments
Labels

Comments

@chasestarr
Copy link
Member

Ecosystem Project

_To begin, There will be NO class March 16 or March 23. This project will be due on March 30._

In this homework we will practice applying forces. These projects will either be uploaded to MOSI's youtube channel, or be on display in the museum. Let's try to put extra polish on and show off what we can do! Refer to week 20 exercise for gravitational attraction examples. Look at these videos to get a refresher on the content we went over in the past couple weeks. Grab the mover class from here.

_Description:_
Similar to a previous homework, we will be creating an ecosystem with organisms moving around the scene. Take a look at these projects for inspiration. They use some more advanced techniques, but that's the feel you should be aiming for.

  • Incorporate all of the different forces we have learned about recently. Custom forces (wind, gravity , etc.), friction, and air/fluid resistance. Include mass to give yourself more control.
  • Create 3 different moving organisms. Each of them should move in a different style.
  • Create 3 different areas in the scene that will apply a force to the organisms. Look back at HW 18 and HW 19.
  • Add color and custom designs for each organism you create.

ch01_16

@chasestarr
Copy link
Member Author

Hi Everyone, how is this project going?
Please let me know if you have questions

@mositech/cs2015-students

@The-Space-Core
Copy link

Please tell me how to make copies appear behind it then disappear after a short while.

@chasestarr
Copy link
Member Author

I made a video explaining the object trail question, but it's not uploading to youtube!!

Don't worry about that function for tomorrow. We will go over it

@Brandonsugar
Copy link

So just don't worry about my broken homework this week? I need to know now, so I can fix it before I have to go to bed.

@chasestarr
Copy link
Member Author

@Brandonsugar

See this comment I made on your code
Brandonsugar/Repository-1#1

@chasestarr
Copy link
Member Author

https://www.youtube.com/watch?v=OssDengJICg

A whole 20 minute behemoth of a video, but it is finally uploaded to youtube! Take a look if you are interested in draw object trails.

screenshot 2016-03-30 09 37 58

@Pummelweed
Copy link

Hello @chasestarr , would you mind taking a look at my code and telling me what is wrong? I'm sure it's something obvious but I'm confused.

https://github.com/Pummelweed/AEMHW/tree/master/zsdc

The first tab is zsdc, the second is Big, third is Fast and fourth is Flying.

@chasestarr
Copy link
Member Author

Take a look here: Pummelweed/AEMHW@master...chasestarr:master
I only touched the files listed on that page. Green are the new changes. There are a couple comments at the top.

Also find the code here: https://github.com/chasestarr/AEMHW

@Pummelweed
Copy link

Thanks much!

@Brandonsugar
Copy link

Here's my code, it's been done for while but I just haven't uploaded it yet.
Tab 1:

Annoying[] bug = new Annoying[10];
Slow turtle;
Wet fish;
PVector repulsion = new PVector(0.2,0.2);
PVector wind = new PVector(0,0.06);


void setup(){
  size(1000,1000);

  for(int i=0; i<bug.length; i++){
    bug[i] = new Annoying();
  }

  fish = new Wet(width/2,height/2);
  //bug = new Annoying(600,700);
  turtle = new Slow(400,600);
}

void draw(){
  background(25,75,25);

  for(int i=0;i<bug.length; i++){
  PVector force = turtle.attract(bug[i]);
  force.div(40);
  bug[i].applyForce(force);
  bug[i].applyForce(wind);
  bug[i].display();
  bug[i].update();
  }

  //Scary Croc
  //legs
  fill(0,100,0);
  triangle(100,185,180,195,175,175);
  triangle(100,80,180,90,175,70);
  triangle(100,80,20,85,25,65);
  triangle(100,185,20,195,15,175);
  //triangle(100,195,
  //ellipse(156,195,65,20);
  //ellipse(156,80,65,20);
  //ellipse(45,195,65,20);
  //ellipse(45,80,65,20);
    fill(0,100,0);
  ellipse(100,125,70,300);
    fill(0);
  //eyes
  ellipse(115,225,5,5);
  ellipse(85,225,5,5);

  turtle.display2();
  turtle.update2();
  turtle.boundary2();
  fish.display3();
  fish.update3();
  fish.boundary3();

  //Environment
  //fill(50,150,50);



  if(turtle.location.x < 300 && turtle.location.y < 350){
   turtle.applyForce(repulsion);
   turtle.velocity.normalize();
  }
  if(fish.location.x < 300 && fish.location.y < 350){
   fish.applyForce(repulsion);
   fish.velocity.normalize();
  }
}

@Brandonsugar
Copy link

Tab 2:

class Annoying{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  float G;

  Annoying(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = 1;
    G = 50;
  }

  void display(){
    stroke(0);
    fill(0);
    ellipse(location.x,location.y,10,10);
  }

  void update(){
  velocity.add(acceleration);
  location.add(velocity);
  acceleration.mult(0);
  velocity.limit(15);
}

void applyForce(PVector force){
  acceleration.add(force);
}
}

@Brandonsugar
Copy link

Tab 3:

class Slow{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float G;
  float mass;

  Slow(int xLoc, int yLoc){
    location = new PVector(xLoc, yLoc);
    velocity = new PVector(0,0);
    acceleration = new PVector(random(-1,1),random(-1,1));
    G = 1;
    mass = random(1,6);
  }

  void display2(){
    stroke(0);
    fill(50,100,50);
    ellipse(location.x,location.y,40,50);
    fill(0,100,0);
    ellipse(location.x,location.y+28.5,12,12);
    ellipse(location.x+24,location.y+10,8,5);
    ellipse(location.x+24,location.y-10,8,5);
    ellipse(location.x-24,location.y-10,8,5);
    ellipse(location.x-24,location.y+10,8,5);
  }

   PVector attract(Annoying o){
   PVector force = PVector.sub(location, o.location);
   float distance = force.mag();
   distance = constrain(distance,5.0,25.0);

   force.normalize();
   float strength = G * mass * mass / distance * distance;
   force.mult(strength);
   return force;
 }


void applyForce(PVector force){
  acceleration.add(force);
}

  void update2(){
    location.add(velocity);
    velocity.add(acceleration);
    acceleration.mult(0);
  }

  void boundary2(){
    if(location.x > width){
      location.x = random(width);
    } else if(location.x < 0){
      location.x = random(width);
    }
    if(location.y > height){
      location.y = random(height);
    } else if(location.y < 0){
      location.y = random(height);
    }
  }
}

@Brandonsugar
Copy link

Tab 4:

class Wet{
  PVector location;
  PVector velocity;
  PVector acceleration;

  Wet(int xLoc, int yLoc){
    location = new PVector(xLoc, yLoc);
    velocity = new PVector(random(-1,1),random(-1,1));
    acceleration = new PVector(random(-2,2),random(-2,2));
  }

  void display3(){
    fill(200);
    //body
    ellipse(location.x,location.y,100,35);
    triangle(location.x+50,location.y,location.x+80,location.y+22,location.x+80,location.y-22);
    //eye
    fill(0);
    ellipse(location.x-30,location.y-5,5,5);
    stroke(0);
  }

    void applyForce(PVector force){
  acceleration.add(force);
  }

  void update3(){
    velocity.add(acceleration);
    velocity.limit(5);
    location.add(velocity);
  }
    void boundary3(){
    if(location.x > width){
      location.x = width/2;
    } else if(location.x < 0){
      location.x = width/2;
    }
    if(location.y > height){
      location.y = height/2;
    } else if(location.y < 0){
      location.y = height/2;
    }
  }
}

@Firefox99
Copy link

I'm still having trouble applying forces, but this is what I have so far.
tab 1

Jelly[] theJelly = new Jelly[10];
Geo[] theGeo = new Geo [10];
Inch[] theInch = new Inch [5];

PVector wind= new PVector(4,0);

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<theInch.length;i++){
   theJelly[i].applyForce(wind);
 }

//mountains 
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();
  }
}

tab 2

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();
      }
    }
  }
}

tab 3

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();
      }
    }
  }
}

tab 4

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();
      }
    }
  }
}

@GoHawks12
Copy link

I'm still having troubles with the processing system. But this is what I have.

Tab one

Trot fox;
Buzzing bee;
Pinching crab;
PVector repulsion;
PVector wind = new PVector(0, 0.5);


void setup(){
  size(1000, 1000);
}

void draw(){
  background(230, 152, 9);
}

Tab two

class Buzzing{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  float A;

  Buzzing(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
    A = 50;
  }

  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display2(){
    //Bee
    stroke(0);
    fill(246, 255, 71);
    ellipse(location.x, location.y, 30, 10);
    ellipse(location.x+1, location.y+1, 15, 15);
    fill(0);
    line(location.x-10, location.y-10, 20, 7);
    line(location.x-20, location.y-20, 20, 7);

  }


void update2(){
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
    velocity.limit(10);
  }

void applyForce(PVector force){
    acceleration.add(force);
  }

  void checkEdges2(){
    if(location.x > width){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }

}

Tab three

class Pinching{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float A;
  float mass;

  Pinching(int xLoc, int yLoc){
    location = new PVector(xLoc, yLoc);
    velocity = new PVector(random(-1,1),random(-1,1));
    acceleration = new PVector(random(-2,2),random(-2,2));
  }

    void display3(){
    //crab
    stroke(0);

fill(217,0,25);
ellipse(location.x,location.y,30,10);
ellipse(location.x+12,location.y+14,4,12);
ellipse(location.x-12,location.y+14,4,12);
ellipse(location.x-28,location.y-2,12,4);
ellipse(location.x+28,location.y-2,12,4);
rect(location.x+35,location.y-5,2,5);
rect(location.x+32,location.y-5,10,2);
rect(location.x+32,location.y-1,8,2);
rect(location.x+40,location.y-0.6,4,0.6);
rect(location.x+40,location.y-4.3,4,0.5);
rect(location.x-32,location.y-5,2,6);
rect(location.x-40,location.y-5,8,2);
rect(location.x-40,location.y-1,8,2);
rect(location.x-45,location.y-0.5,3,0.5);
rect(location.x-45,location.y-4.5,3,0.5);
fill(0);
ellipse(location.x-8,location.y-4,8,8);
ellipse(location.x+8,location.y-4,8,8);



  }

    void applyForce(PVector force){
  acceleration.add(force);
  }

  void update3(){
    velocity.add(acceleration);
    velocity.limit(5);
    location.add(velocity);
  }
    void boundary3(){
    if(location.x > width){
      location.x = width/2;
    } else if(location.x < 0){
      location.x = width/2;
    }
    if(location.y > height){
      location.y = height/2;
    } else if(location.y < 0){
      location.y = height/2;
    }

    }
    }

Tab four

class Trot{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  float A;

  Trot(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = 1;
    A = 50;
  }

  void display(){
    stroke(0);
    fill(0);
    ellipse(location.x,location.y,10,10);
  }

  void update(){
  velocity.add(acceleration);
  location.add(velocity);
  acceleration.mult(0);
  velocity.limit(13);
}

@Jeswing
Copy link

Jeswing commented Apr 6, 2016

Hiii, I'm having trouble applying forces to quadrants but I will post what I have. If they don't move when I initially hit run I just hit it again and they spawn in a different place.
Tab 1

Mover goat;
Fox f;
Turtle t;
PVector wind= new PVector(-1,2);
PVector liquid= new PVector(-10,2);
PVector friction= new PVector(-1,-2);

void setup(){
  size(600,600);
  t= new Turtle(random (width), 100);
  f= new Fox(300, random(height));
  goat= new Mover(90, 200);
}

void draw(){
background(0);
fill(0,150,255);
rect(0,height/200,width,height/2);
fill(37,230,104);
rect(0, height/2,width/2,height/2);
fill(237,220,145);
rect(300,height/2,width,height);
t.display();
t.update();
t.checkEdges();
f.display();
f.update();
f.checkEdges();
goat.display();
goat.update();
goat.checkEdges();


if (goat.location.y < height/2){
goat.applyForce(wind);

if (t.location.y < height/2){
goat.applyForce(wind);
}
if (f.location.y < height/2){
f.applyForce(wind);
}
if (t.location.x < width/2){
  t.applyForce(liquid);
}
}
}

Tab 2

class Fox{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;


  Fox(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display(){
    stroke(0);
    fill(209,86,86);
    ellipse(location.x,location.y,20*mass,20*mass);
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  void checkEdges(){
    if(location.x > width){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }
}

Tab 3

class Mover{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

  Mover(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display(){
    stroke(0);
    fill(150);
    ellipse(location.x,location.y,13*mass,17*mass);

  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  void checkEdges(){
    if(location.x > width){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }
}

Tab 4

class Turtle{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

  Turtle(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display(){
    stroke(0);
    fill(163,113,47);
    ellipse(location.x,location.y,20*mass,20*mass);
    fill(148,209,86);
    ellipse(location.x+12,location.y+25,13*mass,7*mass);
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  void checkEdges(){
    if(location.x > width){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }
}

@Pummelweed
Copy link

I have been working on my code that I posted for the past 2-3 hours and I finally got 2/3 of the quadrants to have forces applied to them. However, my laptop decided that it would be hilarious to crash so I lost all of my progress since I last posted; I saved some of it earlier but not since I applied the forces. This usually would not be a problem but it is getting late and I do not have time to finish it; I am posting this because I do not know what you want me to do about this.

@The-Space-Core
Copy link

Here is what I have so far
Mister Chase.

@The-Space-Core
Copy link

Mover m;
Attractor a;
Rogue r;
void setup() {
size(400, 400);
background(0);
r = new Rogue(300,300);
m = new Mover(100, 100);
a = new Attractor(200, 200);

}

void draw() {
background(0);
PVector force = a.attract(m);
m.applyForce(force);
m.update();
m.display();
a.applyForce(force);
a.edges();
a.display();
a.update();
m.edges();
}

@The-Space-Core
Copy link

class Attractor {
float mass;
PVector location;
PVector velocity;
PVector acceleration;
float G;

 Attractor(float xLoc, float yLoc) { 
   location = new PVector (xLoc, yLoc); 
   //all of your variables need values! just like location, initialize acceleration and velocity 
   // two lines below added by Mr. Chase 
   acceleration = new PVector(0,0); 
   velocity = new PVector(1,0); 
   mass = random(1, 20); 
   G = 0.4; 
 } 
PVector attract(Attractor a){

PVector force = PVector.sub(location, m.location);
float distance = force.mag();
distance = constrain(distance,-5.0,-25.0);
force.normalize();
float strength = (G * mass * m.mass) / (distance * distance);
force.mult(strength);
return force;
}
void applyForce(PVector force) {
PVector f = PVector.div(force, mass);
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}

 PVector attract(Mover m) { 
   PVector force = PVector.sub(location, m.location); 
   float distance = force.mag(); 
   distance = constrain(distance, 5.0, 25.0); 
   force.normalize(); 
   float strength = (G * mass * m.mass) / (distance * distance); 
   force.mult(strength); 
   return force; 
 } 
 //Display function added by Mr. Chase 
 void display(){ 
   ellipse(location.x, location.y, 10,10); 
 } 

 void checkEdges(){ 
   if(location.x > width){ 
     velocity.x *= -1; 
  } else if(location.x < 0){ 
     velocity.x *= -1; 
   } 

   if(location.y > height){ 
     velocity.y *= -1; 
   } else if(location.y < 0){ 
     velocity.y *= -1; 
   }

 }
 void edges(){
if(location.x > width){
    location.x = 0;
} else if(location.x < 0){
  location.x = width;
}

if(location.y > height){
  location.y = 0;
} else if(location.y < 0){
  location.y = height;
      }

}
}

@The-Space-Core
Copy link

class Mover {
PVector location;
PVector velocity;
PVector acceleration;
float mass;
ArrayList history;
float G;

 Mover(float xLoc, float yLoc) { 
   location = new PVector(xLoc, yLoc); 
   velocity = new PVector(0, 0); 
   acceleration = new PVector(1, 0); 
   mass = random(1, 6); 
   G =1;
   history = new ArrayList<PVector>(); 
 }

PVector attract(Mover o){
PVector force = PVector.sub(location, o.location);
float distance = force.mag();
distance = constrain(distance,5.0,25.0);
force.normalize();
float strength = G * mass * mass / distance * distance;
force.mult(strength);
return force;

}

 void applyForce(PVector force) { 
   PVector f = PVector.div(force, mass); 
   acceleration.add(f); 
 } 

 void display() { 
   stroke(0); 
   fill(150); 
   ellipse(location.x, location.y, 20*mass, 20*mass); 
   for (int i = 0; i< history.size(); i++) { 
     PVector current = history.get(i); 
     fill(255, 100, 100, i * 20); 
     ellipse(current.x, current.y, 20*mass, 20*mass); 
   } 
 } 

 void update() { 
   velocity.add(acceleration); 
   location.add(velocity); 
   acceleration.mult(0); 
   PVector v = new PVector(location.x, location.y); 
   history.add(v); 
   if (history.size() > 20) { 
     history.remove(0); 
   } 
 }  

 void checkEdges(){ 
   if(location.x > width){ 
     velocity.x *= -1; 
   } else if(location.x < 0){ 
     velocity.x *= -1; 
   } 

   if(location.y > height){ 
     velocity.y *= -1; 
   } else if(location.y < 0){ 
     velocity.y *= -1; 
   } 
 }
   void edges(){
if(location.x > width){
    location.x = 0;
} else if(location.x < 0){
  location.x = width;
}

if(location.y > height){
  location.y = 0;
} else if(location.y < 0){
  location.y = height;
      }

}
}

@The-Space-Core
Copy link

class Rogue {
PVector location;
PVector acceleration;
PVector velocity;
float mass;
float G;

 Rogue(float xLoc, float yLoc) { 
   location = new PVector(xLoc, yLoc); 
   velocity = new PVector(0, 0); 
   acceleration = new PVector(1, 0); 
   mass = random(1, 6); 
 }

 PVector attract(Rogue o){

PVector force = PVector.sub(location, o.location);
float distance = force.mag();
distance = constrain(distance,-5.0,-25.0);
force.normalize();
float strength = (G * mass * m.mass) / (distance * distance);
force.mult(strength);
}
void applyForce(PVector force) {
PVector f = PVector.div(force, mass);
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}
void checkEdges(){
if(location.x > width){
velocity.x *= -1;
} else if(location.x < 0){
velocity.x *= -1;
}
}
void display(){
stroke(0);
fill(255,0,0);
ellipse(location.x,location.y,45,20);
ellipse(location.x+12,location.y+14,3,12);
ellipse(location.x-12,location.y+14,3,12);
ellipse(location.x-28,location.y-1,12,3);
ellipse(location.x+28,location.y-1,12,3);
//claws
rect(location.x+32,location.y-5,1,6);
rect(location.x+32,location.y-5,8,2);
rect(location.x+32,location.y-1,8,2);
rect(location.x+40,location.y-0.5,3,0.5);
rect(location.x+40,location.y-4.5,3,0.5);
rect(location.x-32,location.y-5,1,6);
rect(location.x-40,location.y-5,8,2);
rect(location.x-40,location.y-1,8,2);
rect(location.x-43,location.y-0.5,3,0.5);
rect(location.x-43,location.y-4.5,3,0.5);
fill(0);
ellipse(location.x-6,location.y-3,6,6);
ellipse(location.x+6,location.y-3,6,6);
fill(255);
ellipse(location.x+7,location.y-3,3,3);
ellipse(location.x-5,location.y-3,3,3);
}

   void edges(){
     if(location.x > width/1){
     location.x = 0;
   } else if(location.x < 0){
     location.x = width/1;
   }
   if(location.y >= height){
   location.y = 0;
  } else if(location.y < 0){
    location.y = height/1;
  }
   }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants