diff options
author | Joel Bodenmann <joel@seriouslyembedded.com> | 2016-01-08 07:27:26 +0100 |
---|---|---|
committer | Joel Bodenmann <joel@seriouslyembedded.com> | 2016-01-08 07:27:26 +0100 |
commit | 6937cc3f0ffc3001e483b13629c246dcaddb62fe (patch) | |
tree | ad290790b4ccf946f00e6c518db9850ffb6b7c0e /demos/modules/gwin | |
parent | 4b891ebc0413129dbea0b3137467db1263f848f4 (diff) | |
download | uGFX-6937cc3f0ffc3001e483b13629c246dcaddb62fe.tar.gz uGFX-6937cc3f0ffc3001e483b13629c246dcaddb62fe.tar.bz2 uGFX-6937cc3f0ffc3001e483b13629c246dcaddb62fe.zip |
Adding comments to graph demo
Diffstat (limited to 'demos/modules/gwin')
-rw-r--r-- | demos/modules/gwin/graph/main.c | 127 |
1 files changed, 67 insertions, 60 deletions
diff --git a/demos/modules/gwin/graph/main.c b/demos/modules/gwin/graph/main.c index 4273b750..e0d82271 100644 --- a/demos/modules/gwin/graph/main.c +++ b/demos/modules/gwin/graph/main.c @@ -30,75 +30,82 @@ #include "gfx.h" #include "math.h" +// A set of data points that will be displayed in the graph static const point data[5] = { - { -40, -40 }, - { 70, 40 }, - { 140, 60 }, - { 210, 60 }, - { 280, 200 } + { -40, -40 }, + { 70, 40 }, + { 140, 60 }, + { 210, 60 }, + { 280, 200 } }; -static GGraphObject g; - +// A graph styling static GGraphStyle GraphStyle1 = { - { GGRAPH_POINT_DOT, 0, Blue }, // point - { GGRAPH_LINE_NONE, 2, Gray }, // line - { GGRAPH_LINE_SOLID, 0, White }, // x axis - { GGRAPH_LINE_SOLID, 0, White }, // y axis - { GGRAPH_LINE_DASH, 5, Gray, 50 }, // x grid - { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // y grid - GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // flags + { GGRAPH_POINT_DOT, 0, Blue }, // Point + { GGRAPH_LINE_NONE, 2, Gray }, // Line + { GGRAPH_LINE_SOLID, 0, White }, // X axis + { GGRAPH_LINE_SOLID, 0, White }, // Y axis + { GGRAPH_LINE_DASH, 5, Gray, 50 }, // X grid + { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // Y grid + GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // Flags }; +// Another graph styling static const GGraphStyle GraphStyle2 = { - { GGRAPH_POINT_SQUARE, 5, Red }, // point - { GGRAPH_LINE_DOT, 2, Pink }, // line - { GGRAPH_LINE_SOLID, 0, White }, // x axis - { GGRAPH_LINE_SOLID, 0, White }, // y axis - { GGRAPH_LINE_DASH, 5, Gray, 50 }, // x grid - { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // y grid - GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // flags + { GGRAPH_POINT_SQUARE, 5, Red }, // Point + { GGRAPH_LINE_DOT, 2, Pink }, // Line + { GGRAPH_LINE_SOLID, 0, White }, // X axis + { GGRAPH_LINE_SOLID, 0, White }, // Y axis + { GGRAPH_LINE_DASH, 5, Gray, 50 }, // X grid + { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // Y grid + GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // Flags }; - + int main(void) { - GHandle gh; - uint16_t i; - - gfxInit(); - - { - GWindowInit wi; - - gwinClearInit(&wi); - wi.show = TRUE; - wi.x = wi.y = 0; - wi.width = gdispGetWidth(); - wi.height = gdispGetHeight(); - gh = gwinGraphCreate(&g, &wi); - } - - gwinGraphSetOrigin(gh, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2); - gwinGraphSetStyle(gh, &GraphStyle1); - gwinGraphDrawAxis(gh); - - for(i = 0; i < gwinGetWidth(gh); i++) - gwinGraphDrawPoint(gh, i-gwinGetWidth(gh)/2, 80*fsin(2*i/5)); //sin(2*0.2*GFX_PI*i/180)); + GHandle gh; + uint16_t i; + + gfxInit(); + + // Create the graph window + { + GWindowInit wi; + + wi.show = TRUE; + wi.x = wi.y = 0; + wi.width = gdispGetWidth(); + wi.height = gdispGetHeight(); + gh = gwinGraphCreate(0, &wi); + } + + // Set the graph origin and style + gwinGraphSetOrigin(gh, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2); + gwinGraphSetStyle(gh, &GraphStyle1); + gwinGraphDrawAxis(gh); + + // Draw a sine wave + for(i = 0; i < gwinGetWidth(gh); i++) { + gwinGraphDrawPoint(gh, i-gwinGetWidth(gh)/2, 80*sin(2*0.2*M_PI*i/180)); + } + + // Modify the style + gwinGraphStartSet(gh); + GraphStyle1.point.color = Green; + gwinGraphSetStyle(gh, &GraphStyle1); + + // Draw a different sine wave + for(i = 0; i < gwinGetWidth(gh)*5; i++) { + gwinGraphDrawPoint(gh, i/5-gwinGetWidth(gh)/2, 95*sin(2*0.2*M_PI*i/180)); + } - gwinGraphStartSet(gh); - GraphStyle1.point.color = Green; - gwinGraphSetStyle(gh, &GraphStyle1); - - for(i = 0; i < gwinGetWidth(gh)*5; i++) - gwinGraphDrawPoint(gh, i/5-gwinGetWidth(gh)/2, 95*fsin(2*i/5)); //sin(2*0.2*GFX_PI*i/180)); + // Change to a completely different style + gwinGraphStartSet(gh); + gwinGraphSetStyle(gh, &GraphStyle2); - gwinGraphStartSet(gh); - gwinGraphSetStyle(gh, &GraphStyle2); - - gwinGraphDrawPoints(gh, data, sizeof(data)/sizeof(data[0])); - - while(TRUE) { - gfxSleepMilliseconds(100); - } + // Draw a set of points + gwinGraphDrawPoints(gh, data, sizeof(data)/sizeof(data[0])); + + while(TRUE) { + gfxSleepMilliseconds(100); + } } - - |