We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do you use the constrain() function to constrain in circle shape instead of rect?
Do note, that by using constrain() within a circle, your just making it harder. The best way to constrain something in a circle would be to use PVector. Here is an example:
int mouseDiam = 30; int circleDiam = 200; void setup() { size(500, 500); } void draw() { background(200); PVector dist = new PVector(mouseX, mouseY); PVector origin = new PVector(width/2, height/2); dist.sub(origin); dist.limit(circleDiam/2 - mouseDiam/2); translate(width/2, height/2); ellipseMode(CENTER); ellipse(0, 0, circleDiam, circleDiam); ellipse(dist.x, dist.y, mouseDiam, mouseDiam); }
It is a mouthful, but this is one of the easiest ways to "constrain" a point in a circle.
-- MenteCode
Answers
Do note, that by using constrain() within a circle, your just making it harder. The best way to constrain something in a circle would be to use PVector. Here is an example:
It is a mouthful, but this is one of the easiest ways to "constrain" a point in a circle.
-- MenteCode