clemp
YaBB Newbies
Offline
Posts: 3
Rotating objects around a circle
Jan 4th , 2009, 5:56pm
Hello everyone. I am new to Processing and to this forum. I appreciate the great community everyone has created. I am trying to create a program that displays objects and rotates them around the same circle. However, I want each object to be created in a random X and Y location, and rotate from there. Here is my current source code: --- Orb[] o; int numOrbs = 2; float attractRadius = 50.0; float attractX = 70.0; float attractY = 90.0; float step = 0.001; void setup() { background(240); size(485, 200); o = new Orb[numOrbs]; for (int i=0; i<numOrbs; i++){ o[i] = new Orb(random(width), random(height), 10); } } void draw() { background(240); stroke(0); for (int i=0; i<numOrbs; i++) { stroke(100, 50); line(attractX, attractY, o[i].px, o[i].py); o[i].display(); o[i].move(); } stroke(0); fill(255, 50); ellipse(attractX, attractY, attractRadius, attractRadius); // orbs are attracted to this } class Orb { float x, y; // x-coordinate, y-coordinate float radius; float angle; float px, py; float frequency = 2; // Constructor Orb(float xpos, float ypos, float rad) { x = xpos; y = ypos; radius = rad; } void display() { smooth(); noStroke(); ellipseMode(CENTER); stroke(100); ellipse(px, py, radius, radius); } void move() { px = attractX + cos(radians(angle)) * ((attractRadius + x)/2); py = attractY + sin(radians(angle)) * ((attractRadius + x)/2); angle -= frequency; println("xpos: " + px + " , ypos: " + py); } } --- The problem I am running into is that the objects all form on the same line, not in completely random locations on the screen. Can anyone offer help? Thank you!