Mail Archives: djgpp/2000/05/27/15:30:16
From: | "Alexei A. Frounze" <see_below AT the_message_body DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: help a semi-newbie with some graphics....
|
Date: | Sat, 27 May 2000 23:19:50 +0400
|
Organization: | None
|
Lines: | 63
|
Message-ID: | <39301FD6.9FE7936F@the_message_body.com>
|
References: | <8gp59t$h8n$1 AT lure DOT pipex DOT net>
|
NNTP-Posting-Host: | ppp99-19.dialup.mtu-net.ru
|
Mime-Version: | 1.0
|
X-Trace: | gavrilo.mtu.ru 959455199 30465 212.188.99.19 (27 May 2000 19:19:59 GMT)
|
X-Complaints-To: | usenet-abuse AT mtu DOT ru
|
NNTP-Posting-Date: | 27 May 2000 19:19:59 GMT
|
X-Mailer: | Mozilla 4.72 [en] (Win95; I)
|
X-Accept-Language: | ru,en
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Standard Bresenham's line drawing function looks like this:
-------------------------8<-------------------------------
void line (int x1, int y1, int x2, int y2, char color) {
int sx, sy, dx1, dy1, dx2, dy2, x, y, m, n, k=0, cnt;
sx = x2-x1;
sy = y2-y1;
if (sx > 0) dx1 = 1;
else if (sx < 0) dx1 = -1;
else dy1 = 0;
if (sy > 0) dy1 = 1;
else if (sy < 0) dy1 = -1;
else dy1 = 0;
m = abs (sx);
n = abs (sy);
dx2 = dx1;
dy2 = 0;
if (m < n) {
m = abs (sy);
n = abs (sx);
dx2 = 0;
dy2 = dy1;
};
x = x1; y = y1;
cnt = m+1;
while (cnt--) {
putpixel (x, y, color);
k += n;
if (k < m) {
x += dx2;
y += dy2;
}
else {
k -= m;
x += dx1;
y += dy1;
};
};
}
-------------------------8<-------------------------------
Good Luck
Alexei A. Frounze
-----------------------------------------
E-mail: alexfru [AT] chat [DOT] ru
Homepage: http://alexfru.chat.ru
Mirror: http://members.xoom.com/alexfru
"DeepBlack (Murray Evans)" wrote:
>
> Right, I've got a working pixel routine, a working rectangle drawing
> routine, and working vertical and horizontal line routines, which can all
> write to either the screen or a 'virtual' screen set up in memory. My
> problem arrises with my line drawing routine to cope with lines that are not
> horizontal/vertical.
- Raw text -