Chess Board using DDA line drawing algorithm

On October 7, 2008, in Algorithms, Drawing, by , Views : 12942


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<conio.h>
#include<graphics.h>
#include<math.h>
 
void ddaline(int x1, int y1, int x2, int y2)
{
    int s, m, dx, dy;
    float xi, yi, x, y;
 
    dx = x2 - x1;
    dy = y2 - y1;
 
    if (abs(dx) > abs(dy))
	s = abs(dx);
    else
	s = abs(dy);
 
    xi = dx / (float) s;
    yi = dy / (float) s;
 
    x = x1;
    y = y1;
 
    putpixel(x1 + 0.5, y1 + 0.5, 15);
 
    for (m = 0; m < s; m++) {
	x += xi;
	y += yi;
	putpixel(x + 0.5, y + 0.5, 15);
    }
}
 
 
void fill(int x, int y)
{
    int i, j;
    for (i = x; i < (x + 50); i++)
	ddaline(i, y, i, y + 50);
}
 
 
void main()
{
    int i, j, c = 0;
    int gd = DETECT, gm = DETECT;
 
    initgraph(&gd, &gm, "");
    cleardevice();
 
    ddaline(100, 50, 100, 450);
    ddaline(100, 50, 500, 50);
    ddaline(500, 50, 500, 450);
    ddaline(100, 450, 500, 450);
 
    for (i = 100; i < 500; i += 50) {
	for (j = 50; j < 450; j += 50) {
	    if (c % 2 == 0)
		fill(i, j);
	    c++;
	}
	c++;
    }
    getch();
}

Download the code using the below link:

Please 'Like' or '+1' us to get the download link! (If you have already liked us on facebook, then like us either on G+ or twitter)



Hope, it helps! 🙂



4 Responses to Chess Board using DDA line drawing algorithm

  1. It's really working….thanks a lot…

  2. Sudhakar Kumar says:

    BGI graphics problem during compilatition.How it can be compiled or save?

    • What is your exact problem?

    • Deven says:

      step : 1– open turbo c++
      press alt+F // file menu will listed .
      select DOS Shell
      if the directory path is :C\TC\BIN>, then type “cd..”
      it will go as C:\TC\> .
      Now type “cd BGI” // to get inside BGI folder which handles all graphics compilation.
      the path should be as :: C\TC\BGI\>
      type “bgiobj cga”

      this is will initialize bgi object to load cga driver. and then later type “exit”.

      All the Graphics-related programs will be executed.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

  • Dipin Krishna

Archives

All entries, chronologically...

Read more:
man_rain
A man walking with umbrella in the rain.

Bouncing-ball
Bouncing Ball

Animated Road
A Simple Animation of a Road

MinMaxClose