|
| 1 | +/* |
| 2 | + * Copyright 2024 Nathanne Isip |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <math.h> |
| 18 | +#include <mdif.h> |
| 19 | +#include <stdio.h> |
| 20 | +#include <stdlib.h> |
| 21 | + |
| 22 | +void draw_circle(mdif_t* image, int centerX, int centerY, int radius) { |
| 23 | + int width = image->width; |
| 24 | + int height = image->height; |
| 25 | + |
| 26 | + for (int y = 0; y < height; y++) { |
| 27 | + for (int x = 0; x < width; x++) { |
| 28 | + int dx = x - centerX; |
| 29 | + int dy = y - centerY; |
| 30 | + |
| 31 | + if (dx * dx + dy * dy <= radius * radius) { |
| 32 | + image->red[y * width + x] = 255; |
| 33 | + image->green[y * width + x] = 255; |
| 34 | + image->blue[y * width + x] = 255; |
| 35 | + image->alpha[y * width + x] = 255; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +int main() { |
| 42 | + mdif_t image, aliased; |
| 43 | + mdif_init(&image, 256, 256); |
| 44 | + |
| 45 | + draw_circle(&image, 128, 128, 50); |
| 46 | + mdif_antialias(&image, &aliased); |
| 47 | + |
| 48 | + if(mdif_write("circle_image.mdif", &image) != MDIF_ERROR_NONE) { |
| 49 | + fprintf(stderr, "Failed to write MDIF image to file.\r\n"); |
| 50 | + mdif_free(&image); |
| 51 | + return EXIT_FAILURE; |
| 52 | + } |
| 53 | + |
| 54 | + mdif_free(&image); |
| 55 | + mdif_free(&aliased); |
| 56 | + |
| 57 | + printf("MDIF image with circle has been created successfully.\n"); |
| 58 | + return 0; |
| 59 | +} |
0 commit comments