Drawing a line on a Cosmic Unicorn problem

Hi! I recently purchased a Cosmic Uniforn display and i have a query re the graphics.line command

I understand the LEDS number from 0 to 31 left to right and 0 to31 top to bottom.
so the top left LED is in position (0,0) and the bottom right LED is (31,31)

So if I have a line in the script

graphics.line(0,0,31,0) i would expect the top row of leds would light from (0,0) to (31,0) inclusive.

However when i run my script LED (31,0) does NOT light up.

If i use graphic.pixel(31,0) i can get that LED to illiminate

I may be doing something wrong (finger trouble!) but could someone run the below script and advise. Just had a thought is graphics.line() different from display.line() Could be that!Many thanks in advance


from cosmic import CosmicUnicorn
from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY

cosmic = CosmicUnicorn()
graphics = PicoGraphics(DISPLAY)

green = graphics.create_pen(0,255,0)

graphics.line(top left co-ordinates (0,0) to top right cordinates (31,0))

graphics.line(0, 0, 31, 0)


I’m seeing something similar on my Stellar Unicorn.
display.line(0, 0, 15, 0, 1) leaves me with the last LED on the right not lit.
display.line(0, 0, 16, 0, 1) lights up the whole row.

Same deal on my Galactic Unicorn

display.line(0, 0, 52, 0) leaves me one short on the right and
display.line(0, 0, 53, 0) lights them all up.

Well thats odd. Hopefully someone will lets us know whats happening. Thanks for the response

I’ve also seen some similar oddities when using display.polygon.
The math doesn’t add up, so to speak. ;)

Looking at the github page re Pico Graphics i found this


To draw a straight line at any angle between two specified points:

display.line(x1, y1, x2, y2)

The X1/Y1 and X2/Y2 coordinates describe the start and end of the line respectively."

To me that would indicate that the top row of leds should illuminate if we put in the top left-top right LED positions. but like we’ve both seen it doesn’t

Also found another inconsistency.

thought i’d add a line thickness arguement of 8 just to see what happens. As you can see below it say i gave six postional arguements in the graphics.line entry but I’ve only put five. I’m assuming graphics.line and display.line do similar things. perhaps you could check display.line. As you say the math(s) dont add up:-)

Hopefully someone in the know knows.

You might need to expand the image to see the error comment

display.line(4, 0, 13, 0, 1)
display.line(4, 0, 13, 0, 2)
etc, work without error for me.
I do remember editing code I copied from various examples to change “graphics” to “display”.
It was what worked, well ran without errors anyway.

Are you using Pico graphics?
I’m doing it this way.

from stellar import StellarUnicorn
from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY

It’s a not-uncommon aspect of the fast maths used to draw lines; it’s one of those things that’s not particularly noticeable on a ‘normal’ size display, but becomes painfully apparent when you only have 32 pixels to play with.

The quick and dirty solution is to draw your line and then add a pixel at the line end point to make sure it appears (computationally it’s probably cheaper to do that than to try and determine if you need to!)

Line algorithms are surprisingly tricky buggers.

Hi all! I am using Pico graphics as in my first posting. Ill have to play around as its a bit of a learning curve for me. Not a great fan of working a round i must admit. especially when whatever the workarounds “fixes” is fixed. Still it wouldn’t be interesting if it was dead easy. Prefer programming to Sodoku. To me thats just the same puzzle with the numbers in a different order :-). Thanks for you replies. Keep them coming if you think of anything else.