Processing 画一个绿色的图像(2)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/teamlet/article/details/85229149

Processing有非常强大的图像处理能力。

创建一个绿色的图片,占满整个画布。

这里需要学习的是 :

createImage(width,height,color)

color(red,green,blue)

img.set(x,y,color)

的用法。

PImage img;

void setup(){
  size(640,480);
  background(100,100,100);
  img = createImage(width,height,ARGB);
  color green = color(0,255,0);
  for(int y=0; y < img.height;y++){
    for(int x=0;x <img.width;x++){
      img.set(x,y,green);
    }
  }
}

void draw(){
  image(img,0,0);
}

PImage 是 Processing提供的图像类。

size(x,y) :

设置画布大小;

background(r,g,b):

设置画布背景颜色 red,green,blue

createImage(width,height,ARGB):

Processing提供的方法,创建一个图像

width 图像的宽度,这里的值取自size中的x

height 图像的高度,这里的值取自size中的y

ARGB 图像颜色,这里的取值是Processing的内置值。

green = color(0,255,0):

创建一个颜色,参数是:red,green,blue 每个参数取值范围 0 ~255

img.set(x,y,green):

在图像的x,y像素设置颜色

猜你喜欢

转载自blog.csdn.net/teamlet/article/details/85229149