Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point
- {
- int x, y;
- Point()
- {
- x = 0;
- y = 0;
- }
- Point(int ax, int ay)
- {
- x = ax;
- y = ay;
- }
- }
- void setup() {
- size(500, 500);
- background(255);
- }
- ArrayList<Point> points = new ArrayList<Point>();
- float X, Y, t;
- void draw() {
- if (points.size() == 4) {
- for (t = 0; t <= 1; t += 0.0001)
- {
- 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));
- 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));
- point(X, Y);
- }
- } else
- {
- for (int i = 0; i < points.size (); i++) point(points.get(i).x, points.get(i).y);
- }
- }
- void mousePressed() {
- if (points.size() < 4)
- {
- if (mouseButton == LEFT)
- {
- points.add(new Point(mouseX, mouseY));
- } else if (mouseButton == RIGHT)
- {
- if (points.size() > 0)
- points.remove(points.size()-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment