當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing beginShape()用法及代碼示例

Processing, beginShape()用法介紹。

用法

  • beginShape()
  • beginShape(kind)

參數

  • kind (int) 點、線、三角形、TRIANGLE_FAN、TRIANGLE_STRIP、四邊形或QUAD_STRIP

返回

  • void

說明

使用beginShape()endShape() 函數可以創建更複雜的表單。 beginShape() 開始記錄形狀的頂點,endShape() 停止記錄。 kind 參數的值告訴它從提供的頂點創建哪些類型的形狀。沒有指定模式,形狀可以是任何不規則多邊形。 beginShape() 可用的參數是 POINTS、LINES、TRIANGLES、TRIANGLE_FAN、TRIANGLE_STRIP、QUADS 和 QUAD_STRIP。調用beginShape() 函數後,必須遵循一係列vertex() 命令。要停止繪製形狀,請調用 endShape() 。帶有兩個參數的vertex() 函數指定2D 中的位置,而帶有三個參數的vertex() 函數指定3D 中的位置。每個形狀都將使用當前筆觸顏色勾勒出輪廓並用填充顏色填充。



translate()rotate()scale() 等轉換在 beginShape() 中不起作用。也不能在 beginShape() 中使用其他形狀,例如 ellipse()rect()



P2D 和 P3D 渲染器允許在 per-vertex 的基礎上更改 stroke()fill(),但默認渲染器不允許。 strokeWeight()strokeCap()strokeJoin() 等設置在帶有任何渲染器的 beginShape() /endShape() 塊內無法更改。

例子

beginShape();
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape(CLOSE);
Image output for example 1
beginShape(POINTS);
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape();
Image output for example 2
beginShape();
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape(CLOSE);
Image output for example 3
beginShape(LINES);
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape();
Image output for example 4
noFill();
beginShape();
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape();
Image output for example 5
noFill();
beginShape();
vertex(120, 80);
vertex(340, 80);
vertex(340, 300);
vertex(120, 300);
endShape(CLOSE);
Image output for example 6
beginShape(TRIANGLES);
vertex(120, 300);
vertex(160, 120);
vertex(200, 300);
vertex(270, 80);
vertex(280, 300);
vertex(320, 80);
endShape();
Image output for example 7
beginShape(TRIANGLE_STRIP);
vertex(120, 300);
vertex(160, 80);
vertex(200, 300);
vertex(240, 80);
vertex(280, 300);
vertex(320, 80);
vertex(360, 300);
endShape();
Image output for example 8
beginShape(TRIANGLE_FAN);
vertex(230, 200);
vertex(230, 60); 
vertex(368, 200); 
vertex(230, 340); 
vertex(88, 200); 
vertex(230, 60); 
endShape();
Image output for example 9
beginShape(QUADS);
vertex(120, 80);
vertex(120, 300);
vertex(200, 300);
vertex(200, 80);
vertex(260, 80);
vertex(260, 300);
vertex(340, 300);
vertex(340, 80);
endShape();
Image output for example 10
beginShape(QUAD_STRIP); 
vertex(120, 80);
vertex(120, 300);
vertex(200, 80);
vertex(200, 300);
vertex(260, 80); 
vertex(260, 300); 
vertex(340, 80);
vertex(340, 300); 
endShape();
Image output for example 11

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 beginShape()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。