Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Graphs in C?

Name: Anonymous 2008-10-09 14:07

Ok a friend of mine is studying his masters in Elec Engineering. he's been handed an assignment to plot some graphs (sine/square/sawtooth etc)
Hes been tasked with coding it in C and run that on a HCS12(x) microcontroller.

Now he knows absoloutly nothing about programming outside of some hardware specific asm code and asked me to help him.

I said sure and ive now realised that i have no fucking clue how to output as a graph. i was hoping to make a function that handled the output to the console (ive got none of the specific hardware or tools hes using) then allow him to write up his own function to run the output on his hardware using whatever fucking libraries codewarrior needs.

so using a standard compiler on standard x86 hardware, how the hell do i output a graph to a console or window? anyone know of any libraries i should look into to handle graphics?

Name: Anonymous 2008-10-09 14:10

I thought you meant graphics in C.
GRAPHS?! fucking hell, go read K&R2. There's an exercise on graphs in the first chapters.

Name: Anonymous 2008-10-09 14:28

>>2
K&R second edition?

Name: Anonymous 2008-10-09 14:43

>>3
No, the sequel.

Name: Anonymous 2008-10-09 14:50

>>4
THERES A FUCKING SEQUEL???????
FFFFFFFFFFFFFFFFFFFFFfffffffffffffffff.

PS: is it actualy a usefull read? im more reliant on c++, will 2 help me reach satori?

Name: Anonymous 2008-10-09 15:02

K&R2
2
Please elaborate.

Name: Anonymous 2008-10-09 15:04

It doesn't strike you that it could be the second edition?

Name: Anonymous 2008-10-09 15:25

>>7
>>3
apparently no one considered this.

Name: Anonymous 2008-10-09 15:26

>>2 here, yes you fucking morons, the second edition that describes ANSI C.

Name: Anonymous 2008-10-09 15:40

>>9
YHBTCBFP

Name: Anonymous 2008-10-09 16:32

>>10
Whatever, you faggot.
I've been here 3 years, I know when someone is trolling and when someone is being stupid.
in this case, they tried to troll, but ended up being plain stupid.

Name: Anonymous 2008-10-09 19:02

make a matrix, A, m x n initialized to 0

iterate over columns:

    map the j to an x value
    compute f(x)
    map f(x) to i value
    Aij = 1

Name: Anonymous 2008-10-09 19:46

#include <stdio.h>
#include <math.h>

void graph(double (*f)(double), double xmin, double xmax, double ymin, double ymax, int rows, int cols)
{
    int r;
    for (r=0; r<rows; r++)
    {
        double x = (xmax-xmin) * r/rows + xmin;
        int c = (f(x)-ymin) / (ymax-ymin) * cols;
        if (c > cols)
            c = cols;
        else if (c < 0)
            c = 0;
        while (c--)
            putchar('*');
        putchar('\n');
    }
}

int main()
{
    graph(sin, 0, 10, -2, 2, 40, 40);
    return 0;
}

Name: Anonymous 2008-10-09 19:55

>>11
3 years? You parents hide you in the basement and only let you out after midnight?

Name: Anonymous 2008-10-12 6:52

>>13
11       int c = (f(x)-ymin) / (ymax-ymin) * cols;

[Warning] converting to `int' from `double'

-----
Try this:

[b]int[/b] c = lround((f(x)-ymin) / (ymax-ymin) * cols);

Name: Anonymous 2008-10-12 6:58

DONT HELP HIM

Name: Anonymous 2011-02-04 19:42


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List