code.club

標題: 畫出六角形的方法 [打印本頁]

作者: processor    時間: 2018-2-23 22:30
標題: 畫出六角形的方法
  1. void setup(){
  2.   size(600,600);
  3. }
  4. void draw(){
  5. background(255);
  6. hexagon(200,200,80);
  7. }
  8. void hexagon(float x, float y, float r){
  9.   pushMatrix();
  10.   translate(x,y);
  11.   beginShape(POLYGON);
  12.   for(float angle = 0;angle<=PI*2;angle+=PI/3){
  13.     vertex(r*cos(angle),r*sin(angle));
  14.   }
  15.   endShape();
  16.   popMatrix();
  17. }
複製代碼





歡迎光臨 code.club (http://code.club/) Powered by Discuz! X3.2