How to draw a smooth curve by point input

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • How to draw a smooth curve by point input

      I need to draw a curve according to the input point. Every time I input a point curve to the left, the GUI_AA_DrawLine method between the point and the point is used to draw a line, so the whole curve is not very smooth, not beautiful enough, I want to ask you There is no better way to handle it and achieve a smooth curve.
    • Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Regards,
      Sven
    • SEGGER - Schoenen wrote:

      Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Regards,
      Sven
      Thank you. It solved my problem.
    • SEGGER - Schoenen wrote:

      Hi,

      Since version 5.44 of emWin it is possible to draw splines resulting in smooth curves.

      Here is a short example:

      C Source Code

      1. #include "GUI.h"
      2. /*********************************************************************
      3. *
      4. * Defines
      5. *
      6. **********************************************************************
      7. */
      8. #define TEMP_MULTIPLY 5
      9. /*********************************************************************
      10. *
      11. * Static data
      12. *
      13. **********************************************************************
      14. */
      15. static const int _axi[] = {
      16. 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240
      17. };
      18. static const int _ayi[3][13] = {
      19. { 8, 7, 6, 7, 8, 11, 14, 16, 18, 16, 13, 9, 7 },
      20. { 7, 7, 6, 6, 8, 11, 14, 15, 15, 14, 13, 8, 7 },
      21. { 7, 6, 5, 4, 5, 8, 9, 12, 14, 12, 11, 8, 6 }
      22. };
      23. static GUI_COLOR _aColor[] = {
      24. GUI_RED, GUI_GREEN, GUI_LIGHTBLUE
      25. };
      26. /*********************************************************************
      27. *
      28. * Static code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * _DrawSplines
      35. */
      36. static void _DrawSplines(void) {
      37. GUI_HMEM hSpline;
      38. U32 NumPoints;
      39. int aTemp[3][13];
      40. int i, j;
      41. for (i = 0; i < GUI_COUNTOF(_ayi); i++) {
      42. for (j = 0; j < GUI_COUNTOF(_ayi[i]); j++) {
      43. aTemp[i][j] = _ayi[i][j] * TEMP_MULTIPLY * -1;
      44. }
      45. NumPoints = GUI_COUNTOF(_axi);
      46. hSpline = GUI_SPLINE_Create(_axi, aTemp[i], NumPoints);
      47. GUI_SetColor(_aColor[i]);
      48. GUI_SetDrawMode(GUI_DM_TRANS);
      49. GUI_SPLINE_DrawAA(hSpline, 20, 100, 0);
      50. GUI_SPLINE_DrawAA(hSpline, 20, 150, 3);
      51. GUI_SetDrawMode(GUI_DM_NORMAL);
      52. GUI_SPLINE_DrawAA(hSpline, 20, 200, 0);
      53. GUI_SPLINE_DrawAA(hSpline, 20, 250, 3);
      54. GUI_SPLINE_Delete(hSpline);
      55. }
      56. }
      57. /*********************************************************************
      58. *
      59. * Public code
      60. *
      61. **********************************************************************
      62. */
      63. /*********************************************************************
      64. *
      65. * MainTask
      66. */
      67. void MainTask(void) {
      68. GUI_Init();
      69. _DrawSplines();
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Regards,
      Sven
      Hello Sven,

      I will like to use the spline features and I tried your example on both custom hardware and an STM32 Demoboard (STM32F46G-DISCO) and in both cases it gives me a linker errors:


      Source Code

      1. compiling splines_app.c...
      2. linking...
      3. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_Create (referred from splines_app.o).
      4. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_Delete (referred from splines_app.o).
      5. STM32746G_DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol GUI_SPLINE_DrawAA (referred from splines_app.o).
      6. Not enough information to list image symbols.
      7. Not enough information to list load addresses in the image map.
      Display All

      Emwin version is GUI_VERSION 54401.

      Am I missing anything?

      Thank you.
      Mark
    • SEGGER - Schoenen wrote:

      Hi Mark,

      That's interesting, I have checked V5.44a but the spline related functions are present.

      Did you updated from an older version to 5.44a?
      Maybe something went wrong in this process.

      If can get hands on a newer version you should give that a try.

      Regards,
      Sven
      Hi Sven, thank you for your answer.

      First I've tried updating an older library version (5.40) to the last present on the STM32Cube_FW_F7_V1.15.0 which is the 5.44 mentioned before.
      The result was I got those linker errors.

      Then I've tried using your example on the "Animation example" on the same package STM32Cube_FW_F7_V1.15.0 on the STM32 Demoboard mentioned before.
      The result was the same.

      On the GUI.h file the prototype functions are present though.

      I'll try downloading a newer version from emWin website then.

      Regards,
      Mark