// -------------------------------------------------------- private void calculPositionAndAngle() { PVector prev = new PVector(0, 0); PVector next; for (int i = 0; i < n; i++) { next = new PVector(); // Position if (i == 0) { next = new PVector(0, 0); } else { next.x = prev.x + cos(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance; next.y = prev.y + sin(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance; // Angle float a = atan2(prev.y - next.y, prev.x - next.x) - HALF_PI; angle.append(a); if (i == n - 1) lastAngle = a; } // Add position position.add(next); distance *= 1.01f; prev.set(next); } }
public void display() { location.x = (sin(radians(angle)) * r) + 5; location.y = cos(radians(angle)) * r; pushMatrix(); translate(location.x, location.y, 0); fill(220); noStroke(); sphere(size); popMatrix(); angle += speed; }
Background(float _sizeX, float _sizeY, Repulseur[] _r) { sizeX = _sizeX; sizeY = _sizeY; repulseurPoint = _r; for (int i = 0; i < 20000; i++) { PVector p = new PVector(); p.x = random(sizeX); p.y = random(sizeY); points.add(p); } }
public void mousePressed() { if (game.screen == 1) { // see above velocity = PVector.fromAngle( radians( (float) angledegrees)); // uses PVector to make a vector from the angle of the shooter if (canfire == true) { // checks if user is able to fire (if ball is active) game.shooterlist[0] = game.shooterlist[1]; // sets active ball to the next ball game.shooterlist[0].setVelocity( velocity.x, velocity.y); // adjusts velocity for ball depending on type game.shooterlist[1] = new Ball( game .createNewBall()); // creates new ball with random type as generated by the // createNewBall function canfire = false; // disables firing while ball is active } } if (game.screen == 0) { // see above if (button.pressed()) { // checks if button is pressed game.gotoGame(); // loads game } } if (game.screen == 2) { if (button.pressed()) { game.reset(); // resets game } } }
// ------------------------------------------------------ public PVector updatedPointPosition(float _x, float _y) { p = new PVector(_x, _y); distance = dist(p.x, p.y, x, y); if (distance < radius) { angle = atan2(p.y - y, p.x - x); force = map(distance, 0, radius, maxForce, 0); p.x += cos(angle) * force; p.y += sin(angle) * force; } return p; }
// ------------------------------------------- public void calcul() { // UP - left side for (int i = 0; i < position.size(); i++) { PVector p = position.get(i); PVector pp = new PVector(); pp.x = cos(angles.get(i) + HALF_PI) * radius[i] + p.x + initPosition.x; pp.y = sin(angles.get(i) + HALF_PI) * radius[i] + p.y + initPosition.y; pointForm.add(pp); } // DOWN - right side for (int i = position.size() - 1; i >= 0; i--) { PVector p = position.get(i); PVector pp = new PVector(); pp.x = cos(angles.get(i) - HALF_PI) * radius[i] + p.x + initPosition.x; pp.y = sin(angles.get(i) - HALF_PI) * radius[i] + p.y + initPosition.y; pointForm.add(pp); } }
public void motion() { xMove += random(-6, 6); theta = radians(xMove); loc.x += cos(theta); lifespan -= 0.29f; }
FontAgent(PVector l) { loc = l.get(); // acc = new PVector (0, 0.1); }
// -------------------------------------------------------- private void calculPositionAndAngle() { PVector prev = new PVector(0, 0); PVector next = new PVector(0, 0); float lastAngle = 0, randomAngle, tempAmplitude; // Position for (int i = 0; i < n; i++) { if (i == 0) { position.add(next); } else { tempAmplitude = amplitude; next = new PVector(0, 0); do { randomAngle = random(-tempAmplitude, tempAmplitude) + lastAngle; next.x = prev.x + cos(randomAngle + beginAngle) * distance; next.y = prev.y + sin(randomAngle + beginAngle) * distance; tempAmplitude += radians(1); } while (outside(next, border)); // Angle float a = atan2(prev.y - next.y, prev.x - next.x); lastAngle = randomAngle; // Add position position.add(next); // Set prev to next prev.set(next); } } // Angle for (int i = 0; i < n; i++) { float a; if (i == 0) { // a = atan2(position.get(0).y-position.get(1).y,position.get(0).x-position.get(1).x); angle.append(beginAngle - PI); } else if (i == n - 1) { a = atan2( position.get(n - 2).y - position.get(n - 1).y, position.get(n - 2).x - position.get(n - 1).x); angle.append(a); } else { a = atan2( position.get(i - 1).y - position.get(i + 1).y, position.get(i - 1).x - position.get(i + 1).x); angle.append(a); } } }