Author: Not specified Language: c
Description: Not specified Timestamp: 2013-06-15 13:37:13 +0000
View raw paste Reply
  1. int over(recw,rech,mx,my,lockh)
  2. {
  3.     if((mouseX>mx && mouseX<(mx+recw)) && (mouseY>(my-lockh/2) && mouseY<(my+rech)) )
  4.         return 1;
  5.     else
  6.         return 0;
  7. }
  8.  
  9. void setup()
  10. {  //setup function called initially, only once
  11.   size(250, 250);
  12.   background(255);  //set background white
  13.   colorMode(RGB);   //set colors to Hue, Saturation, Brightness mode
  14.   stroke(#000000);
  15.   counter = 0;
  16. }
  17.  
  18. void draw()
  19. {  
  20.  
  21.     int recw=50,rech=100, lockh=rech/5;
  22.     int mx=(width-recw)/2, my=(height-rech)/2;
  23.     background(255);
  24.     fill(#FFFFFF);
  25.     rect(mx,my,recw,rech,0);
  26.         fill(000000);
  27.     rect(mx,locky,recw,lockh);
  28.     if(over(recw,rech,mx,my,lockh))
  29.     {
  30.         if(mouseY<my)
  31.             locky=my;
  32.         else if(mouseY>(my+rech-lockh))
  33.             locky=my+rech-lockh;
  34.         else
  35.             locky=mouseY;
  36.            
  37.         if(mouseY>locky)
  38.             locky++;
  39.         else if (mouseY<locky)
  40.             locky--;
  41.        
  42.     }
  43.  
  44.  
  45. }
  46.  
  47. void mouseMoved()
  48. {
  49.  
  50.     redraw();  
  51.    
  52.    
  53. }
View raw paste Reply