【Processing入门】第六七章:函数和数组

本文展示了如何使用Processing库进行图形绘制和图像操作,包括创建眼睛类、使用tint()函数设置图片色彩填充、加载和显示图片、以及文本显示。

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);
}



 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值