Tugas UAS praktik Grafika Komputer :
Gambar Android dengan DEV C++
#include#include#define kiri -70#define kanan 70#define bawah -70#define atas 70#includeconst double PI = 3.141592653589793;int i,radius,jumlah_titik,x_tengah,y_tengah;typedef struct titik{float x,y;}titik;void plot(int x, int y){glBegin(GL_POLYGON);glVertex2f(x-0.5,y-0.5);glVertex2f(x+0.5,y-0.5);glVertex2f(x+0.5,y+0.5);glVertex2f(x-0.5,y+0.5);glEnd();}void tukar(int *ax, int *ay, int *bx, int *by){int temp;temp=*ax; *ax=*bx; *bx=temp;temp=*ay; *ay=*by; *by=temp;}void lingkaran(double sudut, int xc, int yc, double r){glBegin( GL_LINES);double t = 0.;double dt;double jr;jr=360/sudut;dt= sudut * 3.14159/180;for (int i=0; i < jr; ++i) {glVertex2f( xc, yc);glVertex2f( r * cos(t)+xc, r*sin(t)+yc );t = t + dt;}glEnd();}void setengahlingkaran(double sudut, int xc, int yc, double r){glBegin( GL_LINES);double t = 0.;double dt;double jr;jr=360/sudut;dt= sudut * 3.14159/180;if (xc > 0) { //ambil kananfor (int i=0; i < jr; ++i) {if ((i < (jr*0.5)) || ((i > (jr*2.9)) && (i < jr ))){glVertex2f( xc, yc);glVertex2f( r * cos(t)+xc, r*sin(t)+yc );}t = t + dt;}}else {for (int i=0; i < jr; ++i) {if ((i > (jr*0.1)) && (i < (jr*0.6) )){glVertex2f( xc, yc);glVertex2f( r * cos(t)+xc, r*sin(t)+yc );}t = t + dt;}}glEnd();}void badan(){glColor3f(0.6, 1.0, 0.0);glBegin( GL_POLYGON);glVertex2f( 32, -30);glVertex2f( 32, 28);glVertex2f( -18, 28);glVertex2f( -18, -30);glEnd();}static void display(void){titik a,b;glClear(GL_COLOR_BUFFER_BIT);// kepalaglColor3f(0.6, 1.0, 0.0);setengahlingkaran(0.3,7,32,25);//sungut kananglBegin( GL_POLYGON);glVertex2f( 34, 60 );glVertex2f( 36, 58);glVertex2f( 30, 49);glVertex2f( 20, 39);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaranlingkaran(0.3,35,59,1.4);//sungut kiriglBegin( GL_POLYGON);glVertex2f( -19, 60 );glVertex2f( -21, 58);glVertex2f( -15, 49);glVertex2f( -8, 43);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaranlingkaran(0.3,-20,59,1.4);//mata kiriglColor3f(1,1,1);lingkaran(0.3,-5,45,2);//mata kananglColor3f(1,1,1);lingkaran(0.3,20,45,2);//badanbadan();//tangan kiriglColor3f(0.6, 1.0, 0.0);glBegin( GL_POLYGON);glVertex2f( -21, -27);glVertex2f( -21, 23);glVertex2f( -35, 23);glVertex2f( -35, -27);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaran ataslingkaran(0.3,-28,22,7);glColor3f(0.6, 1.0, 0.0); //lingkaran bawahlingkaran(0.3,-28,-25,7);//tangan kananglColor3f(0.6, 1.0, 0.0);glBegin( GL_POLYGON);glVertex2f( 35, -27);glVertex2f( 35, 23);glVertex2f( 49, 23);glVertex2f( 49, -27);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaran ataslingkaran(0.3,42,22,7);glColor3f(0.6, 1.0, 0.0); //lingkaran bawahlingkaran(0.3,42,-25,7);//kaki kiriglColor3f(0.6, 1.0, 0.0);glBegin( GL_POLYGON);glVertex2f( -13, -50);glVertex2f( -13, 8);glVertex2f( 1, 8);glVertex2f( 1, -50);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaran ataslingkaran(0.3,-6,-50,7);//kaki kananglColor3f(0.6, 1.0, 0.0);glBegin( GL_POLYGON);glVertex2f( 27, -50);glVertex2f( 27, 8);glVertex2f( 13, 8);glVertex2f( 13, -50);glEnd();glColor3f(0.6, 1.0, 0.0); //lingkaran bawahlingkaran(0.3,20,-50,7);//titik pusatglColor3f(0,0,0);glBegin(GL_POINTS);glVertex2f(40,40);glEnd();glFlush();}void init(){glClearColor(1,1,1,1); // warna backgroundglMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(kiri,kanan,bawah,atas); //areal pandang atau camera sudut pandangglMatrixMode(GL_MODELVIEW);}int main(int argc, char **argv){glutInit(&argc,argv);glutInitWindowSize(500,500);glutInitWindowPosition(0,0);glutCreateWindow("11520241015");glutDisplayFunc(display);init();glutMainLoop();return 0;}
0 terbaik