Advertisements
Home > Cpp Graphics > C++ Graphics – 02 – Line program by Incremental Algorithm

C++ Graphics – 02 – Line program by Incremental Algorithm


Create a Line program by Incremental Algorithm.

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

void lineIncremental(int x1, int y1, int x2, int y2){
	int x;
	float dy = y2-y1;
	float dx = x2-x1;
	float m = dy/dx;
	float y = y1;
	if ((m > -1) || (m < 1) ){
		for(x=x1; x<=x2;x++){
			putpixel(x, floor(0.5+y), WHITE);
			y+=m;
			}
		}
	else{
		for(x=y1; x<=y2;x++){
			putpixel(x, floor(0.5+y), WHITE);
			x+=1/m;
			}
		}
	}

void main(){
	int gd=DETECT, gm;
	initgraph(&gd, &gm, "\\tc");
	lineIncremental(100, 10, 300, 400);
	lineIncremental(100, 400, 300, 10);
	getch();
	}

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: