English 中文(简体)
Good, free, easy-to-use C graphics libraries? [closed]
原标题:

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed last year.

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot on the system right now.

Or would it just be simpler to switch to another language, and if so which one would be easy to learn?

最佳回答

To plot 2D and 3D graphs in C I would recommend the library DISLIN. You can see examples here or there.

The code is pretty easy to use and gives nice results.

问题回答

I like the Cairo library. It has a nice interface to C and it can output in many formats.

This question is a bit vague, "graphics" is a wide field. You can get pretty far using just plain SDL, but it might also be considered "too low-level". You need to provide more requirements.

There s Clutter. Here are a few snippets from the about page:

"Clutter is an open source software library for creating fast, visually rich, portable and animated graphical user interfaces."

"Clutter aims to be non specific — it implements no particular User Interface style, but rather provides a rich generic foundation that facilitates rapid and easy creation of higher level tool kits tailored to specific needs."

"Developed in C, with language bindings for Perl, Python, C#, C++, Vala and Ruby."

"Scene-graph of layered 2D interface elements manipulated in 3D space via position, grouping, transparency, scaling, clipping and rotation."

I haven t tried it out myself, but it seems pretty flexible if you are looking for something just to play around with.

I ve used netpbm format a few time when I needed something simple.

That s how I found out that qsort() (in my implementation and for the data provided) performs a merge sort!

qsort

Source code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define ARRAY_SIZE 20
#define MAX_VALUE 10

unsigned char arr[ARRAY_SIZE];

void print_array(const void *left, const void *right) {
  static int imgs = 0;
  int k, j;
  FILE *img;
  char fname[100];
  char rgb[100];

  if (++imgs > 9999) return;
  sprintf(fname, "img/img%04d.ppm", imgs);
  /* create image in "img/" directory */
  img = fopen(fname, "w");
  if (img) {
    fprintf(img, "P3
%d %d
255
", ARRAY_SIZE, MAX_VALUE);
    for (j=0; j<MAX_VALUE; j++) {
      for (k=0; k<ARRAY_SIZE; k++) {
        int colour = 0;
        if (left && left == arr+k) colour = 2;
        if (right && right == arr+k) colour = 2;
        if (arr[k] == MAX_VALUE - j - 1) colour = 1;
        switch (colour) {
          default: sprintf(rgb, "%d %d %d", 255, 255, 255); break;
          case 1: sprintf(rgb, "%d %d %d", 0, 0, 0); break;
          case 2: sprintf(rgb, "%d %d %d", 255, 0, 0); break;
        }
        }
        fprintf(img, "%s
", rgb);
      }
    }
    fclose(img);
  } else {
    perror("img fopen");
  }
}

int cmp(const void *left, const void *right) {
  const unsigned char a = *(const unsigned char*)left;
  const unsigned char b = *(const unsigned char*)right;

  print_array(left, right);
  if (a < b) return -1;
  if (a == b) return 0;
  return 1;
}

int main(void) {
  int k;
  unsigned int seed = 0; /* or time(0) */

  srand(seed);
  for (k=0; k<ARRAY_SIZE; k++) {
    arr[k] = rand() % MAX_VALUE;
  }
  print_array(NULL, NULL);
  qsort(arr, (size_t)ARRAY_SIZE, sizeof *arr, cmp);
  print_array(NULL, NULL);
  /* use imagemagick to convert group of files to .gif */
  system("convert -delay 0"
         " img/img*.ppm"
         " -loop 1 img/libc-qsort2.gif");
  /* remove .ppm files */
  system("rm img/" "*ppm"); /* ... my editor does not like a
                                   slash and a star together,
                                   even inside quotes */

  return 0;
}

I recommend the Qt GUI toolkit, coupled with the open-source QwtPlot and QwtPlot3D. It s implemented in C++, easy-to-use, extensible, and free...

Take a look at PGPLOT. It s old but works great and should be in the repos. PLPLOT is also an option, it s similar and newer and should also be readily available in the repos. They re both extremely powerful and can do what you specified.

Most people use the gd library for rendering from C but you must implement the "math plotting" part.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签