Tak jsem se konecne dostal k tomu programku. Tady je - po spusteni se vytvori BMP soubor v rozliseni 256x256 pixelu (me oblibene rozliseni :-) a na nem by mel byt zluty srpek mesice. Tj. pouziva se operace rozdilu mezi dvojici kruhu:
#include <stdio.h>
#include <stdlib.h>
#define XMAX 256
#define YMAX 256
#define SIZE (XMAX*YMAX*3)
void putpixel(unsigned char *array, int x, int y, unsigned char r, unsigned char g, unsigned char b)
{
unsigned char *p=array+(x+y*XMAX)*3;
*p++=r; *p++=g; *p=b;
}
void save(const char *filename, const unsigned char *array)
{
static unsigned char header[54]={
0x42, 0x4d, 0x36, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
FILE *fout=fopen(filename, "wb");
fwrite(header, sizeof(header), 1, fout);
fwrite(array, SIZE, 1, fout);
fclose(fout);
}
#define fceA(x,y) (((x)-100)*((x)-100)+((y)-128)*((y)-128)-70*70)
#define fceB(x,y) (((x)-40-128)*((x)-40-128)+((y)-128)*((y)-128)-70*70)
#define max(a,b) ((a<b) ? (b) : (a))
#define min(a,b) ((a>b) ? (b) : (a))
void render(unsigned char *array)
{
int x, y;
for (y=0; y<YMAX; y++) {
for (x=0; x<XMAX; x++) {
if (max(fceA(x,y), -fceB(x,y))<0) // !!!!!!!
putpixel(array, x, y, 0x00, 0xff, 0xff);
else
putpixel(array, x, y, 0x00, 0x00, 0x00);
}
}
}
int main(void)
{
unsigned char* array=(unsigned char *)malloc(SIZE);
render(array);
save("out.bmp", array);
free(array);
return 0;
}