三角形と図形移動

function setup() {
createCanvas(720, 400);
background(255);
x=100;
w=60;
fill(200);
triangle(x, x, x+w, x+w, x + 2*w, x);
translate(w,0);
triangle(x, x, x+w, x+w, x + 2*w, x);
translate(w,0);
triangle(x, x, x+w, x+w, x + 2*w, x);
// noStroke(); 枠線を消す
}
星型

let vertexNum = 5 * 2;
let outR = 130;
let inR = outR / 2.5;
function setup() {
createCanvas(300, 300);
// 角度の指定を度数法に
angleMode(DEGREES);
}
function draw() {
background(255);
beginShape();
push();
fill(0,255,0);
// スケッチの中心を原点に
translate(width/2,height/2);
// 90度回転
rotate(90);
for (let i = 0; i < vertexNum; i++) {
let r = i % 2 ? outR : inR; // 1個目が外側、2個目が内側、繰り返し
let theta = i * 360 / vertexNum;
let x = r * cos(theta);
let y = r * sin(theta);
vertex(x, y); //座標に点を打ってシェイプを作る。
}
endShape(CLOSE);
pop();
}
引用:http://blog.livedoor.jp/reona396/archives/55768147.html
cos(theta)とsin(theta)から座標x,yを求める
let x = r * cos(theta);
let y = r * sin(theta);
コメント