Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.51 KB | None | 0 0
  1. /*
  2.  * GraphicAPI - Demonstrate graphic API functions
  3.  *
  4.  * This sketch demonstrates the graphics API functions.
  5.  * It is a demo of all the graphic APIexamples
  6.  *
  7.  * 2013-09-04 Bill Perry  - original creation
  8.  *  bperrybap@opensource.billsworld.billandterrie.com
  9.  */
  10.  
  11. #include "openGLCD.h"
  12.  
  13. #define BARMAXVAL 100
  14. #define DELAY 900 // delay between "demos"
  15. #define SDELAY DELAY/6
  16.  
  17. void setup()
  18. {
  19.     GLCD.Init();
  20.     IntroScreen();
  21.     delay(DELAY*3);
  22. }
  23. void IntroScreen()
  24. {
  25.   GLCD.SelectFont(Arial14);
  26.   GLCD.DrawString(GLCD_GLCDLIB_NAMESTR, gTextfmt_center, 3);
  27.   GLCD.DrawString(GLCD_GLCDLIB_VERSIONSTR, gTextfmt_center, GLCD.CharHeight(0) + 2);
  28.   GLCD.DrawRoundRect(0+10,0, GLCD.Right-20, GLCD.CharHeight(0) *2 + 1, 5);  // rounded rectangle around text area  
  29. }
  30.  
  31. void loop()
  32. {
  33.     GLCD.ClearScreen();
  34.     GLCD.SelectFont(Arial14);
  35.     GLCD.DrawString("Graphics Demo", gTextfmt_center, gTextfmt_center);
  36.     delay(DELAY*3);
  37.     DrawVLine();
  38.     DrawHLine();
  39.     DrawLine();
  40.     DrawRect();
  41.     InvertRect();
  42.  
  43.     DrawTriangle();
  44.     DrawRoundRect();
  45.     DrawCircle();
  46.     DrawEllipse();
  47.  
  48.     FillRect();
  49.     FillRoundRect();
  50.     FillTriangle();
  51.     FillCircle();
  52.     FillEllipse();
  53.  
  54.     DrawHBarGraph();
  55.     DrawVBarGraph();
  56. }
  57.  
  58.  
  59. /*
  60.  * Graphic API demo functions
  61.  */
  62.  
  63.  
  64. void DrawCircle(void)
  65. {
  66.     GLCD.ClearScreen();
  67.     /*
  68.      * Draw Circles on the display shrinking every 4 pixels starting
  69.      * from the outsided and moving in.
  70.      */
  71.     for(uint8_t i = 0; i < GLCD.Bottom/2; i +=4)
  72.     {
  73.         GLCD.DrawCircle(GLCD.CenterX,GLCD.CenterY, (GLCD.Bottom - 2*i)/2);
  74.         delay(SDELAY);
  75.     }
  76.     delay(DELAY);
  77. }
  78.  
  79. void DrawEllipse(void)
  80. {
  81.     GLCD.ClearScreen();
  82.     /*
  83.      * Draw Ellipses on the display shrinking every 4 pixels starting
  84.      * from the outsided and moving in.
  85.      */
  86.     for(uint8_t i = 0; i < GLCD.Bottom/2; i +=4)
  87.     {
  88.         GLCD.DrawEllipse(GLCD.CenterX,GLCD.CenterY, (GLCD.Right - 2*i)/2, (GLCD.Bottom - 2*i)/2);
  89.         delay(SDELAY);
  90.     }
  91.     delay(DELAY);
  92. }
  93.  
  94. void DrawHBarGraph()
  95. {
  96.     GLCD.ClearScreen();
  97.     GLCD.SelectFont(fixednums8x16);
  98.     for(int num = 0; num <= BARMAXVAL; num++)
  99.     {
  100.         /*
  101.          * print number with 0 fill
  102.          */
  103.  
  104.         // subtract 2.5 times font width from CenterX
  105.         GLCD.CursorToXY(GLCD.CenterX-12, 0);
  106.         if(num < 100)
  107.             GLCD.print('0');
  108.         if(num < 10)
  109.             GLCD.print('0');
  110.  
  111.         GLCD.print(num);
  112.  
  113.         /*
  114.          * left to right bar graphs
  115.          */
  116.        
  117.         /*
  118.          * Draw Horizontal bar graph:
  119.          * 10 pixels from left edge of display
  120.          * 15 pixels from top
  121.          * (GLCD.Width -20) pixels wide advancing to right of x
  122.          * 5 pixels in height droping down from y
  123.          * no border,
  124.          * with a range of 0 to BARMAXVAL
  125.          */
  126.         GLCD.DrawHBarGraph(GLCD.Left+10, GLCD.Top+15, GLCD.Width-2*10, 5, 0, 0, BARMAXVAL, num);
  127.  
  128.         /*
  129.          * Draw Horizontal bar graph:
  130.          * 10 pixels from left edge of display
  131.          * 21 pixels from top
  132.          * (GLCD.Width -20) pixels wide advancing to right of x
  133.          * 5 pixels in height droping down from y
  134.          * 1 pixel border,
  135.          * with a range of 0 to BARMAXVAL
  136.          */
  137.         GLCD.DrawHBarGraph(GLCD.Left+10, GLCD.Top+21, GLCD.Width-2*10, 5, 1, 0, BARMAXVAL, num);
  138.  
  139.         /*
  140.          * Draw Horizontal bar graph:
  141.          * 10 pixels from left edge of display
  142.          * 27 pixels from top
  143.          * (GLCD.Width -20) pixels wide advancing to right of x
  144.          * 5 pixels in height droping down from y
  145.          * 2 pixel border,
  146.          * with a range of 0 to BARMAXVAL
  147.          */
  148.         GLCD.DrawHBarGraph(GLCD.Left+10, GLCD.Top+27, GLCD.Width-2*10, 5, 2, 0, BARMAXVAL, num);
  149.  
  150.  
  151.     /*
  152.      * on smaller displays
  153.      * break up into two seperate loops
  154.      */
  155. #if (DISPLAY_HEIGHT < 64)
  156.         delay(DELAY/30);
  157.     }
  158.     delay(DELAY);
  159.     GLCD.ClearScreen();
  160.     for(int num = 0; num <= BARMAXVAL; num++)
  161.     {
  162.         /*
  163.          * print number with 0 fill
  164.          */
  165.  
  166.         // subtract 2.5 times font width from CenterX
  167.         GLCD.CursorToXY(GLCD.CenterX-12, 0);
  168.         if(num < 100)
  169.             GLCD.print('0');
  170.         if(num < 10)
  171.             GLCD.print('0');
  172.  
  173.         GLCD.print(num);
  174. #endif
  175.  
  176.         /*
  177.          * right to left bar graphs
  178.          */
  179.  
  180.         /*
  181.          * Draw Horizontal bar graph:
  182.          * 10 pixels from right edge of display
  183.          * along bottom
  184.          * (GLCD.Width -20) pixels wide advancing to left of x
  185.          * 5 pixels in height rising up from y
  186.          * no border,
  187.          * with a range of 0 to BARMAXVAL
  188.          */
  189.         GLCD.DrawHBarGraph(GLCD.Right-10, GLCD.Bottom, -(GLCD.Width-2*10), -5, 0, 0, BARMAXVAL, num);
  190.  
  191.         /*
  192.          * Draw Horizontal bar graph:
  193.          * 10 pixels from right edge of display
  194.          * 6 pixels from bottom
  195.          * (GLCD.Width -20) pixels wide advancing to left of x
  196.          * 5 pixels in height rising up from y
  197.          * 1 pixel border,
  198.          * with a range of 0 to BARMAXVAL
  199.          */
  200.         GLCD.DrawHBarGraph(GLCD.Right-10, GLCD.Bottom-6, -(GLCD.Width-2*10), -5, 1, 0, BARMAXVAL, num);
  201.  
  202.         /*
  203.          * Draw Horizontal bar graph:
  204.          * 10 pixels from right edge of display
  205.          * 6 pixels from bottom
  206.          * (GLCD.Width -20) pixels wide advancing to left of x
  207.          * 5 pixels in height rising up from y
  208.          * 2 pixel border,
  209.          * with a range of 0 to BARMAXVAL
  210.          */
  211.         GLCD.DrawHBarGraph(GLCD.Right-10, GLCD.Bottom-12, -(GLCD.Width-20), -5, 2, 0, BARMAXVAL, num);
  212.  
  213.         delay(DELAY/30);
  214.     }
  215.  
  216.     delay(DELAY);
  217. }
  218. void DrawHLine(void)
  219. {
  220.     GLCD.ClearScreen();
  221.  
  222.     /*
  223.      * Draw a Horizontal line every 4 pixels
  224.      */
  225.     for(uint8_t y = 0; y < GLCD.Height; y+=4)
  226.     {
  227.         GLCD.DrawHLine(0, y, GLCD.Width);
  228.         delay(SDELAY/2);
  229.     }
  230.     delay(DELAY);
  231. }
  232.  
  233. void DrawLine(void)
  234. {
  235.     GLCD.ClearScreen();
  236.  
  237.     /*
  238.      * Draw lines from center connecting to the 8th pixels down the left side
  239.      */
  240.     for(uint8_t y = 0; y < GLCD.Height; y+=8)
  241.     {
  242.         GLCD.DrawLine(GLCD.CenterX,GLCD.CenterY, GLCD.Left,y);
  243.         delay(SDELAY/2);
  244.     }
  245.     /*
  246.      * Draw lines from center connecting to the 8th pixels along bottom
  247.      */
  248.     for(uint8_t x = 0; x < GLCD.Width; x+=8)
  249.     {
  250.         GLCD.DrawLine(GLCD.CenterX,GLCD.CenterY, x,GLCD.Bottom);
  251.         delay(SDELAY/2);
  252.     }
  253.  
  254.     /*
  255.      * Draw lines from center connecting to the 8th pixels up the right side
  256.      */
  257.     for(int y = GLCD.Bottom; y > 0; y -=8)
  258.     {
  259.         GLCD.DrawLine(GLCD.CenterX,GLCD.CenterY, GLCD.Right,y);
  260.         delay(SDELAY/2);
  261.     }
  262.  
  263.     /*
  264.      * Draw lines from center connecting to the 8th pixels along top
  265.      */
  266.     for(uint8_t x = GLCD.Right; x > 7; x -=8)
  267.     {
  268.         GLCD.DrawLine(GLCD.CenterX,GLCD.CenterY, x,GLCD.Top);
  269.         delay(SDELAY/2);
  270.     }
  271.    
  272.     delay(DELAY);
  273. }
  274. void DrawRect(void)
  275. {
  276.     GLCD.ClearScreen();
  277.  
  278.     /*
  279.      * Draw rectangles on the display every 4 pixels starting
  280.      * from the outsided and move in.
  281.      */
  282.     for(uint8_t i = 0; i < GLCD.Bottom/2; i +=4)
  283.     {
  284.         GLCD.DrawRect(GLCD.Left+i, GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i);
  285.         delay(SDELAY);
  286.     }
  287.     delay(DELAY);
  288. }
  289. void DrawRoundRect(void)
  290. {
  291.     GLCD.ClearScreen();
  292.  
  293.     /*
  294.      * Draw rectangles on the display every 4 pixels starting
  295.      * from the outsided and move in.
  296.      */
  297.     for(uint8_t i = 0; i < GLCD.Bottom/2-8; i +=8)
  298.     {
  299.         GLCD.DrawRoundRect(GLCD.Left + i,GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i, 5);
  300.         delay(SDELAY);
  301.     }
  302.  
  303.     delay(2000);
  304.  
  305.     GLCD.ClearScreen();
  306.  
  307.     /*
  308.      * Draw rectangles on the display every 4 pixels starting
  309.      * from the outsided and move in.
  310.      * (Different corner radius from above)
  311.      */
  312.     for(uint8_t i = 0; i < GLCD.Bottom/2-8; i +=8)
  313.     {
  314.         GLCD.DrawRoundRect(GLCD.Left + i,GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i, 15);
  315.         delay(SDELAY);
  316.     }
  317.     delay(DELAY);
  318. }
  319.  
  320. void DrawTriangle(void)
  321. {
  322.     GLCD.ClearScreen();
  323.     /*
  324.      * Draw shrinking Triangles on the display starting
  325.      * on the outside and moving in.
  326.      */
  327.  
  328.     for(uint8_t i=0; i< GLCD.Bottom/2; i +=8)
  329.     {
  330.         GLCD.DrawTriangle(GLCD.Left+2*i+1, GLCD.Bottom-i, GLCD.CenterX, GLCD.Top+i, GLCD.Right-2*i, GLCD.Bottom-i);
  331.         delay(SDELAY);
  332.     }
  333.  
  334.     delay(DELAY);
  335. }
  336.  
  337. void DrawVBarGraph()
  338. {
  339. int num = 0;
  340.  
  341.     GLCD.ClearScreen();
  342.     GLCD.SelectFont(fixednums8x16);
  343.  
  344.     while(num <= BARMAXVAL)
  345.     {
  346.         /*
  347.          * print number with 0 fill
  348.          */
  349.  
  350.         // subtract 2.5 times font width from CenterX
  351.         GLCD.CursorToXY(GLCD.CenterX-12, 0);
  352.         if(num < 100)
  353.             GLCD.print('0');
  354.         if(num < 10)
  355.             GLCD.print('0');
  356.  
  357.         GLCD.print(num);
  358.        
  359.         /*
  360.          * Draw vertical bar graph:
  361.          * left edge of display
  362.          * 4 pixels up from bottom
  363.          * 5 pixels wide to right of x,
  364.          * (HEIGHT - 8) pixels in height advancing up from y
  365.          * no border,
  366.          * with a range of 0 to BARMAXVAL
  367.          */
  368.  
  369.         GLCD.DrawVBarGraph(GLCD.Left, GLCD.Bottom-4, 5, -(GLCD.Height-2*4), 0, 0, BARMAXVAL, num);
  370.  
  371.         /*
  372.          * Draw vertical bar graph:
  373.          * 10 pixels from left edge of display
  374.          * 4 pixels up from bottom
  375.          * 5 pixels wide to right of x,
  376.          * (HEIGHT - 8) pixels in height advancing up from y
  377.          * 1 pixel border,
  378.          * with a range of 0 to BARMAXVAL
  379.          */
  380.         GLCD.DrawVBarGraph(GLCD.Left+10, GLCD.Bottom-4, 5, -(GLCD.Height-2*4), 1, 0, BARMAXVAL, num);
  381.  
  382.         /*
  383.          * Draw vertical bar graph:
  384.          * 20 pixels from left edge of display
  385.          * 4 pixels up from bottom
  386.          * 5 pixels wide to right of x,
  387.          * (HEIGHT - 8) pixels in height advancing up from y
  388.          * 2 pixel border,
  389.          * with a range of 0 to BARMAXVAL
  390.          */
  391.         GLCD.DrawVBarGraph(GLCD.Left+20, GLCD.Bottom-4, 5, -(GLCD.Height-2*4), 2, 0, BARMAXVAL, num);
  392.  
  393.         /*
  394.          * Draw vertical bar graph:
  395.          * right edge of display
  396.          * 4 pixels down from top
  397.          * 5 pixels wide to left of x,
  398.          * (HEIGHT - 8) pixels in height advancing down from y
  399.          * 0 pixel border,
  400.          * with a range of 0 to BARMAXVAL
  401.          */
  402.         GLCD.DrawVBarGraph(GLCD.Right, GLCD.Top+4, -5, (GLCD.Height-2*4), 0, 0, BARMAXVAL, num);
  403.  
  404.         /*
  405.          * Draw vertical bar graph:
  406.          * 10 pixels from right edge of display
  407.          * 4 pixels down from top
  408.          * 5 pixels wide to left of x,
  409.          * (HEIGHT - 8) pixels in height advancing down from y
  410.          * 1 pixel border,
  411.          * with a range of 0 to BARMAXVAL
  412.          */
  413.         GLCD.DrawVBarGraph(GLCD.Right-10, GLCD.Top+4, -5, (GLCD.Height-2*4), 1, 0, BARMAXVAL, num);
  414.  
  415.         /*
  416.          * Draw vertical bar graph:
  417.          * 20 pixels from right edge of display
  418.          * 4 pixels down from top
  419.          * 5 pixels wide to left of x,
  420.          * (HEIGHT - 8) pixels in height advancing down from y
  421.          * 2 pixel border,
  422.          * with a range of 0 to BARMAXVAL
  423.          */
  424.         GLCD.DrawVBarGraph(GLCD.Right-20, GLCD.Top+4, -5, (GLCD.Height-2*4), 2, 0, BARMAXVAL, num);
  425.  
  426.         num++;
  427.         delay(DELAY/20);
  428.     }
  429.     delay(DELAY);
  430. }
  431. void DrawVLine(void)
  432. {
  433.     GLCD.ClearScreen();
  434.  
  435.     /*
  436.      * Draw a vertical line every 4 pixels
  437.      */
  438.     for(uint8_t x = 0; x < GLCD.Width; x+=4)
  439.     {
  440.         GLCD.DrawVLine(x, 0, GLCD.Height-1);
  441.         delay(SDELAY/2);
  442.     }
  443.     delay(DELAY);
  444. }
  445. void FillCircle(void)
  446. {
  447.     GLCD.ClearScreen();
  448.     /*
  449.      * Draw circle in center of display
  450.      */
  451.  
  452.     GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, GLCD.Height/2-1);
  453.     delay(DELAY);
  454.  
  455.     /*
  456.      * Draw filled circle in center of display
  457.      */
  458.  
  459.     GLCD.FillCircle(GLCD.CenterX, GLCD.CenterY, GLCD.Height/2-1);
  460.     delay(DELAY);
  461.  
  462.     /*
  463.      * A little animation for eye candy
  464.      */
  465.  
  466.     GLCD.ClearScreen();
  467.  
  468.     /*
  469.      * Fill pixels from outside in
  470.      */
  471.     for(int r = 1; r < GLCD.Height/2; r++)
  472.     {
  473.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, GLCD.Height/2-r);
  474.         delay(SDELAY/10);
  475.     }
  476.  
  477.     /*
  478.      * Remove pixels from inside out
  479.      */
  480.     for(int r = GLCD.Height/2 -1; r > 0; r--)
  481.     {
  482.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, GLCD.Height/2-r, PIXEL_OFF);
  483.         delay(SDELAY/10);
  484.     }
  485.  
  486.     /*
  487.      * Fill pixels from inside out
  488.      */
  489.     for(int r = 1; r < GLCD.Height/2 -1; r++)
  490.     {
  491.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, r);
  492.         delay(SDELAY/10);
  493.     }
  494.  
  495.     /*
  496.      * remove pixels from inside out
  497.      */
  498.     for(int r = 1; r < GLCD.Height/2 -1; r++)
  499.     {
  500.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, r, PIXEL_OFF);
  501.         delay(SDELAY/10);
  502.     }
  503.  
  504.     /*
  505.      * Fill pixels from inside out
  506.      */
  507.     for(int r = 1; r < GLCD.Height/2 -1; r++)
  508.     {
  509.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, r);
  510.         delay(SDELAY/10);
  511.     }
  512.  
  513.     /*
  514.      * remove pixels from inside out
  515.      */
  516.     for(int r = 1; r < GLCD.Height/2 -1; r++)
  517.     {
  518.         GLCD.DrawCircle(GLCD.CenterX, GLCD.CenterY, r, WHITE);
  519.         delay(SDELAY/10);
  520.     }
  521.  
  522.     delay(DELAY);
  523. }
  524. void FillEllipse(void)
  525. {
  526.     GLCD.ClearScreen();
  527.  
  528.     /*
  529.      * Draw ellipse in center of display with xrad=32, yrad=14
  530.      */
  531.  
  532.     GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, 32, 14);
  533.     delay(DELAY);
  534.     GLCD.ClearScreen();
  535.  
  536.     /*
  537.      * Draw filled ellipse in center of display with xrad=32, yrad=14
  538.      */
  539.  
  540.     GLCD.FillEllipse(GLCD.CenterX, GLCD.CenterY, 32, 14);
  541.     delay(DELAY);
  542.     GLCD.ClearScreen();
  543.  
  544.     /*
  545.      * Draw ellipse with equal x an y rad (circle)
  546.      * Note: DrawCircle() is more efficient
  547.      */
  548.     GLCD.FillEllipse(GLCD.CenterX, GLCD.CenterY, 10, 10);
  549.     delay(DELAY);
  550.     GLCD.ClearScreen();
  551.  
  552.     /*
  553.      * Draw an ellipse that fills the display in center
  554.      */
  555.     GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, GLCD.Width/2-1, GLCD.Height/2-1);
  556.  
  557.     /*
  558.      * A little animation for eye candy
  559.      */
  560.    
  561.     /*
  562.      * Fill pixels from inside out
  563.      */
  564.     for(int x = 1; x < GLCD.Height/2; x++)
  565.     {
  566.         GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, GLCD.Width/2-x, GLCD.Height/2-x);
  567.         delay(SDELAY/10);
  568.     }
  569.     /*
  570.      * remove pixels from inside out
  571.      */
  572.     for(int x = GLCD.Height/2; x > 0; x--)
  573.     {
  574.         GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, GLCD.Width/2-x, GLCD.Height/2-x, PIXEL_OFF);
  575.         delay(SDELAY/10);
  576.     }
  577.  
  578.     /*
  579.      * Fill pixels from inside out (as a circle)
  580.      */
  581.     for(int x = 1; x < GLCD.Height/2 -1; x++)
  582.     {
  583.         GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, x, x);
  584.         delay(SDELAY/10);
  585.     }
  586.     /*
  587.      * remove pixels from inside out (as a circle)
  588.      */
  589.     for(int x = GLCD.Height/2 -1; x > 1; x--)
  590.     {
  591.         GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, GLCD.Height/2-x, GLCD.Height/2-x, PIXEL_OFF);
  592.         delay(SDELAY/10);
  593.     }
  594.  
  595.     /*
  596.      * fill pixels from inside out starting as circle then expanding to ellipse
  597.      */
  598.     for(int x = 1; x < GLCD.Width/2 -1; x++)
  599.     {
  600.         if(x >= GLCD.Height/2)
  601.             GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, x, GLCD.Height/2-1);
  602.         else
  603.             GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, x, x);
  604.         delay(SDELAY/10);
  605.     }
  606.     /*
  607.      * erase pixels from inside out starting as circle then expanding to ellipse
  608.      */
  609.     for(int x = 1; x < GLCD.Width/2 -1; x++)
  610.     {
  611.         if(x >= GLCD.Height/2)
  612.             GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, x, GLCD.Height/2-1,PIXEL_OFF);
  613.         else
  614.             GLCD.DrawEllipse(GLCD.CenterX, GLCD.CenterY, x, x,PIXEL_OFF);
  615.         delay(SDELAY/10);
  616.     }
  617.  
  618.     delay(DELAY);
  619. }
  620.  
  621. void FillRect(void)
  622. {
  623.     GLCD.SelectFont(SystemFont5x7);
  624.     GLCD.SetDisplayMode(NON_INVERTED); // "normal" display mode
  625.     GLCD.ClearScreen();
  626.  
  627. //  GLCD.DrawString("FillRect", gTextfmt_center, gTextfmt_center);
  628.     /*
  629.      * Fill a rectangle
  630.      * 8 pixels in height 2 pixels from top of display
  631.      * 25 pixels in from each end
  632.      */
  633.     GLCD.FillRect(GLCD.Left+25, GLCD.Top+2, GLCD.Width-25*2, 8);
  634.     delay(DELAY/2);
  635.  
  636.     /*
  637.      * Fill a rectangle
  638.      * 8 pixels in height 2 pixels from bottom of display
  639.      * 25 pixels in from each end
  640.      */
  641.     GLCD.FillRect(GLCD.Left+25, GLCD.Bottom-8-2+1, GLCD.Width-25*2, 8);
  642.     delay(DELAY/2);
  643.  
  644.     /*
  645.      * Create a filled rectangle 15x15 pixels in each corner
  646.      */
  647.     draw4corners_FillRect(15, PIXEL_ON); // turn on the pixels
  648.  
  649.     /*
  650.      * erase a filled rectangle 10x10 pixels in each corner
  651.      */
  652.     draw4corners_FillRect(10, PIXEL_OFF); // turn off the pixels
  653.  
  654.     delay(DELAY/2);
  655.  
  656.     /*
  657.      * Now do it all over again in INVERTED mode
  658.      */
  659.     GLCD.SetDisplayMode(INVERTED); // "INVERTED" display mode
  660.     GLCD.ClearScreen();
  661. //  GLCD.DrawString("FillRect", gTextfmt_center, gTextfmt_center);
  662.  
  663.     /*
  664.      * Fill a rectangle
  665.      * 8 pixels in height 2 pixels from top of display
  666.      * 25 pixels in from each end
  667.      *
  668.      */
  669.     GLCD.FillRect(GLCD.Left+25, GLCD.Top+2, GLCD.Width-25*2, 8);
  670.  
  671.     delay(DELAY/2);
  672.     /*
  673.      * Fill a rectangle
  674.      * 8 pixels in height 2 pixels from bottom of display
  675.      * 25 pixels in from each end
  676.      */
  677.     GLCD.FillRect(GLCD.Left+25, GLCD.Bottom-8-2+1, GLCD.Width-25*2, 8);
  678.  
  679.     delay(DELAY/2);
  680.  
  681.     /*
  682.      * Create a filled rectangle 15x15 pixels in each corner
  683.      */
  684.     draw4corners_FillRect(15, PIXEL_ON); // turn on the pixels
  685.  
  686.     /*
  687.      * erase a filled rectangle 10x10 pixels in each corner
  688.      */
  689.     draw4corners_FillRect(10, PIXEL_OFF); // turn off the pixels
  690.  
  691.     GLCD.SetDisplayMode(NON_INVERTED); // "normal" display mode
  692.     delay(DELAY);
  693. }
  694.  
  695. /*
  696.  * create a filled in rectangle in each corner
  697.  * that is exactly size x size pixels.
  698.  */
  699. void draw4corners_FillRect(uint8_t size, uint8_t color)
  700. {
  701.     /*
  702.      * upper left corner
  703.      */
  704.     GLCD.FillRect(GLCD.Left, GLCD.Top, size, size, color);
  705.     delay(DELAY/2);
  706.  
  707.     /*
  708.      * upper right corner
  709.      */
  710.     GLCD.FillRect(GLCD.Right-size+1,GLCD.Top, size, size, color);
  711.     delay(DELAY/2);
  712.  
  713.     /*
  714.      * lower left corner
  715.      */
  716.     GLCD.FillRect(GLCD.Left,GLCD.Bottom-size+1, size, size, color);
  717.     delay(DELAY/2);
  718.  
  719.     /*
  720.      * Lower right corner
  721.      */
  722.     GLCD.FillRect(GLCD.Right-size+1,GLCD.Bottom-size+1, size, size, color);
  723.     delay(DELAY/2);
  724. }
  725. void FillRoundRect(void)
  726. {
  727. uint8_t color;
  728.  
  729.     GLCD.ClearScreen();
  730.  
  731.     /*
  732.      *  Draw filled rectangle on left half of display
  733.      * 4 pixels from left, 4 pixels down from top with radius of 10
  734.      */
  735.     GLCD.FillRoundRect(GLCD.Left+4, GLCD.Top+4, GLCD.Width/2 -2*4, GLCD.Height -2*4, 10);
  736.  
  737.     /*
  738.      *  Draw filled rectangle on right half of display
  739.      * 4 pixels to right of center, 4 pixels down from top with radius of 10
  740.      */
  741.     GLCD.FillRoundRect(GLCD.CenterX+4, GLCD.Top+4, GLCD.Width/2 -2*4, GLCD.Height -2*4, 10);
  742.  
  743.     delay(DELAY);
  744.  
  745.     GLCD.ClearScreen();
  746.  
  747.     /*
  748.      * Draw Filled Rounded rectangles on the display every 8 pixels starting
  749.      * from the outside and move in alternating colors;
  750.      */
  751.     color = PIXEL_ON;
  752.     for(uint8_t i = 0; i < GLCD.Bottom/2-8; i +=8)
  753.     {
  754.         GLCD.FillRoundRect(GLCD.Left + i,GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i, 10,  color);
  755.  
  756.         if(color == PIXEL_ON)
  757.             color = PIXEL_OFF;
  758.         else
  759.             color=PIXEL_ON;
  760.  
  761.         delay(DELAY/2);
  762.     }
  763.  
  764.     delay(DELAY);
  765.  
  766.     GLCD.ClearScreen();
  767.  
  768.     /*
  769.      * Draw Filled Rounded rectangles on the display every 8 pixels starting
  770.      * from the outside and move in alternating colors;
  771.      * (Different corner radius from above)
  772.      */
  773.     color = PIXEL_ON;
  774.     for(uint8_t i = 0; i < GLCD.Bottom/2-8; i +=8)
  775.     {
  776.         GLCD.FillRoundRect(GLCD.Left + i,GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i, 15, color);
  777.  
  778.         if(color == PIXEL_ON)
  779.             color = PIXEL_OFF;
  780.         else
  781.             color=PIXEL_ON;
  782.         delay(DELAY/2);
  783.     }
  784.  
  785.    
  786.     delay(DELAY);
  787. }
  788. void FillTriangle(void)
  789. {
  790.     GLCD.ClearScreen();
  791.     /*
  792.      * Draw a triangle between points:
  793.      * - upper left corner
  794.      * - center of screen
  795.      * - upper right corner
  796.      */
  797.     GLCD.DrawTriangle(GLCD.Left,GLCD.Top, GLCD.CenterX,GLCD.CenterY, GLCD.Right,GLCD.Top);
  798.  
  799.     /*
  800.      * Draw a triangle between points:
  801.      * - lower left corner
  802.      * - center of screen
  803.      * - bottom right corner
  804.      */
  805.     GLCD.DrawTriangle(GLCD.Left,GLCD.Bottom, GLCD.CenterX,GLCD.CenterY, GLCD.Right,GLCD.Bottom);
  806.  
  807.     delay(DELAY);
  808.  
  809.  
  810.     /*
  811.      * Fill a triangle between points:
  812.      * - upper left corner
  813.      * - center of screen
  814.      * - upper right corner
  815.      */
  816.     GLCD.FillTriangle(GLCD.Left,GLCD.Top, GLCD.CenterX,GLCD.CenterY, GLCD.Right,GLCD.Top);
  817.  
  818.     /*
  819.      * Fill a triangle between points:
  820.      * - lower left corner
  821.      * - center of screen
  822.      * - bottom right corner
  823.      */
  824.     GLCD.FillTriangle(GLCD.Left,GLCD.Bottom, GLCD.CenterX,GLCD.CenterY, GLCD.Right,GLCD.Bottom);
  825.  
  826.     delay(DELAY);
  827. }
  828.  
  829. void InvertRect(void)
  830. {
  831.     GLCD.ClearScreen();
  832.  
  833.     /*
  834.      * Draw rectangles on the display every 4 pixels starting
  835.      * from the outsided and move in.
  836.      */
  837.     for(uint8_t i = 0; i < GLCD.Bottom/2; i +=4)
  838.     {
  839.         GLCD.DrawRect(GLCD.Left+i, GLCD.Top+i, GLCD.Width - 2*i, GLCD.Height - 2*i);
  840.     }
  841.  
  842.     delay(DELAY);
  843.     /*
  844.      * invert the entire display
  845.      */
  846.  
  847.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width, GLCD.Height);
  848.     delay(DELAY/2);
  849.     /*
  850.      * invert the entire display to put it back
  851.      */
  852.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width, GLCD.Height);
  853.     delay(DELAY);
  854.  
  855.     /*
  856.      * invert the left side of display
  857.      */
  858.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width/2, GLCD.Height);
  859.     delay(DELAY/2);
  860.  
  861.     /*
  862.      * invert the left side of display to put it back
  863.      */
  864.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width/2, GLCD.Height);
  865.     delay(DELAY);
  866.  
  867.     /*
  868.      * invert the right side of display
  869.      */
  870.     GLCD.InvertRect(GLCD.CenterX, GLCD.Top, GLCD.Width/2, GLCD.Height);
  871.     delay(DELAY/2);
  872.  
  873.     /*
  874.      * invert the right side of display to put it back
  875.      */
  876.     GLCD.InvertRect(GLCD.CenterX, GLCD.Top, GLCD.Width/2, GLCD.Height);
  877.     delay(DELAY);
  878.  
  879.     /*
  880.      * invert the top half of display
  881.      */
  882.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width, GLCD.Height/2);
  883.     delay(DELAY/2);
  884.  
  885.     /*
  886.      * invert the top half of display to put it back
  887.      */
  888.     GLCD.InvertRect(GLCD.Left, GLCD.Top, GLCD.Width, GLCD.Height/2);
  889.     delay(DELAY);
  890.  
  891.     /*
  892.      * invert the Bottom half of display
  893.      */
  894.     GLCD.InvertRect(GLCD.Left, GLCD.CenterY, GLCD.Width, GLCD.Height/2);
  895.     delay(DELAY/2);
  896.  
  897.     /*
  898.      * invert the Bottom half of display to put it back
  899.      */
  900.     GLCD.InvertRect(GLCD.Left, GLCD.CenterY, GLCD.Width, GLCD.Height/2);
  901.     delay(DELAY);
  902. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement