extern "C" { #include #include #include } #include #include "utils.h" void draw_lines_from_center() { KDCoordinate width = SCREEN_WIDTH; KDCoordinate height = SCREEN_HEIGHT; KDColor c = 0xFF; KDPoint center = KDPointMake(width/2, height/2); int step = 2; for (KDCoordinate x=0; xapproximate(plotContext); KDCoordinate j = ((y-yMin)/(yMax-yMin)*screenHeight); KDPoint currentPoint = KDPointMake(i,screenHeight-j); if (i>0) { KDDrawLine(previousPoint, currentPoint, 0xFF); } previousPoint = currentPoint; } } void funnyPlot() { Expression * e = Expression::parse((char *)"1/x"); plot(e, 1.0f, 4.0f, 0.0f, 1.0f); delete e; } static void interactive_expression_parsing() { while (1) { char * text_input = get_text(); clear_screen(); Expression * e = Expression::parse(text_input); if (e) { ExpressionLayout * l = e->createLayout(); int16_t yOffset = 10; if (l) { l->draw(KDPointMake(0, yOffset)); yOffset += l->size().height; delete l; } Expression * simplified = e->simplify(); // Print the simplification. if (simplified) { ExpressionLayout * simplified_l = simplified->createLayout(); if (simplified_l) { int16_t xOffset = SCREEN_WIDTH - simplified_l->size().width; simplified_l->draw(KDPointMake(xOffset, yOffset)); delete simplified_l; } if (simplified != e) { delete simplified; } } delete e; } else { KDDrawString("PARSING ERROR", KDPointMake(10,10), 0); } // We dealocate the memory allocated by get_text; free(text_input); } } void ion_app() { interactive_expression_parsing(); while (1) { ion_sleep(); } }