Box[] box; //<------- Box Class( Look down )
Button btExit= new Button("Exit",1300,850,80,30,255,0);/*<- Button Class
( Look down )*/
int numBox=100;
color c;
boolean tt=true;
//---------- event processing ---------/
void mousePressed()
{
btExit.Focus();
}
void mouseDragged()
{
for(int i=0;i< numBox; i++)
box[i].Focus();
}
// ------------------------------------------------------
void setup()
{
size(1400,900);
box=new Box[numBox];
btExit.Up();
for( int i=0; i<numBox; i++)
{
c=color( random(0,255) , random(0,255) , random(0,255) );
if( i%2==0) box[i]= new Box( random(0,width), random(0,height),random(30,150),c,false);
else box[i]= new Box( random(0,width), random(0,height),random(30,150),c,true);
}
blendMode(ADD); // or
}
void draw()
{
background(0);
for(int i=0;i< numBox; i++)
box[i].Show();
if(btExit.isOn ) //<------- Exit Button is Clicked
{
btExit.Down();
delay(500);
exit();
}else btExit.Up();
}
////////// Box Class ////////////////
class Box // <------- Define Box Class
{
float x,y,size,angle;
color c;
boolean r;
char t;
Box( float _x, float _y, float _size,color _c,boolean _r )
{
x= _x;
y= _y;
size=_size;
c=_c;
angle=random(0,360);
r=_r;
t=(char)( (int)random('A','Z')) ;
}
void Focus()
{
if( dist(x,y,mouseX,mouseY) < size/2 )
{
x=mouseX;
y=mouseY;
}
}
void Show()
{
fill(c);
rectMode(CENTER);
pushMatrix();
translate( x,y);
rotate(angle);
rect(0,0,size,size);
// textSize(size/2);
// textAlign(CENTER, CENTER);
// fill(c >>1);
// text(t,0,0);
// textAlign(LEFT,BOTTOM);
popMatrix();
rectMode(CORNER);
if( r) { angle-=0.1; x=x+10; }
else { angle+=0.1; x=x-10; }
if( x<0 ) { r=!r; x=0; }
if( x>width) { r=!r; x=width; }
}
}// end class
/*////////// Button Class //////////////////////
Button btMake=new Button("Make",stX+610,stY+200,80,30);
btMake.Up(); <--- void setup
btMake.Focus(); <--- void mousePressed()
////////////////////////////////////////////////////////////////////////////*/
class Button{
float x,y,sx,sy;
int cBack=200,cText=0;
String title;
boolean isOn=false;
Button( String _title , int _x, int _y , int _sx, int _sy)
{
x=(float)_x;
y=(float)_y;
sx=(float)_sx;
sy=(float)_sy;
title=_title;
}
Button( String _title , int _x, int _y , int _sx, int _sy, int _cText)
{
x=(float)_x;
y=(float)_y;
sx=(float)_sx;
sy=(float)_sy;
title=_title;
cText=_cText;
}
Button( String _title , int _x, int _y , int _sx, int _sy, int _cText, int _cBack)
{
x=(float)_x;
y=(float)_y;
sx=(float)_sx;
sy=(float)_sy;
title=_title;
cText=_cText;
cBack=_cBack;
}
void Up()
{
isOn=false;
fill(cBack);
rect(x,y,sx,sy);
textSize(20);
stroke(cText);
fill(cText);
textAlign(CENTER,CENTER);
text(title,x+sx/2,y+sy/2);
}
void Down()
{
isOn=true;
fill(100);
rect(x,y,80,30);
stroke(250);
fill(250);
textSize(20);
textAlign(CENTER,CENTER);
text(title,x+sx/2,y+sy/2);
textAlign(LEFT,TOP);
}
void Focus()
{
if( mouseX> x && mouseX <x+80 && mouseY>y && mouseY < y+30)
{
Down();
}else isOn=false;
}
}
'Processing' 카테고리의 다른 글
MultiFormClass (0) | 2019.07.03 |
---|