OLEH :
JURUSAN
TEKNOLOGI INFORMASI DAN KOMPUTER
POLITEKNIK NEGERI LHOKSEUMAWE
LEMBARAN PENGASAHAN
NIM : 1320305095
Kelas/Semester : N3 / VI (Genap)
Mengetahui,
Dosen Pengajar Mahasiswa
I. TUJUAN
1. Mahasiswa dapat membuat program untuk membuat obek menjadi bergerak.
2. Mahasiswa mampu menjelaskan dan memahami setiap kode program
Setelah suatu objek grafis dibangun, kita dapat melakukan transformasi terhadap
objek grafis tersebut dengan berbagai cara tanpa menambahkan komponen baru apapun pada
objek grafis tersebut. Ada banyak cara untuk melakukan transformasi objek grafis, tapi
beberapa cara transformasi yang umum adalah :
1. Translasi : objek dipindahkan ke lokasi baru tanpa mengubah bentuk, ukuran atau
orientasinya.
2. Rotasi : objek dirotasi (diputar) terhadap titik tertentu tanpa mengubah bentuk dan
ukurannya
3. Scalling : objek diperbesar atau diperkecil. objek dapat diskalakan menggunakan
faktor yang sama baik secara horisontal maupun vertikal sehingga proporsinya tetap
atau bisa menggunakan faktor yang berbeda yang akan menyebabkan objek tersebut
menjadi lebih lebih tinggi, lebih pendek, lebih tipis atau lebih tebal.
Translasi dan rotasi disebut juga sebagai rigid body transformation yaitu transformasi
yang hanya mengubah posisi objek, tanpa mengubah bentuknya
a. Translasi
Translasi adalah transformasi paling sederhana yang dapat diterapkan pada suatu
objek grafis. Secara sederhana translasi adalah memindahkan objek grafis dari satu tempat ke
tempat lain tanpa mengubah tampilan dan orientasi.
Untuk menghasilkan translasi dari suatu objek grafis, kita menambahkan konstanta Tx
pada koordinat x dan konstanta Ty pada koordinat Y, formula ini diterapkan pada semua titik
pada objek yang akan ditranslasikan.
Pada prakteknya untuk mentranslasikan objek grafis, tentu saja kita tidak harus
menghitung semua titik pada objek tersebut, tetapi cukup titik-titik pentingnya saja.
Contoh untuk memindahkan garis, cukup dihitung titik awal dan akhir saja kemudian
gambarkan garis dari kedua titik tersebut. Contoh kedua untuk memindahkan lingkaran
cukup menghitung titik pusat lingkaran kemudian dengan menggunakan algoritma penggambaran
lingkaran, lingkaran dengan posisi baru bisa dibentuk.
b. Rotasi
Diktat Kuliah Grafika Komputer Rotasi suatu image adalah memutar objek terhadap
titik tertentu di bidang xy. Bentuk dan ukuran objek tidak berubah. Untuk melakukan rotasi
perlu diketahui sudut rotasi θ dan pivot point (Xp,Yp) atau titik rotasi dimana objek dirotasi.
NIlai positif dari sudut rotasi menentukan arah rotasi berlawanan dengan jarum jam dan
sebaliknya nilai negative akan memutar objek searah jarum jam
Rotasi yang paling sederhana adalah rotasi dengan pivot point di titik pusat koordinat
sistem yaitu (0,0). Pada gambar 5.xx terlihat titik (x,y) dirotasi terhadap titik pusat koordinat
sistem dengan sudut θ, sudut terhadap sumbu x adalah sebesar Ф. Dengan menggunakan
trigonometri dasar dapat dihitung bahwa
c. Scalling (Penskalaan)
Scalling atau penskalaan adalah proses untuk mengubah ukuran objek, dengan cara
Mengubah jarak setiap titik pada objek terhadap titik acuan. Objek dapat diskalakan dengan
arah horizontal maupun vertical dengan cara mengalikan koordinat tiap objek dengan factor
konstanta.
Pada proses ini perlu dispesifikasikan dua hal yaitu :
1. Faktor penskalaan: sx & sy _ real: (0..N]
2. Titik acuan (xf,yf)
Jenis penskalaan ada dua yaitu uniform dan diferensial. Penskalaan Uniform terjadi
bila factor vertical sama dengan horizontal, sedangkan diferensial jika kedua factor tersebut
berbeda.
3. PERALATAN
Pada praktikum ini saya menggunakan laptop dan software yaitu :
- 1 Unit Laptop ASUS
- Microsoft Visual Studio 2012
1V. Percobaan
5. Tuliskan Nama project dan pilih lokasi tempat menyimpan file project.
6. Klik Ok
7. Lalu klik Kanan pada Source Files dan pilih Add > New Item
8. Memilih Visual C++ > lalu klik C++ file(.cpp)
9. Menuliskan Nama file dan Pilih lokasi penyimpanan.
10. Klik finish.
11. Setelah pengaturan area kerja selesai maka memasukkan syntax program.
V. DATA PROGRAM :
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
#define PI 3.141592
void Bola(){
glPopMatrix();
glPushMatrix();
glTranslatef(0,gerakY,0);
glColor3f(1,1,0);
glBegin(GL_POLYGON);
for(i=0; i<=100; i++){
float sudut = i+(2*PI/360);
float x = 200+50*cos(sudut);
float y = 50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//wajah
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/360);
float x = 100+300*cos(sudut);
float y = 300*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//mata hitam
glBegin(GL_POLYGON);
glColor3f(0,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/360);
float x = -10+100*cos(sudut);
float y = 100*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//mata hitam
glBegin(GL_POLYGON);
glColor3f(0,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/360);
float x = 200+100*cos(sudut);
float y = 100*sin(sudut);
glVertex2f(x,y);
}
glEnd();
// mata putih besar
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=200; i++){
float sudut = i+(2*PI/360);
float x = -50+50*cos(sudut);
float y = 30+50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//MULUT
glLineWidth(5.0);
glBegin(GL_LINE_STRIP);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=90; i<=180; i++){
float sudut = i*(2*PI/180);
float x = 90+120*cos(sudut);
float y = -150+120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//gigi1
glLineWidth(5.0);
glBegin(GL_LINE_STRIP);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=90; i<=180; i++){
float sudut = i*(2*PI/180);
float x = 80+30*cos(sudut);
float y = -150+30*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//gigi2
glLineWidth(5.0);
glBegin(GL_LINE_STRIP);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=90; i<=180; i++){
float sudut = i*(2*PI/180);
float x = 60+30*cos(sudut);
float y = -150+30*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//gigi3
glLineWidth(5.0);
glBegin(GL_LINE_STRIP);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=90; i<=180; i++){
float sudut = i*(2*PI/180);
float x = 100+30*cos(sudut);
float y = -150+30*sin(sudut);
glVertex2f(x,y);
}
glEnd();
//topi
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=200; i++){
float sudut = i+(2*PI/360);
float x = 100-300*cos(sudut);
float y = 200-100*sin(sudut);
glVertex2f(x,y);
}
glEnd();
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
Bola();
glFlush();
}
void main(int argc, char **argv) {
glutInitWindowPosition(300, 300);
glutInitWindowSize(640, 800);
glutCreateWindow("ayu wahyuni");
gluOrtho2D(-640,640,-640,640);
glutTimerFunc(0.5,Timer,0);
glutDisplayFunc(display);
glutMainLoop();
}
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
#define PI 3.141592
bool atas, samping = true;
int LingkaranP=0;
int i;
int gerakY=0;
int gerakX=0;
void Bola(){
glPopMatrix();
glPushMatrix();
glTranslatef(gerakY,gerakX,0);
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=100; i++){
float sudut = i+(2*PI/90);
float x = -20+30*cos(sudut);
float y = 120*50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=100; i++){
float sudut = i+(2*PI/90);
float x = 20+20*cos(sudut);
float y = 120*50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=100; i++){
float sudut = i+(2*PI/90);
float x = -10+30*cos(sudut);
float y = 100*50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=100; i++){
float sudut = i+(2*PI/90);
float x = 10+10*cos(sudut);
float y = 200*50*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -20+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -40+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 40+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 60+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -60+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -60+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 80+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -80+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 90+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -90+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 100+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -100+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 110+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -110+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 120+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -120+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 130+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -130+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 140+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -140+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 150+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -150+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 160+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -160+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 170+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -170+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 180+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 190+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -190+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 200+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -200+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 210+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -210+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 220+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -220+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 230+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -230+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 240+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -240+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 2500+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -250+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 260+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -260+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 270+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -270+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 280+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -280+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 290+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -290+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 300+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -300+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 310+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -310+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 320+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -320+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 330+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -330+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 340+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -340+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 350+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -350+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 360+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -360+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 370+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 370+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 380+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -380+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 390+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -390+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 400+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -400+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 410+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -410+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 420+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -420+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 430+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -430+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 440+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -440+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 450+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -450+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 460+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -460+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 470+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -470+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 480+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -480+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 490+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -490+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 500+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -500+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 510+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -510+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 520+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -520+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 530+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -530+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 540+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -540+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 550+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -550+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 560+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -560+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 560+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -560+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 570+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -570+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 580+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -580+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 590+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -590+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 600+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -600+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(0,1,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 610+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,0);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -610+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = 620+10*cos(sudut);
float y = 100*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
glLineWidth(2.0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(i=0; i<=300; i++){
float sudut = i+(2*PI/90);
float x = -620+10*cos(sudut);
float y = 50*120*sin(sudut);
glVertex2f(x,y);
}
glEnd();
}
void Bola(){
glPopMatrix();
glPushMatrix();
glTranslatef(gerakY,gerakX,0);
glColor3f(1,1,1);
glBegin(GL_POLYGON);;
glEnd();
}
gerakY-=1;
}if(gerakY>300){
atas=false;
}else if(gerakY<=-300){
atas=true;
}
glutPostRedisplay(); //Fungsi mengirimkan perintah untuk
mengaktifkan display secara berkala (looping).
//Kemudian pada main program perlu menambahkan fungsi untuk
mengaktifkan timer function.
glutTimerFunc(1,Timer,0);
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);//fungsi ini untuk menghapus
windows dan memberi warna
Bola(); //inisial Bola pada void sebelumnya
glFlush();//untuk memastikan bahwa perintah objek di eksekusi
}
glutTimerFunc(0.5,Timer,0);
glutDisplayFunc(display); //glutDisplayFunc() adalah fungsi
istimewa GLUT untuk memanggil fungsi yang akan menggambar seisi
kanvas
glutMainLoop();//event yang menandakan pemrosesan glut terjadi
}
Program
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
#define PI 3.141592
bool atas, samping = true; //pendeklarasian atas dan samping
int LingkaranP=0;// mendeklarasikan variable LingkaranP dengan tipe
data int
int i;
int gerakY=0; // pendeklarasian arah gerak objek ke atas dan ke
bawah
void Bola(){
glPopMatrix(); //memanggil suatu fungsi yang telah disimpan
pada glPushMatrix
glPushMatrix(); //berfungsi untuk menyimpan koordinat yang ada
glTranslatef(gerakY,gerakY,0); //Mengubah posisi titik pusat
sumbu koordinat kearah diagonal
glEnd();
glBegin(GL_POLYGON);
glBegin(GL_QUADS );
glColor3f(0.6,0.8,0.7);//memberikan perintah warna ABU
ABU
for(i=0; i<=200; i++){
float sudut = i+(2*PI/360);
float x = 200+300*cos(sudut); //pendeklarasian objek
untuk menentukan posisi pada sumbu x dan bersar kecil nya radius
float y = 300*sin(sudut); //pendeklarasian objek
untuk menentukan posisi pada sumbu y dan bersar kecil nya radius
glVertex2f(x,y);
}
glEnd();
}
void Timer(int t){
if(atas){
gerakY+=3;} //menyatakan kecepatan bola yang bergerak
dengan gerak ke atas
else{
glutTimerFunc(0.5,Timer,0);
glutDisplayFunc(display); //glutDisplayFunc() adalah fungsi
istimewa GLUT untuk memanggil fungsi yang akan menggambar seisi
kanvas
glutMainLoop();//event yang menandakan pemrosesan glut terjadi
}
V1. Analisa