2011年12月12日 / 2025年3月21日 更新
2Dの回転をもとに動きを付けてみる
void setup() {
size(100, 100);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotate(frameCount*PI/60);
rect(0, 0, width/2, height/2);
}
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateX(frameCount*PI/60);
rect(0, 0, width/2, height/2);
}
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateY(frameCount*PI/60);
rect(0, 0, width/2, height/2);
}
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateY(frameCount*PI/60);
rect(width/2, 0, width/2, height/2);
}
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateZ(frameCount*PI/60);
rect(0, 0, width/2, height/2);
}
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateX(frameCount*PI/60);
rotateY(frameCount*PI/60);
rect(0, 0, width/2, height/2);
}
z軸方向に移動したい場合は、translate関数の引数を1つ追加する。
void setup() {
size(100, 100, P3D);
rectMode(CENTER);
}
void draw() {
background(0);
translate(width*2/5, height/2);
rotateY(PI/6);
for (int i = 0; i < 5; i++) {
pushMatrix();
translate(0, 0, i*10);
rotateZ(frameCount*(i+1)*PI/600);
fill(255, 51);
rect(0, 0, width/2, height/2);
popMatrix();
}
}
void setup() {
size(100, 100, P3D);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateY(frameCount*PI/60);
box(40, 30, 20); // 幅, 高さ, 奥行きの順。引数を1つにすると立方体になる。
}
lights関数を用いると光が当たっている状態をシミュレートできる。
void setup() {
size(100, 100, P3D);
}
void draw() {
background(0);
lights();
translate(width/2, height/2);
rotateY(frameCount*PI/120);
translate(50, 0);
noStroke();
sphere(10); //半径30pxの球
}