Thread: Help with a C program (linux) to do graphics using characters

  1. #16
    Registered User
    Join Date
    Jun 2013
    Posts
    11
    Quote Originally Posted by rcgldr View Post

    You should also have a check to prevent index from becoming < 0 or > 64.
    Have you downloaded my program? I do not understand what are you saying.. Please put an example code , because i can see it more easy, just an example if you do not wanna download my code.

  2. #17
    Registered User
    Join Date
    Jun 2013
    Posts
    11
    Please help this is for tomorrow don't let me die! I still don't knowing how to make a graph in my code.. I try.. and try.. and try... but nothing! Please download my code and help me! It's only that! Or tell me and i put my code here..!

  3. #18
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    It's probably too late, but the next time you should post your code here in the forum instead of putting it somewhere to download.

    Additionally, you should only post the part you have problems with. The number of people who are willing to help you is usually inversely proportional to the number of code lines you post.

    Bye, Andreas

  4. #19
    Registered User
    Join Date
    Jun 2013
    Posts
    11
    Quote Originally Posted by AndiPersti View Post
    It's probably too late, but the next time you should post your code here in the forum instead of putting it somewhere to download.

    Additionally, you should only post the part you have problems with. The number of people who are willing to help you is usually inversely proportional to the number of code lines you post.

    Bye, Andreas
    I have time, is for today up to 12pm please help.

    This is a part of my code, in the graphic.c that draw the grid

    Code:
    void DrawGrid(char canvas[PG_MAX_VERTICAL][PG_MAX_HORIZONTAL],int valuex,int valuey,double jumpy,double jumpx,int widthdiv,int highdiv){
        int i,j;
        int width=(jumpx-1)*widthdiv,high=(jumpy-1)*highdiv;
        int xs,ys;
        double tampasoy = valuey/(jumpy-1); 
        double tampasox = valuex/(jumpx-1);
        double valuepointy = tampasoy/highdiv;
        double valuepointy = tampasox/widthdiv;
      
        /*left vertical enumeration*/
        char buffer[30]="";
        
        xs=0;
        double enumy=0;
        int maxlongbuffer=0;
        for(i=high;i>=0;i--){
            if((xs%highdiv)==0){
                 
                 sprintf(buffer, "%.1f",enumy);   
                 int longbuffer = strlen(buffer);
                 if(longbuffer>maxlongbuffer)
                     maxlongbuffer = longbuffer;
                 int ibuffer;//Counter to cycle buffer
                 
                 for(ibuffer=0;ibuffer<longbuffer;ibuffer++)
                     canvas[i][ibuffer] = buffer[ibuffer];
                 
                 enumy+=tampasoy;
                 
                }
            xs++;
        }
        maxlongbuffer++;
        /*end of left vertical enumeration*/
        /*lower horizontal enumeration*/
       ys=0; 
       double enumx=0;
       for(j=maxlongbuffer ;j<(width+1+maxlongbuffer);j++){
           
           if((ys%widthdiv)==0){
                    
                 sprintf(buffer, "%.1f",enumx);   
                 int longbuffer = strlen(buffer);
                 int ibuffer;
                 
     
                 for(ibuffer=0;ibuffer<longbuffer;ibuffer++)
                     canvas[alto+1][ibuffer+j] = buffer[ibuffer];
                 
                 enumx+=tampasox;
           }
           ys++;
       }
        
        /*end of lower horizontal enumeration*/
        /*Making the grid*/
        xs=0;ys=0;
        for(i=high;i>=0;i--){
            ys=0;
            for(j=maxlongbuffer;j<(width+1+maxlongbuffer);j++){
               
                if((xs%highdiv)==0){
                    if((ys%widthdiv)==0)
                    canvas[i][j]='+';
                    else    
                    canvas[i][j]='-';   
                }
                
                if((xs%highdiv)!=0){
                        if((ys%widthdiv)==0)
                        canvas[i][j]='|';
                } 
                ys++;         
            }
            xs++;
        }
        /*end of making the grid*/
        
        
    }
    And this are my declarations on the header file (.h)

    Code:
    #define MAX_SCREEN_AREA 100
    #define PG_MAX_HORIZONTAL 80
    #define PG_MAX_VERTICAL 40
    #define PG_MAX_SERIES 40
    I only need 2 functions that let me graph in the grid.. Like an sin function, or circle, or straight line, or parable.. I need two.. But i don't know how to do that... really.. i was trying and trying.. but nothing... Please help!!

  5. #20
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Eduard Perez View Post
    This is a part of my code, in the graphic.c that draw the grid
    I personally wouldn't store the labels in the grid array. IMHO this makes the code unnecessarily more complex.

    Quote Originally Posted by Eduard Perez View Post
    I only need 2 functions that let me graph in the grid.. Like an sin function, or circle, or straight line, or parable.. I need two.. But i don't know how to do that... really.. i was trying and trying.. but nothing...
    Animal Nominal told you already that the method is the same as using pen and graph paper. The grid array will be your graph paper.
    So sit down and try to find a step-by-step solution graphing a function on paper. If you can't do it on paper you won't be able to write a program.

    Bye, Andreas

  6. #21
    Registered User
    Join Date
    Jun 2013
    Posts
    11
    So, how can i make the code less complex?

    And ok, i already have a paper, and trying to find how can i graph a function (positive) in my grid.. I know the idea, but translate it code, it's difficult to me... And i don't have so much time!! Please help me, i will send the program today at 11:00pm but i wanna take time to analyze the code, the program... But just help me, i'm out of time and i have to make a report of the program Please!!!

  7. #22
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Eduard Perez View Post
    So, how can i make the code less complex?
    Don't store the labels for the axes in the grid array. You only need them when you display the grid on the screen. If you do like Nominal Animal suggested (putting a '\0' at the end of each row) you just need to print a label for the y-axis in front of the row:
    Code:
    // if you need to print a label
    printf("%5.4g %s", label_value, row);
    // else
    printf("      %s", row);
    Quote Originally Posted by Eduard Perez View Post
    And i don't have so much time!! Please help me, i will send the program today at 11:00pm but i wanna take time to analyze the code, the program... But just help me, i'm out of time and i have to make a report of the program Please!!!
    Stop whining about having no time. It's your problem if you've started too late not ours. And we won't write the program for you (at least I will not).

    Bye, Andreas

  8. #23
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by Eduard Perez View Post
    how can i graph a function (positive) in my grid.
    Assuming your graph can handle numbers in the range 0 to 64, try these equations for x = 10 to x = 54 ... for(x = 10.; x < 54.5; x += 1.){ ... .

    y = ((x-32.)^2.)/8. + 2.5

    y = ((x-32.)^3.)*(1/96.) - (x-32.)*(121./32.) + 32.5

    (The .5 is for rounding).

    Then just plot the results you get for each pair of x and y for the first equation, then again for the second equation. You'll need to learn how to scale more general functions.
    Last edited by rcgldr; 06-09-2013 at 04:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux Graphics Engine
    By drdroid in forum Linux Programming
    Replies: 1
    Last Post: 09-28-2003, 06:08 PM
  2. Graphics in Linux
    By ashesh in forum C Programming
    Replies: 0
    Last Post: 12-12-2002, 04:31 AM
  3. Graphics in Linux
    By Xterria in forum Game Programming
    Replies: 3
    Last Post: 08-12-2002, 03:43 PM
  4. Blitting characters in graphics modes
    By SMurf in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-05-2002, 12:08 PM
  5. Graphics won't print characters
    By cheesehead in forum C++ Programming
    Replies: 0
    Last Post: 11-12-2001, 11:45 AM