Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The Equation Paint (v 0.01) on Linux Console!
- * Copyright ©2011 - @uthor #Utroz(RsC)#.
- * File: global.h
- * Blog: http://OAKcoders.com/ (Access it)!
- */
- /* Equation Size */
- #define MAX 30
- typedef char string[MAX];
- /* Software Version */
- #define SOFTWARE_VERSION 0.01
- /* Errors ID's */
- #define ERROR_X -1 // Don't find x.
- /* Graphics ID */
- #define ARROW_NORTH '^'
- #define ARROW_RIGHT '>'
- #define ARROW_LEFT '<'
- #define ARROW_SOUTH 'v'
- #define V '|' /* Vertical */
- #define H '-' /* Horizontal */
- #define POINT '*'
- /* Signal Status */
- #define POS_NUM 0 /* Positive Number */
- #define NEG_NUM 1 /* Negative Number */
- /* Graphic Paint Size */
- #define GS 10
- //------------
- /* The Equation Paint (v 0.01) on Linux Console!
- * Copyright ©2011 - @uthor #Utroz(RsC)#.
- * File: main.c
- * Blog: http://OAKcoders.com/ (Access it)!
- */
- #include "global.h"
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- string str;
- int equ_status, value_x;
- float cord[3];
- size_t equation;
- printf("\tWelcome to Equation Paint (v %.2f) by Utroz!\n\tPlease access http://Oakcoders.com/ to more informations.\n", SOFTWARE_VERSION);
- do
- {
- printf("\n\tPlease input a First Degree Equation: ");
- fgets(str, MAX, stdin);
- puts("\n");
- /* Receive POS_X or error */
- equ_status = check_syntax(str, strlen(str));
- } while(equ_status == ERROR_X);
- /* Catch previous value of x */
- value_x = catch_pre_x(str, equ_status);
- /* Send previous value of x to
- * cordenate calculate */
- calc_cordenates(cord, value_x);
- /* Catch array size and put on
- * equation variable and
- * show results on log */
- equation = sizeof(cord)/sizeof(cord[0]);
- log_msg(value_x, cord, equation, str);
- /* Reorganize array removing
- * x and previous value of x
- * after print this value */
- sort_array(str, strlen(str), equ_status);
- /* Starting calculus and
- * after show this on log */
- start_calc(str, cord);
- log_msg(value_x, cord, sizeof(cord)/sizeof(cord[0]), str);
- /* Show results on cordenates graphic */
- show_cordenates(cord, sizeof(cord)/sizeof(cord[0]));
- show_graphics(cord, sizeof(cord)/sizeof(cord[0]));
- return 0;
- }
- //------------
- /* The Equation Paint (v 0.01) on Linux Console!
- * Copyright ©2011 - @uthor #Utroz(RsC)#.
- * File: first_degree.h
- * Blog: http://OAKcoders.com/ (Access it)!
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include "global.h"
- int check_syntax(char *args, int argc);
- int catch_pre_x(char *args, int pos_x);
- void calc_cordenates(float *args, int arg_x);
- void sort_array(char *args, int argc, int pos_x);
- void start_calc(char *args, float *arg_f);
- int check_signal(char * args);
- /* This function Search by X */
- int check_syntax(char *args, int argc)
- {
- int pos_x;
- for(pos_x = 0; pos_x < argc; pos_x++)
- {
- /* Searching by X */
- if(args[pos_x] == 'x' || args[pos_x] == 'X')
- return pos_x;
- }
- /* If don't find to letter 'X', ERROR_X return! */
- return ERROR_X;
- }
- /* This function converts a previous value of x. */
- int catch_pre_x(char *args, int pos_x)
- {
- char *tmp; /* Temporary Pointer */
- int previous_x = 0, i;
- tmp = (char *) malloc(pos_x-1);
- /* Catching number value */
- for(i = 0; i < pos_x; i++)
- tmp[i] = args[i];
- /* Converting to integer */
- previous_x = atoi(tmp);
- free(tmp);
- return previous_x;
- }
- /* Calculate cordenates with X(-1,0,1) */
- void calc_cordenates(float *args, int arg_x)
- {
- args[0] = arg_x * -1;
- args[1] = arg_x * 0;
- args[2] = arg_x * 1;
- }
- /* Define array only with values after of x */
- void sort_array(char *args, int argc, int pos_x)
- {
- int i, aux = 0;
- for(i = pos_x+1; i < argc; i++)
- {
- /* Resorting... */
- args[aux++] = args[i];
- args[i] = 0;
- }
- }
- /* Starting Calculations */
- void start_calc(char *args, float *arg_f)
- {
- int signal, number_;
- /* Check equation signal */
- signal = check_signal(args);
- /* Converting number to integer */
- number_ = atoi(args);
- /* Calculate coordinate Y
- with base on signal */
- if(signal == POS_NUM)
- {
- arg_f[0] += number_;
- arg_f[1] += number_;
- arg_f[2] += number_;
- }
- else
- {
- arg_f[0] -= number_;
- arg_f[1] -= number_;
- arg_f[2] -= number_;
- }
- printf("\tSignal: [%d] / Value: [%d]\n", signal, number_);
- }
- /* This function check the equation signal */
- int check_signal(char *args)
- {
- if(args[0] == '+') return POS_NUM;
- return NEG_NUM;
- }
- //------------
- /* The Equation Paint (v 0.01) on Linux Console!
- * Copyright ©2011 - @uthor #Utroz(RsC)#.
- * File: paint_graphics.h
- * Blog: http://OAKcoders.com/ (Access it)!
- */
- #include <stdio.h>
- #include <string.h>
- #include "global.h"
- void log_msg(int arg_x, float *arg_f, size_t argc, char *args);
- void show_cordenates(float *arg_f, size_t argc);
- void show_graphics(float *arg_f, size_t argc);
- void create_map(char args[][GS], int argc);
- /* This function is responsible to
- * showing calculus record */
- void log_msg(int arg_x, float *arg_f, size_t argc, char *args)
- {
- int i;
- /* Previous value of x */
- printf("\tPrevious: %d\n", arg_x);
- /* Show cordenates result */
- for(i = 0; i < argc; i++)
- printf("\tFloat [%d]: %.1f\n", i-1, arg_f[i]);
- printf("\tCurrent Equation: %s\n", args);
- }
- /* Showing cordenates of x,y point */
- void show_cordenates(float *arg_f, size_t argc)
- {
- int i;
- printf("\t--------------------\n");
- printf("\t- Cordenates:\n");
- printf("\tx\t|\ty\n");
- printf("\t--------------------\n");
- for(i = 0; i < argc; i++)
- printf("\t%d\t|\t%2.1f\n", i-1, arg_f[i]);
- printf("\t--------------------\n");
- getchar();
- }
- /* Showing graphic cordenates
- * of x,y point */
- void show_graphics(float *arg_f, size_t argc)
- {
- /* (GS) is a graphic size constant defined
- * on global.h */
- int i, j; // Line / Column
- char tmp[GS][GS];
- create_map(tmp, GS);
- printf("\n\t--------------------\n");
- printf("\t- Equation Graphic:\n");
- printf("\t--------------------\n");
- /* Put arrow details on
- * graphic vertex */
- tmp[0][ (GS-1)/2 ] = ARROW_NORTH;
- tmp[GS-1][ (GS-1)/2 ] = ARROW_SOUTH;
- tmp[ (GS-1)/2 ][0] = ARROW_LEFT;
- tmp[ (GS-1)/2 ][GS-1] = ARROW_RIGHT;
- /* Creating x vertex(line) */
- for(i = 1; i < GS-1; i++)
- tmp[i][ (GS-1)/2 ] = V;
- tmp[( (GS-1)/2) -1 ][(GS-1)] = 'x';
- /*---------------------*/
- /* Creating y vertex(line) */
- for(i = 1; i < GS-1; i++)
- tmp[ (GS-1)/2 ][i] = H;
- tmp[0][ ((GS-1)/2) -1 ] = 'y';
- /*---------------------*/
- /* Put Default X Cordenates (-1,0,1) */
- tmp[ ((GS-1)/2) +1 ] [ ((GS-1)/2) -1 ] = '1';
- tmp[ ((GS-1)/2) +1 ] [ ((GS-1)/2) +1 ] = '1';
- /* Print Graphic */
- for(i = 0; i < GS; i++)
- {
- printf("\n\n");
- for(j = 0; j < GS; j++)
- printf(" %c ", tmp[i][j]);
- }
- puts("\n");
- getchar();
- }
- /* Creating graphic map */
- void create_map(char args[][GS], int argc)
- {
- int i, j;
- for(i = 0; i < argc; i++)
- {
- for(j = 0; j < argc; j++)
- args[i][j] = ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement