You are on page 1of 3

#include <stdlib.

h>
#include <glut.h>
#include <math.h>
int x = 0, y = 0;
bool gerak = true;
void pinggir(int tebal, int radius)
{
double PI = 3.14;
glLineWidth(tebal);
glBegin(GL_LINE_LOOP);
for (int i=1;i<=360;i++)
{
float sudut=i*(2*PI/360);
float x=radius*cos(sudut);
float y=radius*sin(sudut);
glVertex2i(x,y);
}
glEnd();
}
void tengah ()
{
glBegin(GL_POLYGON);
glVertex2i(0,-25);
glVertex2i(27,-5);
glVertex2i(15,25);
glVertex2i(-15,25);
glVertex2i(-27,-5);
glEnd();
}
void garis()
{
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(0,-75);
glEnd();
}
void datar()
{
glColor3f(0.1,0,0);
glBegin(GL_QUADS);
glVertex2i(-450,0);
glVertex2i(450,0);
glVertex2i(450,-450);
glVertex2i(-450,-450);
glEnd();
}
void halangan()
{
glColor3f(0,0,0);
glBegin(GL_QUADS);
glVertex2i(300,0);
glVertex2i(450,0);
glVertex2i(450,150);
glVertex2i(300,150);
glEnd();
}
void render()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
datar();
glPopMatrix();
glPushMatrix();
halangan();
glTranslatef(0,100,0);
glTranslatef(x,0,0);
glRotatef(-y,0,0,1);
glPushMatrix();
glColor3f(0,0,0);
pinggir(7,100);
pinggir(4,80);
glPopMatrix();
glPushMatrix();
glScalef(1.2,1.2,0);
glTranslatef(0,-3,0);
glColor3f(0,0,0);
tengah();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
garis();
glRotatef(67,0,0,1);
garis();
glRotatef(67,0,0,1);
garis();
glRotatef(80,0,0,1);
garis();
glRotatef(80,0,0,1);
garis();
glPopMatrix();
glPopMatrix();
glFlush();
}
void timer(int a)
{
if(gerak)
{
x+=3;
y+=2;
}
else
{
x-=3;
y-=2;
}
if(x >= 200)
{
gerak = false;
}
else if( x <= -200)
{
gerak = true;
}
glutPostRedisplay();
glutTimerFunc(10,timer,0);
}
void main()
{
glutInitWindowPosition(350,150);
glutInitWindowSize(300,300);
glutCreateWindow("Roda yang Menggelinding");
gluOrtho2D(-330,330,-330,330);
glutDisplayFunc(render);
glutTimerFunc(100,timer,0);
glutMainLoop();
}