hozer

[CG]VitasLab3

Nov 25th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. class Point
  2. {
  3.   int x, y;
  4.  
  5.   Point()
  6.   {
  7.     x = 0;
  8.     y = 0;
  9.   }
  10.  
  11.   Point(int ax, int ay)
  12.   {
  13.     x = ax;
  14.     y = ay;
  15.   }
  16. }
  17. void setup() {
  18.   size(500, 500);
  19.   background(255);
  20. }
  21.  
  22. ArrayList<Point> points = new ArrayList<Point>();
  23. float X, Y, t;
  24.  
  25. void draw() {
  26.   if (points.size() == 4) {
  27.     for (t = 0; t <= 1; t += 0.0001)
  28.     {
  29.       X = (pow(1.0 - t, points.get(0).x)* points.get(0).x + pow(1.0 - t, 2)*3*t*points.get(1).x + 3*t*t*(1.0 - t)*points.get(2).x + pow(t, 3)*points.get(3).x)/(pow(1.0 - t, 3) + pow(1.0 - t, 2)*3*t + 3*t*t*(1.0 - t) + pow(t, 3));
  30.       Y = (pow(1.0 - t, 3)* points.get(0).y + pow(1.0 - t, 2)*3*t*points.get(1).y + 3*t*t*(1.0 - t)*points.get(2).y + pow(t, 3)*points.get(3).y)/(pow(1.0 - t, 3) + pow(1.0 - t, 2)*3*t + 3*t*t*(1.0 - t) + pow(t, 3));
  31.       point(X, Y);
  32.     }
  33.   } else
  34.   {
  35.     for (int i = 0; i < points.size (); i++) point(points.get(i).x, points.get(i).y);
  36.   }
  37. }
  38.  
  39.  
  40. void mousePressed() {
  41.   if (points.size() < 4)
  42.   {
  43.     if (mouseButton == LEFT)
  44.     {
  45.       points.add(new Point(mouseX, mouseY));
  46.     } else if (mouseButton == RIGHT)
  47.     {
  48.       if (points.size() > 0)
  49.         points.remove(points.size()-1);
  50.     }
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment