Diagonal line for GLCD

Status
Not open for further replies.

superbrew

Member
Hello again, i am trying to write a function to draw a line from (x1,y1) to (x2,y2) on a GLCD. What I have so far only works if the slope of the line is 1 and x1,y1 values are less than x2,y2 values. Please be patient with me, lol.
Code:
void dline(unsigned char x1, unsigned char x2,unsigned char y1,unsigned char y2){
	signed int dx,dy;
	double slope,draw;
	
	//plot start
	plot(x1,y1);
	//find delta and delta y
	dx=(x2-x1);
	dy=(y2-y1);
	//find slope
	slope = dx/dy;
	//draw the line
	while(dx--){
		for(draw=0;draw<=(slope-1);draw++)
		{
			plot(x1,y1);
			y1++;			
		}
		x1++;		
	}
}
 
Google for Bresenham's algorithm. Even looking for just the basic one should get you a version that will handle any angle, and drawing from either end.

Then start digging for all the improved versions that have been made. The improved ones are MUCH faster.
 
If you can, get yourself a copy of this old book. I see there's some used copies available for cheap on Amazon. It goes over all the very basic graphic algo's in pretty good detail, progressing to improved versions as you learn how the simpler ones work. I bought it when it was new, for MUCH, MUCH more than you're going to pay.
 
Thanks for the replies. It looks like I have a lot more reading to do. For some reason, it does not seem like there is a lot of info on the net regarding glcd's and pics.
 
superbrew said:
Thanks for the replies. It looks like I have a lot more reading to do. For some reason, it does not seem like there is a lot of info on the net regarding glcd's and pics.
There isn't much out there, which is why I'm posting my reckless adventures online. But graphic algorithms are the same whether your screen is 128x64 or 1680x1050.
 
I've got an old book somewhere, in 6502 assembler, which gave routines for all kinds of text and graphic manipulation - there are probably various old books from back then.
 
superbrew said:
Hello again, i am trying to write a function to draw a line from (x1,y1) to (x2,y2) on a GLCD. What I have so far only works if the slope of the line is 1 and x1,y1 values are less than x2,y2 values. Please be patient with me, lol.
Hey superbrew. If you don't mind cheating, I borrowed and ported to C a piece of BlitzMax BASIC code I borrowed off the interweb. It works perfect on my GLCD. Just now got the last buglets out of it. It's pretty quick. All integers. If you want it, just say so.
 
i have wrote my code using Microbasic , if it can help i'll send to you .

it works very well ,

even i have wrote code for the eraser !
 
watzmann said:
even i have wrote code for the eraser !
What is "the eraser"?

I'm just now posting an update on my site. Some new movies of simple glcd animation demos and a picture. Should be up in 10 or 15 minutes.
 
Last edited:
loll . for you eraser means when you draw a line and need to select it and erase .

exaclty like what happens with CAD softwares , draw aline , or a circle , and if you don't like it you can remove .

try to do it
 
Thanks guys for the offers. I don't actually need this code, I am just trying to learn how do some stuff with a GLCD. MikroC has some nice functions for drawing lines and circles, but you don't have access to how they do it. I think from the information given I should be able to fiure it out.
 
watzmann said:
loll . for you eraser means when you draw a line and need to select it and erase .

exaclty like what happens with CAD softwares , draw aline , or a circle , and if you don't like it you can remove .

try to do it
Easy. Just XOR the same bits again. See the **broken link removed** on my site. It's not clearing the screen between moves (though that might be quicker ). It's erasing (redrawing in background color) the line just before drawing the new one.
 
Last edited:
futz said:
Easy. Just XOR the same bits again. See the **broken link removed** on my site. It's not clearing the screen between moves (though that might be quicker ). It's erasing (redrawing in background color) the line just before drawing the new one.


wow nice animation ....... but don't you agree with me that this is the basic animation technique which you can do with mcu.

i'm not telling i don't like, really a good effort , but i'm doing a more complicated one now , i'm doing 3D animation ,

as for the eraser it works very well too.
 
watzmann said:
but don't you agree with me that this is the basic animation technique which you can do with mcu.

i'm not telling i don't like, really a good effort , but i'm doing a more complicated one now , i'm doing 3D animation
Well ya, that was just the first quicky line tests to check out the routine.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…