Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- point2d P0, P1, P2, P3, P4,P5;
- int radius = 5;
- int sensitive = 8;
- int dragged = -1;
- int activePoint = -1;
- point2d[] points;
- class point2d {
- float x, y;
- point2d(float x, float y) {
- this.x = x;
- this.y = y;
- }
- }
- void setup(){
- size(800,600);
- points = new point2d[6];
- P0 = points [0] = new point2d(100,400);
- P1 = points [1] = new point2d(150,250);
- P2 = points [2] = new point2d(270,200);
- P3 = points [3] = new point2d(400,250);
- P4 = points [4] = new point2d(450,350);
- P5 = points [5] = new point2d(470,400);
- }
- int getActivePoint( point2d[] t, int size, int sens, int mousex, int mousey ) {
- point2d M = new point2d( mousex, mousey );
- for ( int i = 0; i < size; i++ ) {
- if ( pow(M.x-t[i].x, 2)+pow(M.y-t[i].y,2) < pow(sens, 2 ) )
- return i;
- }
- return -1;
- }
- void draw(){
- stroke(255,0,0);
- strokeWeight(10);
- beginShape(POINTS);
- vertex(P0.x, P0.y);
- vertex(P1.x, P1.y);
- vertex(P2.x, P2.y);
- vertex(P3.x, P3.y);
- vertex(P4.x, P4.y);
- vertex(P5.x, P5.y);
- endShape();
- strokeWeight(2);
- noFill();
- beginShape();
- vertex(P0.x, P0.y);
- vertex(P1.x, P1.y);
- vertex(P2.x, P2.y);
- vertex(P3.x, P3.y);
- vertex(P4.x, P4.y);
- vertex(P5.x, P5.y);
- endShape();
- beginShape();
- for(float t=0 ; t<=1 ; t+= 0.01){
- vertex( pow(1-t,5)*P0.x + 5*t*pow(1-t,4)*P1.x+ 10*t*t*pow(1-t,3)*P2.x+ 10*t*t*t*pow(1-t,2)*P3.x+ 5*t*t*t*t*pow(1-t,1)*P4.x + t*t*t*t*t*P5.x,
- pow(1-t,5)*P0.y + 5*t*pow(1-t,4)*P1.y+ 10*t*t*pow(1-t,3)*P2.y+ 10*t*t*t*pow(1-t,2)*P3.y+ 5*t*t*t*t*pow(1-t,1)*P4.y + t*t*t*t*t*P5.y );
- }
- endShape();
- }
- void mousePressed() {
- activePoint = getActivePoint( points, 6, sensitive, mouseX, mouseY );
- if (activePoint != -1 ) {
- dragged = activePoint;
- }
- }
- void mouseDragged() {
- if(dragged!=-1) {
- points[dragged].x = mouseX;
- points[dragged].y = mouseY;
- }
- }
- void mouseReleased() {
- dragged = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement