KaanKarabay_d_1

 

I was trying to find a solution which mimics the movement  from this image. Actually this is a rigid object. 🙂

Use the code with processing

/**

"
* Acceleration with Vectors
* by Daniel Shiffman. "

Örneği baz alınarak yapılmıştır.
Arraylist örneğin içine gömülmüştür.

*/

// A Mover object
ArrayList<Mover> mover;
int maxR = 250; // max çap
int minR = 20; // min çap
int farkR = 20; // çaplar farkı
int n = ((maxR-minR)/farkR)+1;

void setup() {
size(600,600);
mover = new ArrayList<Mover>();
for ( int i=minR; i<= maxR; i=i+farkR) {
mover.add(new Mover(i));

}

}

void draw() {
background(0);
for (int i =0; i < n; i++) {
Mover m = mover.get(i);
// Update the location
m.update();
// Display the Mover
m.display();
}
}

/**
Mover class ı acceleration içinde yazılmıştı.
bu class tek bir circle için bağımsız çalışıyordu.
buna radius kontrolünü ekledim
Bir de acceleration ı radius a bağladım ki çemberler farklı hızlanmalarda haraket etsinler

*/
class Mover {

// The Mover tracks location, velocity, and acceleration
PVector location;
PVector velocity;
PVector acceleration;
// The Mover's maximum speed
float topspeed;
float rad;
float x;

Mover(float rad) {
// Start in the center
location = new PVector(width/2, height/2);
velocity = new PVector(0, 0);
topspeed =2;
x = rad;
}

void update() {

// Compute a vector that points from location to mouse
PVector mouse = new PVector(mouseX, mouseY);
PVector acceleration = PVector.sub(mouse, location);
// Set magnitude of acceleration
acceleration.setMag(20/x);
// Velocity changes according to acceleration
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
}

void display() {
stroke(255);
strokeWeight(2);
noFill();
// if (velocity.lenght =0 ) {
// ellipse(mouseX, mouseY, x, x);
// } else {

ellipse(location.x, location.y, x, x);
// }
}
}

 

 

 


 

 

[iframe width=”628″ height=”680″ scrolling=”no” frameborder=”0″ src=”http://www.openprocessing.org/sketch/194098/embed/?width=600&height=600&border=true”][/iframe]

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.