help me do 2 things to this sketch (please!)
in
Programming Questions
•
2 years ago
hi,
i would love some help with 2 things for the attached sketch. firstly i want words inside each circle which move with the circle as its dragged around.
second i would like to render the shapes in 3D so they look a little less basic.
any code you care to add would be most welcome!
josh
- boolean over1 = false;
- boolean selected1 = false;
- boolean over2 = false;
- boolean selected2 = false;
- boolean over3 = false;
- boolean selected3 = false;
- boolean over4 = false;
- boolean selected4 = false;
- int pos1X, pos1Y, pos2X, pos2Y, pos3X, pos3Y, pos4Y, pos4X;
- int offset1X, offset1Y, offset2X, offset2Y, offset3X, offset3Y, offset4X, offset4Y;
- float radius = 25.0f;
- void setup()
- {
- size(512, 512);
- textFont(createFont("SanSerif", 12));
- pos1X = width/2-50;
- pos1Y = height/2;
- pos2X = width/2+50;
- pos2Y = height/2;
- pos3X = width/2-0;
- pos3Y = height/2;
- pos4X = width/2-100;
- pos4Y = height/2;
- smooth();
- }
- void draw()
- {
- background(0);
- strokeWeight (1.0f);
- fill(255,155);
- // see waveform.pde for more about this
- {
- // map the mouse position to the range of the pan
- float valPan = map(pos1X, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- float valGain = map(pos1Y, 0, height, 6, -48);
- // if a pan control is not available this will report zero
- ellipse (pos1X,pos1Y,radius*2.0f,radius*2.0f);
- fill (255,0,0);
- valPan = map(pos2X, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- valGain = map(pos2Y, 0, height, 6, -48);
- ellipse (pos2X,pos2Y,radius*2.0f,radius*2.0f);
- fill (155,50,20);
- valPan = map(pos3X, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- valGain = map(pos3Y, 0, height, 6, -48);
- // if a pan control is not available this will report zero
- ellipse (pos3X,pos3Y,radius*2.0f,radius*2.0f);
- fill (55,100, 150);
- valPan = map(pos4X, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- valGain = map(pos4Y, 0, height, 6, -48);
- // if a pan control is not available this will report zero
- ellipse (pos4X,pos4Y,radius*2.0f,radius*2.0f);
- }
- {
- }
- }
- void stop()
- {
- // always close Minim audio classes when you are finished with them
- super.stop();
- }
- void mouseMoved() {
- over1 = false;
- if (sqrt(sq(mouseX-pos1X)+sq(mouseY-pos1Y))<=radius) {
- over1 = true;
- }
- over2 = false;
- if (sqrt(sq(mouseX-pos2X)+sq(mouseY-pos2Y))<=radius) {
- over2 = true;
- }
- over3 = false;
- if (sqrt(sq(mouseX-pos3X)+sq(mouseY-pos3Y))<=radius) {
- over3 = true;
- }
- over4 = false;
- if (sqrt(sq(mouseX-pos4X)+sq(mouseY-pos4Y))<=radius) {
- over4 = true;
- }
- }
- void mousePressed() {
- if (over1) {
- selected1 = true;
- offset1X = pos1X-mouseX;
- offset1Y = pos1Y-mouseY;
- }
- if (over2) {
- selected2 = true;
- offset2X = pos2X-mouseX;
- offset2Y = pos2Y-mouseY;
- }
- if (over3) {
- selected3 = true;
- offset3X = pos3X-mouseX;
- offset3Y = pos3Y-mouseY;
- }
- if (over4) {
- selected4 = true;
- offset4X = pos4X-mouseX;
- offset4Y = pos4Y-mouseY;
- }
- }
- void mouseReleased() {
- selected1 = false;
- selected2 = false;
- selected3 = false;
- selected4 = false;
- }
- void mouseDragged()
- {
- if (selected1) {
- pos1X = max(0,min(mouseX+offset1X,width));
- pos1Y = max(0,min(mouseY+offset1Y,height));
- }
- if (selected2) {
- pos2X = max(0,min(mouseX+offset2X,width));
- pos2Y = max(0,min(mouseY+offset2Y,height));
- }
- if (selected3) {
- pos3X = max(0,min(mouseX+offset3X,width));
- pos3Y = max(0,min(mouseY+offset3Y,height));
- }
- if (selected4) {
- pos4X = max(0,min(mouseX+offset4X,width));
- pos4Y = max(0,min(mouseY+offset4Y,height));
- }
- }
1