adding some working code and controlP5 button to the new window
Hello.
I've done something like this (which works great),
where you can move top points of the triangle:
- class Point {
- public float x, y;
- Point(float x, float y){ this.x = x; this.y = y; }
- }
- Point p1, p2, p3;
- int iter;
- int over;
- Boolean drag;
- float zoom;
- void setup() {
- size(555, 555, P2D);
- smooth();
- iter = 2;
- over = 0;
- drag = false;
- zoom = 1.0;
- p1 = new Point( 100.0*zoom, 400.0*zoom );
- p2 = new Point( 250.0*zoom, 150.0*zoom );
- p3 = new Point( 400.0*zoom, 400.0*zoom );
- }
- void mouseDragged() {
- if( over == 0 ) return;
- if( over == 1 ) p1 = new Point(mouseX*(1.0/zoom), mouseY*(1.0/zoom)); // dolny lewy
- if( over == 2 ) p2 = new Point(mouseX*(1.0/zoom), mouseY*(1.0/zoom)); // górny
- if( over == 3 ) p3 = new Point(mouseX*(1.0/zoom), mouseY*(1.0/zoom)); // dolny prawy
- }
- void mousePressed() {
- if( over > 0 )drag = true;
- }
- void mouseReleased() {
- drag = false;
- }
- void updateHover() {
- if( drag ) return;
- over = 0;
- if( overCircle(p1.x, p1.y, 10) ) over = 1;
- if( overCircle(p2.x, p2.y, 10) ) over = 2;
- if( overCircle(p3.x, p3.y, 10) ) over = 3;
- }
- boolean overCircle(float x, float y, int diameter) {
- float disX = (x*zoom) - mouseX;
- float disY = (y*zoom) - mouseY;
- if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) return true;
- else return false;
- }
- void draw() {
- updateHover();
- background(#FFFAFA);
- beginShape();
- fill((color)103,105,168); // -----------------------------------------------> kolor Trójkąta Sierpińskiego...
- noStroke();
- vertex(p1.x, p1.y);
- vertex(p2.x, p2.y);
- vertex(p3.x, p3.y);
- endShape();
- // kolor `punktów kontrolnych`
- if( over == 1 ){ fill(#00FF00); stroke(#00FF00); } else{ fill((color)103,105,168); stroke((color)103,105,168); }
- ellipse(p1.x, p1.y, 7, 7);
- if( over == 2 ){ fill(#00FF00); stroke(#00FF00); } else{ fill(#000000); stroke(#000000); }
- ellipse(p2.x, p2.y, 7, 7);
- if( over == 3 ){ fill(#00FF00); stroke(#00FF00); } else{ fill(#000000); stroke(#000000); }
- ellipse(p3.x, p3.y, 7, 7);
- }
And now appears my problem. I made another application with a new window.
This is a very similar application (almost the same...) and has a bit more than 70 lines, but with classes takes almost 400 lines. My class (Point) takes only a few lines, class ExtraWindow (made by someone else) is much bigger/longer. Still it's to big to post here because of the limits, so I pasted the code into the following link: http://wklej.org/id/369642/txt/ // of course it's safe, after opening the code appears and it's very easy to copy
And now my problems/questions to the linked code above...
1) In a new window I can't move 3 top points. How can I solve it?
2) How can I implement controlP5 button, but in a new window...?