如何用Processing生成马赛克风格的图像?
文章目录
首先使用PImage来实例化对象,再通过loadImage赋值,两层for循环遍历图片上的像素点,每隔5个像素点,画一个直径为3的圆。颜色通过pic.get(x,y)获取。
最后通过save函数来保存图片。
PImage pic;
int spacing=5;
void setup(){
pic=loadImage("steve.jpeg");
size(706, 644);
}
void draw(){
for (int x=spacing; x<width; x+=spacing) {
for (int y=spacing; y<height; y+=spacing) {
color c=pic.get(x, y);
fill(c);
noStroke();
ellipse(x, y, spacing*0.6, spacing*0.6);
}
}
save("image_2.jpg");
}


评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论