函數:
繪制直線自由圖形:
beginShape(), vertex(), endShape() 分別是繪制圖形開始,連接圖形的節點,繪制結束 endShape(CLOSE)表示閉合圖形。
繪制曲線邊框自由圖形:
beginShape() 開始繪制
vertex() 圖形起始端點
bezierVertex(cx1,cy1,cx2,cy2,x,y) 曲線 cx1,cy1,cx2,cy2為第一和第二個控制點坐標 x,y為結束端點坐標
endShape()
顏色:關鍵在括號后面有幾個值
灰階: color(灰度)
灰階含透明度: color(灰度, 透明度)
彩色: color(R,G,B)
彩色含透明度: color(R,G,B,透明度)
colorMode(): 定義色彩模式
colorMode(RGB, 255) 采用RGB模式
colorMode(HSB,360,100,100) 采用HSB模式 后面數字是取值范圍
繪畫屬性:
background(color) 設定畫布顏色
fill(color) 指定填充顏色
noFill() 不填色
stroke(color) 指定線條顏色
noStroke() 不畫線條
strokeWeight(thickness) 指定邊框寬度
strokeCap(mode) 指定線條端點形式包括 SQUARE(方形端點) PROJECT(方形延伸端點) ROUND(圓形端點)
strokeJoin(mode) 指定線條折角形式 包括 MITER(尖角) BEVEL(斜角) ROUND(圓角)
smooth()開啟平滑繪圖模式
noSmooth() 關閉平滑繪圖模式
------------------------------------------
代碼實例:來自《Processing互動編程藝術》
size(300,300); background(255); smooth(); noFill(); for(int i = 0; i < 400; i+= 15) { stroke(0); strokeWeight(i/35); ellipse(150,150,i+i/3,i+i/3); }
---------------------------------------------------------------------
size(300,300); background(0); smooth(); strokeWeight(2); for(int y = 30; y <= 270; y+=10) { for(int x = 20; x <= 270; x+=20) { stroke(y,x,255); line(x,y,x+10,y-10); } } for(int y = 20; y <= 260; y+=10) { for(int x = 30; x <= 270; x+=20) { stroke(x,y,255); line(x,y,x+10,y+10); } }
---------------------------------------------
size(300,300); background(0); smooth(); noFill(); for(int d = 0; d < 75; d+=4) { for(int x = 0; x < 350; x+=75) { for(int y = 0; y < 350; y+=75) { stroke(random(0,200),random(0,200),random(0,255)); strokeWeight(4); ellipse(x,y,d,d); } } }
很像是書的封面
------------------------------------------------------------------
size(300,300); smooth(); //ear fill(0); ellipse(80,100,70,70); ellipse(220,100,70,70); //head fill(255); strokeWeight(2); ellipse(150,150,200,180); //eye fill(0); ellipse(100,160,60,70); ellipse(200,160,60,70); fill(255); ellipse(100,150,12,12); ellipse(200,150,12,12); //nose fill(0); ellipse(150,200,15,10); //mouse noFill(); stroke(0); strokeWeight(2); bezier(145,220,145,225,155,225,155,220);
-----------------------------------------------------
size(300,300); background(255); int d = 60; for(int x = 0; x < 320; x += d/3) { for(int y = 0; y < 320; y+=d/3) { noFill(); stroke(0,125,255); ellipse(x,y,d,d); } }