change 1 litle thing
in
Programming Questions
•
2 years ago
Now, the closer you are to the ellipse the faster it rotates, what i want is that the closer you are the slower it goes.
- float angle = 0.0;
float scalar = 20;
float dir = 1;
float speed = 0.01;
float posX;
float posY;
float maxDist;
void setup() {
size(600, 600);
maxDist = dist(0, 0, width, height);
posX = width/2;
posY = height/2;
}
void draw() {
background(255);
float x = posX + cos(angle)*scalar;
float y = posY + sin(angle)*scalar;
ellipse(x, y, 20, 20);
float distance = dist(mouseX, mouseY, posX, posY);
speed = map(distance, 0, maxDist, 0.2, -0.2);
angle += speed*dir;
}
void mousePressed(){
dir = -dir;
}
void mouseDragged() {
posX = mouseX;
posY = mouseY;
}
1
