Draw a Filled Triangle
Analog clock hands can be draw with simple lines. But the display will be more pleasing if we use clock hands that are made of triangles.
If the framebuf functions were supported in the driver drawing a filled triangle
would be easy. We would just put the three points in an array and call
the poly()
with a fill option.
However, the current driver does not support the framebuf functions. To overcome this limiation we will need to write our own function that will fill all the points in a triangle.
Our founction must take in the three points and a color and draw the traingle.
Draw Filled Triangle
Without going into too much detail, here is
the algorithm we will use dto draw a filled triangle.
Note that only the last line does drawing using the line()
function.
You will note that it must get the points in order
before the main loops run.
This version also checks for divide by zero errors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Full Test Program
To test our alforithm we can genrate three random points near the center of the display
and then call the traingle fill on these points. If you would like to see
how the algorithm does the drawing, you can uncomment the sleep function just
before the tft.line()
above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
Crazy Triangles
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|