星期四, 11月 30, 2006
NxM eyeballs that look at mouse cursor and change
這眼睛真的很難寫
我是參考了多人的範例所寫出來的!
對CLASS的概念還需要多一點練習
Processing Code:
--------------------------------------
int sCon=5,sRow=4,sColor=4;
sEyes[][] cl_Eye= new sEyes[sCon+1][sRow+1];
void setup()
{
size(200, 200);
smooth();
noStroke();
colorMode(HSB,360,100,100);
for(int i=0; i < sCon; i++)
{
for(int j=0; j < sRow; j++)
cl_Eye[i][j] = new sEyes(i*((width)/(sCon+1)),j*((height)/(sRow+1)));
}
}
void draw()
{
background(0);
for(int i=1; i < sCon; i++)
{
for(int j=1; j < sRow; j++)
cl_Eye[i][j].Display();
}
}
void mouseMoved()
{
for(int i=0; i < sCon; i++)
{
for(int j=0; j < sRow; j++)
cl_Eye[i][j].sChange(mouseX,mouseY);
}
}
void mousePressed()
{
sColor=(int)random(180,270);
for(int i=1; i < sCon; i++)
{
for(int j=1; j < sRow; j++)
cl_Eye[i][j].sChangeColor();
}
}
class sEyes
{
int x, y;
int size,icolor;
float angle = 0.0;
sEyes(int sPosx, int sPosy) {
x = sPosx;
y = sPosy;
icolor=(int)(sColor+random(-30,90));
if(width>=height)
size=height/(sRow+2);
else
size=width/(sCon+2);
}
void sChangeColor()
{
icolor=(int)(sColor+random(180));
}
void sChange(int sx, int sy)
{
angle = atan2(sy-y, sx-x);
}
void Display() {
pushMatrix();
translate(x, y);
fill(255);
ellipse(0,0, size, size);
rotate(angle);
fill(icolor,100,100);
ellipse(size/4, 0, size/2, size/2);
popMatrix();
}
}
--------------------------------------
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言