Advertisements
Home > Cpp Graphics > C++ Graphics – 01 – Line program by Using Mid-Point Algorithm

C++ Graphics – 01 – Line program by Using Mid-Point Algorithm


Create a Line program by Using Mid-Point Algorithm.

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>

void lineMidPoint(int x1, int y1, int x2, int y2){
	int dx = x2 - x1;
	int dy = y2 - y1;
	int d = 2 * dy - dx;
	int incrE = 2 * dy;
	int incrNE = 2 * (dy - dx);
	int x = x1;
	int y = y1;
	putpixel(x, y, WHITE);
	while(x < x2){
		if(d<=0){
			d += incrE;
			x++;
			}
		else{
			d += incrNE;
			x++;
			y++;
			}
		putpixel(x, y, WHITE);
		}
	}

int main(){
	int gd=DETECT, gm;
	initgraph(&gd, &gm, "\\tc");
	lineMidPoint(100, 100, 600, 300);
	getch();
	return 0;
	}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: