News Update :
Home » , , , , » penggambaran garis dengan algoritma DDA dan bresenham

penggambaran garis dengan algoritma DDA dan bresenham

Penulis : Unknown on Senin, 08 April 2013 | 05.57


Selamat Malem teman-teman,
 Sebelum saya mengerjakan tugas kuliah apah salahnya saya untuk posting dulu, barang kali artikel saya bermafaat buat teman-teman.
ok langsung saja kali ini saya akan memposting tetang penggambaran garis dengan algoritma DDA dan bresenham, tidak lama-lama langsung saja ini source code nya :

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include <math.h>

voiddisplay(void)
{
glClearColor (1.0 ,1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 300.0, 0.0, 300.0);
}
voidsetPixel (GLint xCoordinate, GLint yCoordinate)
{
glBegin(GL_POINTS);
glVertex2i (xCoordinate, yCoordinate);
glEnd();
glFlush();
}

voidlineBres(GLint x0, GLint y0, GLint xEnd, GLint yEnd)
{
GLint dx = (float)fabs((float) xEnd - x0);
GLint dy = (float)fabs((float) yEnd - y0);
GLint p = 2 * (dy-dx);
GLint twoDy = 2 * dy;
GLint twoDyMinusDx = 2 * (dy-dx);
GLint x,y;

if (x0 > xEnd){
x = xEnd;
y = yEnd;
xEnd = x;
}else{
x = x0;
y = y0;
}
setPixel (x,y);
while(x<xEnd){
x++;
if(p<0)
p  += twoDy;
else{
y++;
p += twoDyMinusDx;
}
setPixel(x,y);
}
}
voiddrawMyLine(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glPointSize (4.0);
GLint x0 = 100;
GLint y0 = 100;
GLint xEnd = 200;
GLint yEnd = 100;
lineBres (x0, y0, xEnd, yEnd);

glColor3f (0.0, 0.0, 1.0);
glPointSize (4.0);
GLint x1 = 100;
GLint y1 = 200;
GLint xEnd1 = 200;
GLint yEnd1 = 200;
lineBres (x1, y1, xEnd1, yEnd1);

glColor3f (1.0, .0, 1.0);
glPointSize (4.0);
GLint x2 = 100;
GLint y2 = 300;
GLint xEnd2 = 200;
GLint yEnd2 = 300;
lineBres (x2, y2, xEnd2, yEnd2);
}

intmain (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (400, 400);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Digital Differential Anallyzer Algorithm");
display();
glutDisplayFunc (drawMyLine);
glutMainLoop();
return 0;
}

Dan ini Hasil Output nya :


penggambaran garis dengan algoritma DDA dan bresenham

Share this article :
Comments to facebook

+ komentar + 2 komentar

23 Oktober 2013 pukul 11.10

Mantap gan artikelnya..
Kunjungi juga artikel ane gan.. http://www.nongool.com/2013/10/cara-membuat-input-data-mahasiswa.html

23 Oktober 2013 pukul 11.14

iyahh gan terimakasih sudah berkunjung..

Posting Komentar

 
Copyright © 2011. .:: wahyudin 21 ::. . All Rights Reserved.
Design Template by panjz-online | Support by creating website | Powered by Blogger