» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » Over rect a l envers : http://codelab.fr/4487 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Over rect a l envers |
imdidi — 2013-09-12 18:26:08 |
bonjour tous le monde int rectX, rectY; // Position of square button int circleX, circleY; // Position of circle button int rectSize = 90; // Diameter of rect int circleSize = 93; // Diameter of circle color rectColor, circleColor, baseColor; color rectHighlight, circleHighlight; color currentColor; boolean rectOver = false; boolean circleOver = false; void setup() { size(640, 360); rectColor = color(0); rectHighlight = color(51); circleColor = color(255); circleHighlight = color(204); baseColor = color(102); currentColor = baseColor; circleX = width/2+circleSize/2+10; circleY = height/2; rectX = width/2-rectSize-10; rectY = height/2-rectSize/2; ellipseMode(CENTER); } void draw() { update(mouseX, mouseY); background(currentColor); if (rectOver) { fill(rectHighlight); } else { fill(rectColor); } stroke(255); rect(rectX, rectY, rectSize, rectSize); if (circleOver) { fill(circleHighlight); } else { fill(circleColor); } stroke(0); ellipse(circleX, circleY, circleSize, circleSize); } void update(int x, int y) { if ( overCircle(circleX, circleY, circleSize) ) { circleOver = true; rectOver = false; } else if ( overRect(rectX, rectY, rectSize, rectSize) ) { rectOver = true; circleOver = false; } else { circleOver = rectOver = false; } } void mousePressed() { if (circleOver) { currentColor = circleColor; } if (rectOver) { currentColor = rectColor; } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } boolean overCircle(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } merci d avance |
Seb — 2013-09-13 09:17:19 |
Pardon mais j'ai un peu du mal à saisir ton problème, tu pourrais être plus clair ? |
Olivier — 2013-09-13 13:59:45 |
Oui... Code (P5) :boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return false; } else { return true; } } Mais je ne suis vraiment pas sûr de répondre à ton pb... :/ |
imdidi — 2013-09-13 17:40:14 |
salut a tous |