Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 30th March 2008, 03:32 AM   (permalink)
Default Diagonal line for GLCD

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++;		
	}
}
superbrew is offline  
Old 30th March 2008, 03:38 AM   (permalink)
Default

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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 30th March 2008, 03:50 AM   (permalink)
Default

I have a line draw in asm if that's any use.

Mike.
Pommie is offline  
Old 30th March 2008, 03:55 AM   (permalink)
Default

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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 30th March 2008, 09:25 PM   (permalink)
Default

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 is offline  
Old 30th March 2008, 09:37 PM   (permalink)
Default

Quote:
Originally Posted by superbrew
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 30th March 2008, 11:33 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 31st March 2008, 07:09 AM   (permalink)
Default

Quote:
Originally Posted by superbrew
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 31st March 2008, 08:02 AM   (permalink)
Default

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 is offline  
Old 31st March 2008, 08:06 AM   (permalink)
Default

Quote:
Originally Posted by watzmann
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 31st March 2008 at 08:11 AM.
futz is offline  
Old 31st March 2008, 08:11 AM   (permalink)
Default

That would be drawing in colour zero on a background of zero. :-)

Mike.
Pommie is offline  
Old 31st March 2008, 08:13 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
That would be drawing in colour zero on a background of zero. :-)
Heh LOL
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 31st March 2008, 01:36 PM   (permalink)
Default

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 :P
watzmann is offline  
Old 31st March 2008, 02:01 PM   (permalink)
Default

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.
superbrew is offline  
Old 31st March 2008, 03:32 PM   (permalink)
Default

Quote:
Originally Posted by watzmann
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 :P
Easy. Just XOR the same bits again. See the animation movies 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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 31st March 2008 at 04:22 PM.
futz is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Need advice about this AC Line Current Detector Avocado Electronic Projects Design/Ideas/Reviews 6 21st March 2008 06:37 PM
DS1302 with PIC16f877 program RasCreationKing Micro Controllers 28 3rd May 2007 01:03 PM
QBasic Serial Port Control DigiTan Micro Controllers 3 6th January 2006 12:32 AM
2 line telephone patcher / switcher .. help please rca507 Electronic Projects Design/Ideas/Reviews 1 20th February 2004 05:19 AM
LCD 4 Line 40 Character Interfacing rwamser Electronic Projects Design/Ideas/Reviews 5 28th November 2003 01:44 AM



All times are GMT. The time now is 09:13 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker