(二)利用processing绘制自定义图像

来源:互联网 发布:ubuntu如何使用cd命令 编辑:程序博客网 时间:2024/05/02 00:03
绘制自定义图案:
void setup(){                         //绘制一个箭头  size(360, 100);  background(0, 255, 0);  fill(0, 0, 255);  noStroke();  beginShape();  vertex(width/7, height/2);    vertex(width/4, height/6);  vertex(width/4, 2*height/6);  vertex(5*width/6, 2*height/6);    vertex(5*width/6, 4*height/6);  vertex(width/4, 4*height/6);  vertex(width/4, 5*height/6);  endShape(CLOSE);  saveFrame("Shape.png");}

程序运行结果:


函数使用说明:

beginShape() -> vertex() -> endShape() //开始自定义图案绘制 -> 标记顶点像素 -> 结束自定义图案绘制,CLOSE参数 表示是封闭图案
P5机器人绘制:

void setup(){  size(720, 480);  smooth();  strokeWeight(2);  background(0, 128, 255);  ellipseMode(RADIUS);    //neck  stroke(102);  line(266, 257, 266, 162);  line(276, 257, 276, 162);  line(286, 257, 286, 162);    //antenna  line(276, 155, 246, 112);  line(276, 155, 306, 56);  line(276, 155, 342, 170);    //body  noStroke();  fill(102);  ellipse(264, 377, 33, 33);  fill(0);  rect(219, 257, 90, 120);  fill(102);  rect(219, 274, 90, 6);    //head  fill(0);  ellipse(276, 155, 45, 45);  fill(255);  ellipse(288, 150, 14, 14);  fill(0);  ellipse(288, 150, 3, 3);  fill(153);  ellipse(263, 148, 5, 5);  ellipse(296, 130, 4, 4);  ellipse(305, 162, 3, 3);  saveFrame("Shape.png");}
程序运行结果:


函数使用说明:

ellipseMode()  //CENTER 设置 x,y 表示中心点,width、height表示椭圆的 长度 和 宽度               //RADIUS  设置 x,y 表示中心点,width、height表示椭圆的 长度的一半和宽度的一半               //CORNER 设置 x,y 为椭圆的左上角,width、 height表示椭圆的 长度 和 宽度               //CORNERS 这个不太能理解(ellipseMode(CORNERS) interprets the first two parameters of ellipse() as the location of one corner of the ellipse's bounding  box, and the third and fourth parameters as the location of the opposite corner.)

函数运行和结果展示:

void setup(){  size(100, 100);  ellipseMode(RADIUS);  fill(255);  ellipse(50, 50, 30, 30);    ellipseMode(CENTER);  fill(100);  ellipse(50, 50, 30, 30); }####################################################void setup(){  size(100, 100);  ellipseMode(CORNER);  fill(255);  ellipse(25, 25, 50, 50);    ellipseMode(CORNERS);  fill(100);  ellipse(25, 25, 50, 50);  saveFrame("Shape.png");}

0 0