Komputer Grafika, menggambar menggunakan Titik-titik koordinat, jadi harus bisa menentukan titik-titik koordinatnya.
Nah, berhubung teman satu kampus saya ada yang minta tolong buatkan program pelangi menggunakan C++, berikut saya sertakan Source Code Programnya
Program 1 PERSEGI Pelangi
![]() |
| Output/Hasil saat di eksekusi |
====================================================
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
void display(void)
{
/* bersihkan layar dari titik pixel yang masih ada */
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 0.0);
/* posisi vertex */
glBegin(GL_POLYGON);
glColor3f (1, 0, 0); glVertex3f (-0.5 ,-0.5,0.0);
glColor3f (0, 1, 0); glVertex3f (-0.5,0.5,0.0);
glColor3f (0, 0, 1); glVertex3f (0.5,0.5,0.0);
glColor3f (1, 0, 1); glVertex3f (0.5,-0.5,0.0);
glEnd();
glFlush ();
}
void kunci(unsigned char key, int x, int y)
{
switch (key)
{
/* aplikasi berhenti ketika tombol q ditekan */
case 27 :
case 'q':
exit(0);
break;
}
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("Polygon Pelangi Oleh Herniwati Tindaon");
glutDisplayFunc(display);
glutKeyboardFunc(kunci);
glutMainLoop();
return 0;
}
====================================================
2. Program PELANGI
![]() |
| Output/Hasil saat di eksekusi |
Source Code
====================================================
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <glut.h>
void display(void)
{
/* bersihkan layar dari titik pixel yang masih ada */
glClear (GL_COLOR_BUFFER_BIT);
/* gambar 5 titik di layar */
glColor3f (1.0, 1.0, 1.0);
/* posisi vertex */
glBegin(GL_POLYGON);
glColor3f (0.0, 0.0, 1.0);glVertex3f (-0.8, 0.0, 0.0);
glColor3f (0.0, 0.0, 1.0);glVertex3f (-0.8, 0.2, 0.0);
glColor3f (0.0, 0.0, 1.0);glVertex3f (0.8 ,0.2, 0.0);
glColor3f (0.0, 0.0, 1.0);glVertex3f (0.8, 0.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f (0.0, 1.0, 0.0);glVertex3f (-0.8, 0.2, 0.0);
glColor3f (0.0, 1.0, 0.0);glVertex3f (-0.8, 0.4, 0.0);
glColor3f (0.0, 1.0, 0.0);glVertex3f (0.8, 0.4, 0.0);
glColor3f (0.0, 1.0, 0.0);glVertex3f (0.8, 0.2, 0.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f (1.0, 1.0, 0.0);glVertex3f (-0.8, 0.4, 0.0);
glColor3f (1.0, 1.0, 0.0);glVertex3f (-0.8, 0.6, 0.0);
glColor3f (1.0, 1.0, 0.0);glVertex3f (0.8, 0.6, 0.0);
glColor3f (1.0, 1.0, 0.0);glVertex3f (0.8, 0.4, 0.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f (1.0, 0.0, 0.0);glVertex3f (-0.8, 0.6, 0.0);
glColor3f (1.0, 0.0, 0.0);glVertex3f (-0.8, 0.8, 0.0);
glColor3f (1.0, 0.0, 0.0);glVertex3f (0.8, 0.8, 0.0);
glColor3f (1.0, 0.0, 0.0);glVertex3f (0.8, 0.6, 0.0);
glEnd();
glFlush ();
}
void kunci(unsigned char key, int x, int y)
{
switch (key)
{
/* aplikasi berhenti ketika tombol q ditekan */
case 27 :
case 'q':
exit(0);
break;
}
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("Program Pelangi Oleh Herman Putra");
glutDisplayFunc(display);
glutKeyboardFunc(kunci);
glutMainLoop();
return 0;
}
====================================================













