1.函数和数组的使用案例
Eye[] hiEye = new Eye[100];
void setup()
{
size(300,300);
smooth();
panda(100,100,2);
panda(200,200,1.3);
}
void panda(int x,int y,float s)
{
pushMatrix();
translate(x,y);
scale(s);
//ears
fill(0);
strokeWeight(1);
stroke(255);
ellipse(-35,-25,35,35);
ellipse(35,-25,35,35);
//head
fill(255);
strokeWeight(1);
stroke(0);
ellipse(0,0,100,90);
//eye
fill(0);
ellipse(-25,5,30,35);
ellipse(25,5,30,35);
fill(255);
ellipse(-25,0,6,6);
ellipse(25,0,6,6);
fill(0);
ellipse(0,25,7,5);
noFill();
stroke(0);
strokeWeight(1);
bezier(-2.5,35,-2.5,37,2.5,37,2.5,35);
popMatrix();
}
class Eye
{
color c;
float x;
void display()
{
}
}
2.图片的使用
tint()用于设置图片的色彩填充值
PImage photo;
void setup()
{
size(300,300);
photo=loadImage("008.jpg");
tint(255,0,255,50);
}
void draw()
{
background(0);
//image(photo,0,0);
//image(photo,0,0,150,150);
image(photo,mouseX,mouseY,150,150);
int h = int(random(photo.height));
int w = int(random(photo.width));
int all=w+h*photo.width;
loadPixels();
float r = red(photo.pixels[all]);
float g = green(photo.pixels[all]);
float b = blue(photo.pixels[all]);
}
3.文字
PFont f;
PFont f_new;
String message = "Processing is coming!";
void setup()
{
size(300,300);
smooth();
f=loadFont("SegoeUI-Light-48.vlw");
f_new=createFont("Arial",36,true);
textFont(f,48);
textFont(f_new,48);
}
void draw()
{
background(200);
textSize(48);
fill(0);
text("I feel fine",10,100);
textSize(36);
text("I feel fine",10,150);
textSize(24);
text("I feel fine",10,190);
fill(255,255,0);
text(message,10,10,290,290);
}