LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2006, 02:03 PM   #1
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Rep: Reputation: 15
Unhappy how to plot a curve in linux?


hi
i want to plot a curve in linux using c language
can u help me in that
i 've a freind that told me that i must use the library gtk or qt

can any one help me in installing that library ?
plz i need help
 
Old 10-16-2006, 03:22 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,697

Rep: Reputation: 232Reputation: 232Reputation: 232
You probably already have them installed, as Gnome is based on GTK and KDE is based on Qt. What you may be missing are headers. Run your package manager and install all gtk*devel and qt*devel packages you can find.

If you prefer pure C, you need to stick with Gtk. Qt uses C++ (GTK works in both C and C++).

The thing is what you need to do with the curve. If just save to a file - you may deal with .bmp, .png or .gif manually. If you plan to show it, using Qt or GTK is the right thing to do.
 
Old 10-16-2006, 03:32 PM   #3
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
ok i will explain what i want exactly

i have suse
i make this program


#include<stdio.h>


main()
{
printf("hello evrey body \n");

# here i want to plot a line or a curve or smthg graphic


exit(0);
}
i save it as myprog.c

then i compile using gcc -o myprog myprog.c
how can i add the gtk?
plz i'm a newbee with this gtk ...
be easy with me
 
Old 10-17-2006, 12:06 AM   #4
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
any help plz
 
Old 10-17-2006, 03:25 PM   #5
Youri
Member
 
Registered: Oct 2004
Distribution: slamd64-current, slackware-current, clfs 6.1, arch-current, ubuntu dapper
Posts: 144

Rep: Reputation: 15
google for the expression "c tutorial" or "c++ tutorial" or "gtk tutorial"
 
Old 10-18-2006, 03:59 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,697

Rep: Reputation: 232Reputation: 232Reputation: 232
This may ba helpful: http://www.gtkmm.org/docs/gtkmm-2.4/...l/ch15s03.html
It's in C++, but functions in C do the same and have nearly the same names.
 
Old 10-18-2006, 04:16 PM   #7
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
our teacher want only c language and not c++
 
Old 10-19-2006, 01:01 AM   #8
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hello, spinal2 !

I suggest you to use the `plotutils' package:
http://directory.fsf.org/graphics/plotutils.html
http://www.gnu.org/software/plotutils/plotutils.html

GTK and QT is a libs for GUI-creation. If you need just one window without any menus, buttons etc., then `plotutils' or smth. like is the best choice.

There is a good documentation, see
Code:
info plotutils  --> libplot
This package consists of a plotting C-library `libplot' and a bunch of utilities (graph, plot, ode,...).

PS: I prefer to save data to file or use pipes:
Code:
my-program | graph -CTX
Hope, this is useful.
 
Old 10-19-2006, 11:04 AM   #9
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
it's a shell command
i want a command which i use in the c compilor
 
Old 10-19-2006, 11:48 AM   #10
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
I seriously doubt your teacher wants you to use any graphics libraries - you probably want to use some sort of character placement method (a function that places a character at an arbitrary location on the screen), and use sine or somesuch to determine where to place each individual character.

In other words, say you want to limit the output to 10 lines, and you want it displayed on a sine curve. You would want to have the initial 'h' on line 5 or 6, then place each of the next characters one column forward but up towards line 1, then when you reach line 1 start placing characters downwards until line 10 and so on.

Anyway, I hope you get the idea.
 
Old 10-20-2006, 05:57 AM   #11
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Quote:
Originally Posted by spinal2
it's a shell command
i want a command which i use in the c compilor
If you download, compile and install plotutils package (or install .deb package), you'll get the `libplot' library installed on your system.

Then you must read documentation (info plotutils), and find there examples, written in C. If you copy sample code to the file (example.c) and compile it as follows:
Code:
gcc example.c -lplot
you'll get executable file a.out.

Bye.
 
Old 10-21-2006, 01:45 AM   #12
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ciotog
I seriously doubt your teacher wants you to use any graphics libraries - you probably want to use some sort of character placement method (a function that places a character at an arbitrary location on the screen), and use sine or somesuch to determine where to place each individual character.

In other words, say you want to limit the output to 10 lines, and you want it displayed on a sine curve. You would want to have the initial 'h' on line 5 or 6, then place each of the next characters one column forward but up towards line 1, then when you reach line 1 start placing characters downwards until line 10 and so on.

Anyway, I hope you get the idea.
no man what i want is a function that when i give her the x and y coordination i get the line
for example
i want such a function line(x,y,x1,y1) ;


so when i write my program prog.c in this way

vi prog.c

#include <studio.h>
#include <"the library i want it to draw the line">

main
{
printf("hello evrey body i will draw line \n ");

line(12,45,14,25);
}

so when i compile then by taping gcc -o prog prog.c

i get my line

do you understand me ?
 
Old 10-21-2006, 01:48 AM   #13
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
so which i want a library that contains such a funtion line

can you help me in that ?
 
Old 10-21-2006, 02:06 AM   #14
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
GTK+, Xlib and SDL are three (among many) choices...

Hi -

You're asking a fair question.

You want "simple" and you want "C". You have many, many options - including GTK+ (which can be programmed in either C or C++, as well as many other languages).

Here's an example in SDL (Simple Direct Media Layer):
http://wiki.gp2x.org/wiki/Writing_an_SDL_Hello_World
Code:
#include "SDL.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8

int main(int argc, char *argv[]) {
     SDL_Surface *screen;
     Uint8       *p;
     int         x = 10; //x coordinate of our pixel
     int         y = 20; //y coordinate of our pixel
     
     /* Initialize SDL */
     SDL_Init(SDL_INIT_VIDEO);
     
     /* Initialize the screen / window */
     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
     
     /* Make p point to the place we want to draw the pixel */
     p = (Uint8 *)screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
     
     /* Draw the pixel! */
     *p=0xff;
     
     /* update the screen (aka double buffering) */
     SDL_Flip(screen);
     while(1);
}
SDL is commonly used in games programming. You can find out more about it here:
http://www.linuxjournal.com/article/440
http://www.libsdl.org/index.php

SDL makes it simple to use your hardware, but it is NOT a graphics toolkit per se. Believe it or not, SDL does *not* even have a "DrawLine()" primitive (although it's certainly easy to substitute your own).

Here's another example, written in the low-level X Windows API (also a 'C' API, and X *does* have a "DrawLine()" primitive ;-)):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

int
main (int argc, char *argv[])
{
    Display    *dpy;            /* X server connection */
    Window      win;            /* Window ID */
    GC          gc;             /* GC to draw with */
    unsigned long fg, bg, bd;   /* Pixel values */
    unsigned long bw = 5;       /* Border width */
    XGCValues   gcv;            /* Struct for creating GC */
    XEvent      event;          /* Event received */
    XSizeHints  xsh;            /* Size hints for window manager */

    /* Open X display */
    if ((dpy = XOpenDisplay(NULL)) == NULL) {
        printf("%s: can't open %s\n", 
          argv[0], XDisplayName(NULL));
        exit(1);
    }

    /*
     * Select colors for the border,  the window background,  and the
     * foreground.
     */
    bd = BlackPixel(dpy, DefaultScreen(dpy));
    bg = BlackPixel(dpy, DefaultScreen(dpy));
    fg = WhitePixel(dpy, DefaultScreen(dpy));

    /* Set original size/position */
    xsh.flags = (PPosition | PSize);
    xsh.height = 500;
    xsh.width = 500;
    xsh.x = (DisplayWidth(dpy, DefaultScreen(dpy)) - xsh.width) / 2;
    xsh.y = (DisplayHeight(dpy, DefaultScreen(dpy)) - xsh.height) / 2;

    /* Create the window */
    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
                              xsh.x, xsh.y, xsh.width, xsh.height,
                              bw, bd, bg);

    /* Create a "Graphics context" for drawing */
    gcv.foreground = fg;
    gcv.background = bg;
    gc = XCreateGC(dpy, win, (GCForeground | GCBackground), &gcv);

    /* Specify the event types we're interested in */
    XSelectInput(dpy, win, ExposureMask);

    /* Map the window to make it visible */
    XMapWindow(dpy, win);

    /* Main event loop */
    while (1) {
        XNextEvent(dpy, &event);
        if (event.type == Expose && event.xexpose.count == 0) {
          XDrawLine (dpy, win, gc, 0, 0, xsh.x, xsh.y);
        }
    }

    return 0;
}
Here's the corresponding makefile:
Code:
#
# makefile
#
CC=gcc
CFLAGS= -DLINUX -g -Wall -pedantic
LDFLAGS=-lSDL

hellox: hellox.c
	$(CC) -m32 -I/usr/X11R6/include $(CFLAGS) $< \
          -o $@ $(LDFLAGS) -L/usr/X11R6/lib -lX11 -lm

sdltest: sdltest.c
	$(CC) -I/usr/include/SDL $(CFLAGS) $< -o $@ $(LDFLAGS)
And heres a good link on basic graphics programming in Xlib:
http://users.actcom.co.il/~choo/lupg...ogramming.html

'Hope that helps .. PSM

Last edited by paulsm4; 10-21-2006 at 02:54 AM.
 
Old 10-21-2006, 02:27 AM   #15
spinal2
Member
 
Registered: Oct 2006
Posts: 30

Original Poster
Rep: Reputation: 15
very nice job man
but now time for solving another problem

ok i've write this program
and i saved it
but
First: where i get this library sdl.h ?
Second how can i compile such a program? ( say to me what i tape ? )

## edited:i'm currently tring to do it

Last edited by spinal2; 10-21-2006 at 07:49 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MEPIS/Linux learning curve questions 21Williamkp Linux - Software 3 05-01-2006 09:40 PM
can I use AIX plot(1B) format files in linux (plotutils?) jkey AIX 2 01-26-2006 02:28 PM
Using linux to read unix ".plot" files jkey Linux - General 0 10-05-2005 02:30 PM
using SunOS plot files (1b or 4b format) in linux jkey Solaris / OpenSolaris 0 09-18-2005 06:14 AM
Real Time Plot... DaFrEQ Linux - Software 0 08-27-2002 08:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration