shapes moving in opposite directions
in
Programming Questions
•
1 year ago
Hi all,
I've been adjusting a sketch from the Processing Handbook (32_02 two circles moving around each other.) I'm no good with maths so I've adjusted it to my own needs. What I want is to have 5 circles moving in separate directions from each other depending on the 'breathStatus' (view below.) This is a simplified sketch, the real thing will work with dynamic data coming from the web but I just want to get my head round how I can have the dots move independently from each other.
In the code below the red dots should move counter clockwise and the blue once clockwise.
I've been adjusting a sketch from the Processing Handbook (32_02 two circles moving around each other.) I'm no good with maths so I've adjusted it to my own needs. What I want is to have 5 circles moving in separate directions from each other depending on the 'breathStatus' (view below.) This is a simplified sketch, the real thing will work with dynamic data coming from the web but I just want to get my head round how I can have the dots move independently from each other.
In the code below the red dots should move counter clockwise and the blue once clockwise.
- float angle = 0; // Current angle
- float speed = 0.003; // Speed of motion
- float radius = 200.0; // Range of motion
- float sx = 1.0;
- float sy = 0.0;
- float increase = 20.0;
- String[] breathStatus = {"in", "out", "in", "out", "in"};
- void setup() {
- size(768, 768);
- noStroke();
- smooth();
- background(255);
- }
- void draw() {
- for(int i=0; i<5; i++){
- //println(increase);
- fill(255, 4);
- rect(0, 0, width, height);
- if(breathStatus[i] == "out"){
- fill(0, 0, 200, 20);
- angle += speed; // Update the angle
- }
- else{
- fill(200, 0, 0, 20);
- angle -= speed; // Update the angle
- }
- float sinval = sin(angle);
- float cosval = cos(angle);
- float x = width/2 + (cosval * radius+(increase*i));
- float y = width/2 + (sinval * radius+(increase*i));
- //fill(255);
- ellipse(x, y, 20, 20); // Draw circle
- }
- }
1