孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

函数的定义

返回类型 函数名称 (引数) {

//函数的代码

}

如下面描绘熊猫的代码

void setup() {

  size(900,300);

  smooth();

}

void draw() {

  background(200);

  for (int x=60;x<width;x+=110) {

    for (int y=50;y<height;y+=100) {

      panda(x,y);

    }

  }

}

void panda(int x,int y) {

  pushMatrix();

  translate(x,y);

  //耳朵

  fill(0);

  strokeWeight(1);

  ellipse(-35,-25,35,35);

  ellipse(35,-25,35,35);

  //头部

  fill(255);

  strokeWeight(0);

  ellipse(0,0,100,90);

  //眼睛

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

}

使用for语句和函数,绘制多个熊猫

posted on 2011-10-06 22:32  孤独的猫  阅读(4038)  评论(0编辑  收藏  举报