1: //extern declarations 2: extern (C) typedef void *gdImagePtr; 3: extern (C) typedef int FILE; //lying to D so it compiles 4: 5: //C prototypes for gd functions 6: extern (C) gdImagePtr gdImageCreate(int sx, int sy); //gets pointer to new gdImage 7: extern (C) void gdImagePng(gdImagePtr im, FILE* handle); //saves gdImage to PNG 8: extern (C) int gdImageColorAllocate(gdImagePtr im, int r, int g, int b); //allocate colors 9: extern (C) void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color); //draw a line 10: extern (C) void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color); /* Draw a "dashed" line */ 11: 12: //C prototypes for stdio functions 13: extern (C) FILE *fopen(char* filename, char* mode); 14: extern (C) int fclose(FILE* handle); 15: 16: void draw_prism(gdImagePtr im, int triangle_depth, int im_height, int im_width, int color) { 17: gdImageLine(im, 10, triangle_depth + 10, im_width / 2, 10, color); 18: gdImageLine(im, 10, triangle_depth + 10, im_width - 10, triangle_depth + 10, color); 19: gdImageLine(im, im_width - 10, triangle_depth + 10, im_width / 2, 10, color); 20: 21: gdImageDashedLine(im, 10, im_height - 10, im_width / 2, im_height - 10 - triangle_depth, color); 22: gdImageDashedLine(im, im_width - 10, im_height - 10, im_width / 2, im_height - 10 - triangle_depth, color); 23: gdImageLine(im, 10, im_height - 10, im_width - 10, im_height - 10, color); 24: 25: gdImageLine(im, 10, im_height - 10, 10, triangle_depth + 10, color); 26: gdImageLine(im, im_width - 10, im_height - 10, im_width - 10, triangle_depth + 10, color); 27: gdImageDashedLine(im, im_width / 2, 10, im_width / 2, im_height - 10 - triangle_depth, color); 28: 29: return; 30: } 31: 32: void draw_dot(gdImagePtr im, int smart, int sane, int cute, int overall, int radius, int color, int image_width, int image_height) { 33: 34: 35: } 36: 37: int main(char[][] args) { 38: int smart, cute, sane, weight; 39: int color_white, color_black; 40: gdImagePtr image; 41: int image_height, image_width; 42: int triangle_depth; 43: 44: image_height = 200; 45: image_width = 200; 46: triangle_depth = 40; 47: 48: /* 49: * Create a blank image and allocate some colors 50: */ 51: image = gdImageCreate(image_height, image_width); 52: if (image == null) { 53: return(1); 54: } 55: 56: color_white = gdImageColorAllocate(image, 0xff, 0xff, 0xff); 57: color_black = gdImageColorAllocate(image, 0x00, 0x00, 0x00); 58: 59: /* 60: * Draw our prism 61: */ 62: draw_prism(image, triangle_depth, image_height, image_width, color_black); 63: 64: /* 65: * Save the image to a PNG file. 66: */ 67: FILE* imgFile = fopen("test.png","w"); 68: gdImagePng(image, imgFile); 69: fclose(imgFile); 70: 71: /* 72: * Declare victory. 73: */ 74: return(0); 75: } |