C-Playground/main.c

115 lines
3.5 KiB
C
Executable File

#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
/*#include <wctype.h>
#include "lib/temperature.h"
#include "lib/array.h"
#include "lib/base10.h"
#include "lib/alloc.h"*/
#include "lib/math.h"
#include "lib/bmp.h"
#include "lib/grapher.h"
void swap_int(int *pX, int *pY) {
int temp = *pX;
*pX = *pY;
*pY = temp;
}
int main() {
/* TODO: Move all of this stuff into its own projects */
/*intArray unsorted_array;
int unsorted_array_data[] = { 1, 5, 2, 1, 4, 8, 3, 2, 6, 7 };
unsorted_array.length = sizeof(unsorted_array_data) / sizeof(int);
unsorted_array.data = unsorted_array_data;
intArray sorted_array;
int sorted_array_data[] = { 1, 2, 4, 8, 9, 9, 9 };
sorted_array.length = sizeof(sorted_array_data) / sizeof(int);
sorted_array.data = sorted_array_data;
printf("Unsorted Array : ");
print_intArray(&unsorted_array);
printf("Unsorted Array Sorted?: %d\n", check_intArray_sorted(&unsorted_array));
printf("Sorted Array : ");
print_intArray(&sorted_array);
printf("Sorted Array Sorted?: %d\n", check_intArray_sorted(&sorted_array));
printf("40C == %dF\n", (int) celsius_to_farenheit(40.0));
char *reserved_memory = ss_alloc(100);
ss_alloc_free(reserved_memory);
printf("Memory : %d/%d", ALLOC_SIZE, (int)ss_alloc_get_used_bytes());*/
const bitmap_header test = init_bitmap_header(1024, 1024);
const bitmap_file test_file = init_bitmap_file(&test, "test.bmp");
bitmap_pixel_color target_pixel;
int32_t width;
int32_t height;
for (height = 1; height <= test_file.bitmap_metadata->image_height; ++height) {
for (width = 1; width <= test_file.bitmap_metadata->image_width; ++width) {
/* Test hello world */
/*
target_pixel.red = ((float)width / (float)test_file.bitmap_metadata->image_width) * 255;
target_pixel.green = ((float)height / (float)test_file.bitmap_metadata->image_height) * 255;
target_pixel.blue = 100;
*/
/* Simple skybox generator */
target_pixel.red = ((float)height / (float)test_file.bitmap_metadata->image_height) * 255;
target_pixel.green = ((float)height / (float)test_file.bitmap_metadata->image_height) * 255;
target_pixel.blue = 255;
//target_pixel.red = 255;
//target_pixel.green = 255;
//target_pixel.blue = 255;
write_bitmap_pixel(test_file, target_pixel, width, height);
}
}
/*
target_pixel.red = 255;
target_pixel.green = 0;
target_pixel.blue = 0;
grapher_draw_line_lerp(test_file, target_pixel, 10, 10, 100, 245, 0.01);
target_pixel.red = 0;
target_pixel.green = 255;
target_pixel.blue = 0;
grapher_draw_line_lerp(test_file, target_pixel, 10, 10, 245, 245, 0.01);
target_pixel.red = 0;
target_pixel.green = 0;
target_pixel.blue = 255;
grapher_draw_line_lerp(test_file, target_pixel, 10, 10, 245, 100, 0.01);
*/
target_pixel.red = 0;
target_pixel.green = 255;
target_pixel.blue = 0;
int32_t iteration = -22;
int32_t y = iteration * iteration;
int32_t previous_iteration = iteration;
int32_t previous_y = iteration * iteration;
int32_t x = iteration;
int32_t previous_x = x;
while (y < 500 && x < 500) {
y = iteration * iteration;
x += 10;
++iteration;
grapher_draw_line_lerp(test_file, target_pixel, previous_x + 250, previous_y + 250, x + 250, y + 250, 0.1);
previous_iteration = iteration;
previous_x = x;
previous_y = y;
};
/* Draw graph */
target_pixel.red = 0;
target_pixel.green = 0;
target_pixel.blue = 0;
grapher_draw_line_linear(test_file, target_pixel, 10, 10, 1014, 10);
grapher_draw_line_linear(test_file, target_pixel, 10, 10, 10, 1014);
close(test_file.fd);
}