Advertisement
lumpynose

codingMath05a

May 10th, 2015
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. float angle;
  2. float arrowX, arrowY, dx, dy;
  3.  
  4. PShape arrow;
  5.  
  6. void setup() {
  7.   size(400, 400, P2D);
  8.  
  9.   arrowX = width / 2;
  10.   arrowY = height / 2;
  11.  
  12.   angle = 0;
  13.  
  14.   arrow = createShape();
  15.  
  16.   arrow.beginShape();
  17.   arrow.fill(0);
  18.   arrow.noStroke();
  19.   arrow.vertex(1,0);
  20.   arrow.vertex(0,1);
  21.   arrow.vertex(3,0);
  22.   arrow.vertex(0,-1);
  23.   arrow.endShape(CLOSE);
  24. }
  25.  
  26. void draw() {
  27.   background(255); // clear canvas
  28.  
  29.   dx = mouseX - arrowX;
  30.   dy = mouseY - arrowY;
  31.  
  32.   angle = atan2(dy, dx);
  33.  
  34.   println(mouseX, mouseY, dx, dy, angle);
  35.  
  36.   translate(arrowX, arrowY);
  37.   rotate(angle);
  38.  
  39.   shape(arrow, 0, 0, 20, 20);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement