Advertisement
Guest User

menu test

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. int num = 0;
  2. int s = 20;
  3. int y = 1;
  4.  
  5. void setup() {
  6.   size(640, 480);
  7.   background(204);
  8.   rectMode(CENTER);
  9.   stroke(0);
  10.   line(width/2, 0, width/2, height);
  11.   line(0, height/2, width, height/2);
  12.  
  13. }
  14.  
  15. void mouseClicked() {
  16.   num++;
  17.  
  18.   while ((y*s*1.5) < width) {
  19.     y++;
  20.   }
  21. }
  22.  
  23. void draw() {
  24.   background(204);
  25.   stroke (0);
  26.   line(width/2, 0, width/2, height);
  27.   line(0, height/2, width, height/2);
  28.   fill(0);
  29.   textAlign(CENTER);
  30.   textSize(14);
  31.   text("num_w = " + y, width/2, height-20);
  32.  
  33.   int level = 1;
  34.   int num_c = 0;
  35.   int f = 255;
  36.   float i_c;
  37.  
  38.  
  39.   for (int i = 1; i < num; i++) {
  40.    
  41.     // gradient
  42.     if (f > 10) {
  43.       f = f - 10;
  44.     } else {
  45.       f = 255;
  46.     }
  47.     fill(f);
  48.    
  49.     float y_c = s;
  50.    
  51.     // new line of boxes wip
  52.     if ((num*s*1.5)>(width)) { //if more than one row
  53.       if ((i*s*1.5)>(width)) { // in second row when 2 rows
  54.  
  55.        
  56.         y_c = level*2.5*s; // to be changed to get vertical margin on multiple levels and get more than 2 rows
  57.         //console.log(num_w)
  58.         num_c = num - y;
  59.         i_c = i - y +0.5  ; // why is not centered ? (shouldn't have to add .5)
  60.        
  61.       } else { // in first row of 2 row
  62.      
  63.         //console.log(num_w)
  64.        
  65.         num_c = y ;
  66.         i_c = i;
  67.        
  68.       }
  69.     } else { // if only one row
  70.    
  71.       num_c = num;
  72.       i_c = i;
  73.      
  74.     }
  75.    
  76.     float x_c = width/2  -(num_c*s*1.5)/2 +i_c*s*1.5;  
  77.    
  78.     float newX = x_c-s/2;
  79.     float newY = y_c-s/2;
  80.    
  81.     // hover (vewy noice)
  82.     if ((mouseX > newX) && (mouseX < newX+s) && (mouseY > newY) && (mouseY < newY+s)) {
  83.       fill(137, 211, 255);
  84.       stroke(237, 247, 170);
  85.     }
  86.    
  87.    
  88.    
  89.     rect(x_c, y_c, s, s);
  90.    
  91.     fill(255, 0, 0);
  92.     textSize(10);
  93.     text(f, x_c, y_c +4);
  94.    
  95.     stroke(0);
  96.   }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement