Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // midpoint perpendicular points
- // drag mouse left or right to move points
- // move wheel to adjust the distance
- // Code for Processing 3
- float x1 = 0, y1 = 0;
- float x2 = 0, y2 = 0;
- float newLen = 30;
- void setup(){
- size(500, 500);
- fill(0, 0);
- }
- void draw(){
- background(255);
- line(x1, y1, x2, y2);
- circle(x1, y1, 12);
- circle(x2, y2, 12);
- float cx = (x1+x2)/2;
- float cy = (y1+y2)/2;
- float dx = x1 - cx;
- float dy = y1 - cy;
- float len = sqrt(dx*dx + dy*dy);
- float fx1 = dy/len*newLen + cx;
- float fy1 = -dx/len*newLen + cy;
- circle(fx1, fy1, 20);
- float fx2 = -dy/len*newLen + cx;
- float fy2 = dx/len*newLen + cy;
- circle(fx2, fy2, 20);
- line(fx1, fy1, fx2, fy2);
- }
- void mouseDragged() {
- if (mouseButton == LEFT) {
- x1 = mouseX;
- y1 = mouseY;
- } else if (mouseButton == RIGHT) {
- x2 = mouseX;
- y2 = mouseY;
- }
- }
- void mouseWheel(MouseEvent event) {
- newLen += event.getCount()*5;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement