Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Constrain Example (c)2015 Giles Cartmel */
- int borderX, borderY;
- void setup() {
- size(800,600);
- borderX = width/5;
- borderY = height/5;
- }
- void draw() {
- background(0);
- int x1, y1, x2, y2;
- x1 = borderX;
- y1 = borderY;
- x2 = width-borderX;
- y2 = height-borderY;
- // draw a rectangle based on 10% border of the canvas
- rectMode(CORNER);
- fill(20);
- stroke(80);
- rect(x1,y1,x2-x1,y2-y1);
- // draw an ellipse at the mouse position
- // constraining it's centre to within the rectangle
- ellipseMode(RADIUS);
- fill(128,255,128,128);
- stroke(255);
- ellipse(constrain(mouseX, x1, x2)
- ,constrain(mouseY, y1, y2)
- ,borderX/5
- ,borderY/5
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement