Advertisement
ahorsewithnoname

Módulo 4

May 9th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. import static javax.swing.JOptionPane.*;
  2.  
  3. boolean overButton = false;
  4. boolean overit = false;
  5. int x, y;
  6. void setup() {
  7.   size(400,400);
  8.   rectMode(RADIUS);
  9.   textSize(20);
  10.   stroke(0);
  11.   textAlign(CENTER, CENTER);
  12.   x = 3*width/4;
  13.   y = 3*height/4;
  14. }
  15.  
  16. void draw(){
  17.   modo4();
  18. }
  19.  
  20. void modo4(){
  21.   background(255);
  22.   println(mouseY);
  23.   //isitover(mouseX,mouseY);
  24.   if(mouseX > x-90 && mouseX < x+90 && mouseY > y-20 && mouseY < y+20){
  25.     do{
  26.         x = int(random(110,width-110));
  27.         y = int(random(210,height-20));
  28.         isitover(x,y);
  29.     }while(overit == true /*&& mouseX > x-90 && mouseX < x+90 && mouseY > y-20 && mouseY < y+20*/);
  30.     //println("x: " + x + " y: " + y);
  31.   }
  32.   boton(x,y,"No");
  33.   boton(width/4,3*height/4,"Si");
  34. }
  35.  
  36. void boton(int posx, int posy, String texto){
  37.   fill(255);
  38.   if(mouseX > posx-90 && mouseX < posx+90 && mouseY > posy-20 && mouseY < posy+20){
  39.     stroke(0,0,255);
  40.     overButton = true;
  41.   }
  42.   else{
  43.     overButton = false;
  44.     stroke(0);
  45.   }
  46.   rect(posx,posy,90,20);
  47.   fill(0);
  48.   text(texto,posx,posy);
  49.   textSize(40);
  50.   text("¿Pondrías un 10\na este trabajo?",width/2,120);
  51.   textSize(20);
  52. }
  53.  
  54. void mousePressed(){
  55.   if(overButton == true) showMessageDialog(null, "Sabía que dirías que sí :D", "Info", INFORMATION_MESSAGE);
  56. }
  57.  
  58. void isitover(int x, int y){
  59.   //rect(x,y,90,20);
  60.   if((x-89 > (width/4)-90 && x-89 < (width/4)+90 && y-19 > (3*height/4)-20 && y-19 < (3*height/4)+20)||(x+89 > (width/4)-90 && x+89 < (width/4)+90 && y-19 > (3*height/4)-20 && y-19 < (3*height/4)+20)||(x+89 > (width/4)-90 && x+89 < (width/4)+90 && y+19 > (3*height/4)-20 && y+19 < (3*height/4)+20)||(x-89 > (width/4)-90 && x-89 < (width/4)+90 && y+19 > (3*height/4)-20 && y+19 < (3*height/4)+20)){
  61.     overit = true;
  62.    
  63.   }
  64.   else overit = false;
  65.   println(overit);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement