tags: Processing
想繪制一個類似像框這種內部鏤空的形狀,類似 Photoshop 里的遮罩效果。“回”字圖或“O”字圖。嘗試了一下。
環境:Processing 3.x
方法1:畫線,調整線的寬度
示例代碼:
//方法1代碼示例
size(200, 200);
noFill();
float w=20;
stroke(255, 0, 0);
strokeWeight(w);
ellipse(width/2, height/2,100,100);
stroke(255);
strokeWeight(1);
ellipse(width/2, height/2,100-w,100-w);
ellipse(width/2, height/2,100+w,100+w);
效果圖:
方法2:畫輪廓線 beginContour()
Processing 內置提供了輪廓線方法。案例參考:
// code from: https://processing.org/reference/beginContour_.html
size(100, 100);
translate(50, 50);
stroke(255, 0, 0);
beginShape();
// Exterior part of shape, clockwise winding
vertex(-40, -40);
vertex(40, -40);
vertex(40, 40);
vertex(-40, 40);
// Interior part of shape, counter-clockwise winding
beginContour();
vertex(-20, -20);
vertex(-20, 20);
vertex(20, 20);
vertex(20, -20);
endContour();
endShape(CLOSE);
效果:
即 beginShape()
開始畫自定義圖形,先畫外輪廓線,然后 beginContour()
開始畫內輪廓線。
注意:外輪廓線,順時針給坐標。內輪廓線,逆時針給坐標。
[正文結束]
[更新記錄]
2016-10-14,初建筆記。記錄了 storkeWeight 和 beginContour 2種方法