ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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:
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
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).
#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 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;
}
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 ? )
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.