![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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++;
}
} | |
| |
| | (permalink) |
| 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 ========================= | |
| |
| | (permalink) |
| I have a line draw in asm if that's any use. Mike. | |
| |
| | (permalink) |
| 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 ========================= | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| 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 ! | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) |
| That would be drawing in colour zero on a background of zero. :-) Mike. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 31st March 2008 at 04:22 PM. | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |