Contoh Operasi Tranformasi Objek
sumber:unsplash.com
Translating, Scalling dan Rotasi Objek Manusia
1.
Translating
Sourcode:
void setup(){
size(500, 800);
fill(100);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
fill(200, 100, 150, 100);
pushMatrix();
translate(60,80);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
popMatrix();
}
Screenshot:
2.
Scalling
Sourcode:
void setup(){
size(800, 1000);
fill(100);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
pushMatrix();
fill(0,0,255,128);
scale(2.0);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
popMatrix();
}
Screenshot:
3.
Rotasi
Sourcode:
void setup(){
size(800, 800);
fill(100);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
pushMatrix();
rotate(radians(-25));
fill(0);
// Kepala
ellipse(250,285,100,100);
// Badan
rect(178,335, 150,200);
// Lengan kanan
rect(78,335, 100,50);
rect(78,385, 50,100);
// Lengan kiri
rect(328,335, 100,50);
rect(378,385, 50,100);
// Kaki kanan
rect(178,535, 50,100);
rect(178,635, 50,100);
// Kaki kiri
rect(278,535, 50,100);
rect(278,635, 50,100);
popMatrix();
}
Screenshot:
Translating, Scalling
dan Rotasi Objek Rumah
1.
Translating
Sourcode:
void setup() {
size(500, 300);
// warna abu abu sebagai posisi awal
fill(100);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
// warna biru sebagai posisi terakhir
fill(0,0,255,128);
pushMatrix();
translate(60,80);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
popMatrix();
}
Screenshot:
2.
Scalling
Sourcode:
void setup() {
size(1000, 500);
// warna abu abu sebagai posisi awal
fill(100);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
// warna biru sebagai posisi terakhir
fill(0,0,255,128);
pushMatrix();
scale(2.0);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
popMatrix();
}
Screenshot:
3.
Rotasi
Sourcode:
void setup() {
size(600, 500);
// warna abu abu sebagai posisi awal
fill(100);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
pushMatrix();
rotate(radians(45));
fill(0);
triangle(200,100, 275,40, 350,100);
rect(200,100, 150,100);
popMatrix();
}
Screenshot:
Translating, Scalling
dan Rotasi Objek Balok
1.
Translating
Sourcode:
void setup(){
size(500,500);
fill(100);
smooth();
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
fill(200, 100, 150, 100);
pushMatrix();
translate(60,80);
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
popMatrix();
}
Screenshot:
2.
Scalling
Sourcode:
void setup(){
size(800,700);
fill(100);
smooth();
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
fill(200, 100, 150, 100);
pushMatrix();
scale(2.0);
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
popMatrix();
}
Screenshot:
3.
Rotasi
Sourcode:
void setup(){
size(500,500);
fill(100);
smooth();
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
//fill(200, 100, 150, 100);
pushMatrix();
rotate(radians(-15));
fill(0);
quad(150,200, 250,200,
250,300, 150,300);
quad(150,200, 220,120,
315,120, 250,200);
quad(315,120, 315,220,
250,300, 250,200);
popMatrix();
}
Screenshot:
0 Komentar