Rotation round the Centre not 0,0
in
Programming Questions
•
7 months ago
Hey, I'm having trouble with my rotation sketch. It's part of an audio reactive one I'm making but I've just attached the basic one for now. When it rotates, it moves round the top left corner rather than them all rotating round the centre.
You may need to move your mouse around to find the points at first.
Any ideas on how to fix this?
- PFont font;
- final static byte FPS = 30;
- final static int maxDots = 700;
- final static ArrayList<PVector> dotList = new ArrayList<PVector>();
- final static ArrayList<PVector> targetPosList = new ArrayList<PVector>();
- final static ArrayList<PVector> currentPos = new ArrayList<PVector>();
- float distance;
- PVector center;
- void setup() {
- size(displayWidth, displayHeight, OPENGL);
- smooth(6);
- noCursor();
- background(255);
- frameRate(FPS);
- strokeWeight(1);
- font = createFont("Arial Bold",48);
- center = new PVector(displayWidth/2, displayHeight/2);
- stroke(0);
- }
- boolean sketchFullScreen() {
- return true;
- }
- void draw() {
- background(-1);
- textFont(font, 36);
- fill(200);
- // text(int(frameRate),20,60);
- for (int i = dotList.size()-1; i > 0; i--) {
- float a = atan2(mouseY - center.y, mouseX - center.x);
- float nx, ny;
- float sinAngle = sin(a);
- float cosAngle = cos(a);
- currentPos.get(i).x = currentPos.get(i).x + (dotList.get(i).x - targetPosList.get(i).x)*0.008;
- currentPos.get(i).y = currentPos.get(i).y + (dotList.get(i).y - targetPosList.get(i).y)*0.008;
- nx = currentPos.get(i).x * cosAngle - currentPos.get(i).y * sinAngle;
- ny = currentPos.get(i).x * sinAngle + currentPos.get(i).y * cosAngle;
- strokeWeight(5);
- stroke(255, 0, 0);
- point(nx, ny);
- }
- for (int i = dotList.size()-1; i > 0; i--) {
- if (currentPos.get(i).x > width ||
- currentPos.get(i).x < 0 ||
- currentPos.get(i).y > height ||
- currentPos.get(i).y < 0) {
- currentPos.remove(i);
- dotList.remove(i);
- targetPosList.remove(i);
- }
- }
- for (int i = 0; i < 2; i++) {
- dotList.add (new PVector( random(0, width), random(0, height) ));
- currentPos.add(new PVector( dotList.get(dotList.size()-1).x, dotList.get(dotList.size()-1).y));
- targetPosList.add (new PVector( random(width), random(height) ));
- }
- // println(dotList.size());
- }
1