Wheel

On October 7, 2008, in Drawing, Shapes, by , Views : 4895


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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<conio.h>
#include<graphics.h>
#include<math.h>
 
int L = 0;
 
void ddaline(int x1, int y1, int x2, int y2)
{
 
    int s, dx, dy, m, c = 0;
    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;
	if (getpixel(x + 0.5, y + 0.5) == 4) {
	    c++;
	    continue;
	}
	if (c % 2 == 0) {
	    putpixel(x + 0.5, y + 0.5, 15);
	}
    }
}
 
 
void plotpoints(int x, int y, int cx, int cy, int s)
{
    if (s == 0) {
	if (L % 20 == 0) {
	    ddaline(cx - x, cy - y, cx + x, cy + y);
	    ddaline(cx - y, cy + x, cx + y, cy - x);
	    ddaline(cx - y, cy - x, cx + y, cy + x);
	    ddaline(cx - x, cy + y, cx + x, cy - y);
	}
	L++;
    }
    putpixel(cx + x, cy + y, 4);
    putpixel(cx - x, cy + y, 4);
    putpixel(cx + x, cy - y, 4);
    putpixel(cx - x, cy - y, 4);
    putpixel(cx + y, cy + x, 4);
    putpixel(cx - y, cy + x, 4);
    putpixel(cx + y, cy - x, 4);
    putpixel(cx - y, cy - x, 4);
}
 
 
void mcircle(int cx, int cy, int r, int s)
{
    int x = 0, y, p;
 
    y = r;
    p = 1 - r;
 
    while (x <= y) {
	plotpoints(x, y, cx, cy, s);
	x++;
	if (p < 0)
	    p += 2 * x + 1;
	else {
	    y--;
	    p += 2 * (x - y) + 1;
	}
    }
 
}
 
void main()
{
    int gd = DETECT, gm = DETECT;
    initgraph(&gd, &gm, "");
 
    mcircle(300, 250, 20, 1);
    mcircle(300, 250, 100, 0);
 
    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! 🙂



One Response to Wheel

  1. nikhil says:

    much interesting
    and its very helpfull

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:
clock ticking
Show the ticking of Clock

Final translated Image
2D Transformations: Translations

kite
Flying Kite

MinMaxClose