Line drawing algorithm, anyone create one in spin?
![Timothy D. Swieter](https://forums.parallax.com/uploads/userpics/482/n6OIB3WNWVK0M.jpg)
I have been working on my uOLED display driver (clocking data to the OLED from the Propeller) and the graphics driver (an 8-bit graphics engine).· Right now the display driver is working great.· It is written in ASM and the memory in the Prop is being written to the memory of the OLED in about 6ms per frame!
·
Now, I am trying to piece together some graphics drawing routines.· I am writing them in Spin first and then I will convert to a graphics engine in ASM.· The bitmap memory·color depth is·8-bit per pixel.· I have a plot pixel function working.· Next is a line algorithm.· I looked through the Hydra book and there were only a couple references, nothing major.· I also looked at the Black Art e-book on the Hydra CDROM and that helped a little.· I mostly did searches on Google for Bresenham to read more about his work.
·
Anyway, has anyone created a line drawing algorithm in Spin that works for all line slopes?· I have a partial line function working, but it only applies to slopes from -1 to 1 and sometimes I think it is still not right.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
·
Now, I am trying to piece together some graphics drawing routines.· I am writing them in Spin first and then I will convert to a graphics engine in ASM.· The bitmap memory·color depth is·8-bit per pixel.· I have a plot pixel function working.· Next is a line algorithm.· I looked through the Hydra book and there were only a couple references, nothing major.· I also looked at the Black Art e-book on the Hydra CDROM and that helped a little.· I mostly did searches on Google for Bresenham to read more about his work.
·
Anyway, has anyone created a line drawing algorithm in Spin that works for all line slopes?· I have a partial line function working, but it only applies to slopes from -1 to 1 and sometimes I think it is still not right.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
Comments
Give this a try. It's a line drawing algorithm that uses no multiplies or divides and works for any pair of endpoints. I've transcribed it from an assembly routine and haven't tested it, so let me know if it doesn't work and I'll fix it.
-Phil
Shouldn't those be
Oops never mind
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
There is an ASM line function that should work for you from the VGA text and graphics demo... I derived this from the TV graphics demo, but if I remember correctly you must draw the line from BOTH end points to the center or continue to the opposite end once you have determined if the slope of the line is Vertically or Horizontally dominate.
http://forums.parallax.com/showthread.php?p=606957
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
In a couple days I will be making a post with further details about the OLED driver and the basic graphics engine (really just a set of routines at this point).· Yes, the memory is just bitmap memory.· The system is setup with an on-screen memory and an off-screen memory but in reality you could eliminate one and just have the graphics engine and display driver work in series (i.e. draw the image in memory and then update the OLED).·
There isn't a palette in the driver.· I am using the OLED in 8-bit mode which allows for 256 colors with 3-bits for R, 3-bits for G and 2-bits for blue.· There are some advance features of the OLED for grayscale and PWM adjustment, but I haven't messed with those.· In time maybe the display driver can be expanded.
Stay tuned for pics/video and·a further post.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
Andre'
I will focus my attention on a couple other functions to finish before I post the code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
No, sorry, I don't have one handy. The assembly program that the line routine came from doesn't do circles.
-Phil
Andre'
The code works well for radi that are smaller, but as the circle expands to larger radi it begins to look more polygonish (8 sides).· I will have to read more about this.· I bet it has to deal with the simplifications and·the reflections.· For now though it will work to express the point of the 8-bit driver.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
Would a generic sine/cosine algorithm work for drawing circles? or would that be too slow? You could cut it into quadrants so that the sine/cosine would only need to calculate for 1/4 of the circle and just translate the remaining 3/4 and that would speed it up a little bit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
http://www.4dsystems.com.au/downloads/micro-OLED/uOLED-96-PROP/Docs/Pdf/SSD1331.pdf
<!--EndFragment -->
Regards
Gerry
Oops, yes. I never thought about that method of implementing it (I've been doing most of my graphics work on architectures with hardware divisors; In that case, division can be faster, depending on the speed of your divisor)
Gerry - I realize the oled driver has built in drawing algorithms, but I am avoiding those. I created a display driver which clocks video memory into the OLED at 6ms per frame. I am not working on an 8-bit graphics driver to draw in the Propeller memory.
I did figure out a circle routine from another post in the forum, I think it was Paul Sr. I also added sprite ability and text ability. Again it is just a collection of SPIN routines at this time, so it isn't fast, but in time I hope to transfer to ASM. I am cooking up a small demo now and will post in a day or so.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
http://forums.parallax.com/showthread.php?p=716659
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
www.tdswieter.com
One little spark of imagination is all it takes for an idea to explode
-phar