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 # 14 #32

Open
chasestarr opened this issue Jan 20, 2016 · 9 comments
Open

HW # 14 #32

chasestarr opened this issue Jan 20, 2016 · 9 comments
Labels

Comments

@chasestarr
Copy link
Member

In this homework we will get some more practice with vectors. Look back on your homework from week13 for help.

  • Develop a set of rules for simulating the real-world behavior of a creature, such as a nervous fly, swimming fish, hopping bunny, slithering snake, etc. Can you control the object’s motion by only manipulating the acceleration? Try to give the creature a personality through its behavior (rather than through its visual design).

Please paste your code as a comment on this post

nature of code

@chasestarr
Copy link
Member Author

Take a look at Example 1.9 from The Nature of Code Chapter 1 which talks about randomness within acceleration vectors.

Example 1.9: Motion 101 (velocity and random acceleration)

  void update() {

//The random2D() function will give us a PVector of length 1 pointing in a random direction.
    acceleration = PVector.random2D();

    velocity.add(acceleration);
    velocity.limit(topspeed);
    location.add(velocity);
  }

Because the random vector is a normalized one, we can try scaling it:

  • scaling the acceleration to a constant value
acceleration = PVector.random2D();
//Constant
acceleration.mult(0.5);
  • scaling the acceleration to a random value
acceleration = PVector.random2D();
//Random
acceleration.mult(random(2));

While this may seem like an obvious point, it’s crucial to understand that acceleration does not merely refer to the speeding up or slowing down of a moving object, but rather any change in velocity in either magnitude or direction. Acceleration is used to steer an object, and we’ll see this again and again in future chapters as we begin to program objects that make decisions about how to move about the screen.

@chasestarr
Copy link
Member Author

Take a look at the examples for help.

@GoHawks12
Copy link

Tab one


Mover armadillo;

void setup(){
  size(500,500);
  background(255);
  armadillo = new Mover();
}

void draw(){
  PVector mouse = new PVector(mouseX, mouseY);
  PVector center = new PVector(width/2, height/2);

 mouse.sub(center);

  float magnitude = mouse.mag();

  rect(0, 0, magnitude, 50);
  translate(center.x, center.y);
  line(0, 0, mouse.x, mouse.y);

  background(255);
  armadillo.display();
  armadillo.update();
  armadillo.checkEdges();
}

@GoHawks12
Copy link

Tab two

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

  Mover(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(random(-2.5,2.5),random(-2.5,2.5));
    acceleration = new PVector(0.015,-0.015);
  }

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

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

  void checkEdges(){
    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

Sorry mister Chase
I forgot a lot of the stuff because I did not do the homework until the last day.
I am not asking for a total recap, but the information you have given me does not seem too work on processing. It always says something is done improperly( for instance it says the size is the cause of the problems most of the time).

@chasestarr
Copy link
Member Author

Try going through example 1.9 at this page: http://natureofcode.com/book/chapter-1-vectors/
The code from that section will go in your Mover class and then in the update function. You may need to look at the rest of that web page for more information 😄

@The-Space-Core
Copy link

Helico heli;

void setup(){
heli = new Helico();
size(400,400);

}
void draw(){
background(255);
heli.edges();
heli.display();
heli.update();
}

@The-Space-Core
Copy link

class Helico{
PVector location;
PVector velocity;
PVector acceleration;

Helico(){
location = new PVector(random(width),random(height));
velocity = new PVector(random(-2,2),random(-2,2));
acceleration = new PVector(0.01,-0.01);
}

void display(){
stroke(0);
fill(200,200,0);
rect(location.x,location.y,9,65);
fill(0);
rect(location.x,location.y,9,10);
fill(255);
ellipse(location.x+4,location.y+27,30,30);

}

void update(){
acceleration = PVector.random2D();
acceleration.mult(random(2));

velocity.add(acceleration);
velocity.limit(2);
location.add(velocity);
}

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

}
}

@chasestarr chasestarr mentioned this issue Jan 27, 2016
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

4 participants