Processing 畫一個綠色的影象(2)
阿新 • • 發佈:2018-12-25
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畫素設定顏色