/* Praktikum 05
* Membuat objek lingkaran sederhana
*/
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include<math.h>
using namespace std;
typedef unsigned char uchar;
// number of line segments
static int num_lines = 3;
static int num_lines1 = 20;
// callback prototypes
void disp(void);
void keyb(uchar k, int x, int y);
void reshape(int x, int y);
// main
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow("circle.cpp");
glClearColor(0.0,0.0,0.0,1.0);
glutDisplayFunc(disp);
glutKeyboardFunc(keyb);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
// disp
void disp(void){
double angle;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glColor3f(0.0,1.0,0.0);
for(int i =0;i<num_lines;i++){
angle = i*2*3.14/num_lines;
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
for(int i =0;i<num_lines1;i++){
angle = i*2*3.14/num_lines1;
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glColor3f(1.0,0.0,1.0);
glBegin(GL_POLYGON);
for(int i =0;i<num_lines1;i++){
angle = i*2*3.14/num_lines1;
glVertex2f((cos(angle)/2),(sin(angle)/2));
}
glEnd();
glutSwapBuffers();
}
// keyb
void keyb(uchar k, int x, int y){
switch (k){
case 'q':
exit(0);
break;
case '+':
if(num_lines< 99){
num_lines++;
num_lines1--;
cout << "Circle consists of " << num_lines << " lines " << endl;
glutPostRedisplay();
}
break;
case '-':
if(num_lines >3){
num_lines--;
num_lines1++;
cout << "Circle consists of " << num_lines << " lines " << endl;
glutPostRedisplay();
}
break;
}
}
// reshape
void reshape(int x,int y){
if(x<y)
glViewport(0,(y-x)/2,x,x);
else
glViewport((x-y)/2,0,y,y);
}
* Membuat objek lingkaran sederhana
*/
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include<math.h>
using namespace std;
typedef unsigned char uchar;
// number of line segments
static int num_lines = 3;
static int num_lines1 = 20;
// callback prototypes
void disp(void);
void keyb(uchar k, int x, int y);
void reshape(int x, int y);
// main
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow("circle.cpp");
glClearColor(0.0,0.0,0.0,1.0);
glutDisplayFunc(disp);
glutKeyboardFunc(keyb);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
// disp
void disp(void){
double angle;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glColor3f(0.0,1.0,0.0);
for(int i =0;i<num_lines;i++){
angle = i*2*3.14/num_lines;
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
for(int i =0;i<num_lines1;i++){
angle = i*2*3.14/num_lines1;
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glColor3f(1.0,0.0,1.0);
glBegin(GL_POLYGON);
for(int i =0;i<num_lines1;i++){
angle = i*2*3.14/num_lines1;
glVertex2f((cos(angle)/2),(sin(angle)/2));
}
glEnd();
glutSwapBuffers();
}
// keyb
void keyb(uchar k, int x, int y){
switch (k){
case 'q':
exit(0);
break;
case '+':
if(num_lines< 99){
num_lines++;
num_lines1--;
cout << "Circle consists of " << num_lines << " lines " << endl;
glutPostRedisplay();
}
break;
case '-':
if(num_lines >3){
num_lines--;
num_lines1++;
cout << "Circle consists of " << num_lines << " lines " << endl;
glutPostRedisplay();
}
break;
}
}
// reshape
void reshape(int x,int y){
if(x<y)
glViewport(0,(y-x)/2,x,x);
else
glViewport((x-y)/2,0,y,y);
}
No comments:
Post a Comment