so I have this task to create mandel fractals in C. I will keep the code simple as it's quite much. The Problem:
in the given file, each pixel (char[3]) is calculated separately and then written to stdout via write(1, pixeldata, 3)
NOW: as this is not very efficient, I want to first collect all pixels of one line in a char array char line[width*3]
- everything works, except that the output is very different from the one before (colors look displaced, etc.)
Here's the code:
char pixelData[3];
char line[width*3];
for (y=1; y <= height; ++y) {
...
for (x=1; x <= width; ++x) {
... calculate ...
// iterate
for ( .... calculate ...) {
... calculate ....
}
strncat(line, pixelData, 3); // after
// write(1, pixelData, 3); // before: worked
}
write(1, line, sizeof(line)); // after
memset(line, 0, sizeof(line));
}
It would be pretty cool, if someone could tell me, what I did wrong here... Thanks in advance :)