#include #include #include "studio/bitmap.h" #include "studio/geometry.h" #include "studio/random.h" struct bitmap *plot(struct bitmap *image, vector coordinate, const colour ink, const double pressure) { assert(image); assert(image->depth == grey8); const double nib[6][6] = { {0.01, 0.03, 0.06, 0.06, 0.03, 0.01}, {0.03, 0.10, 0.30, 0.30, 0.10, 0.03}, {0.06, 0.30, 1.00, 1.00, 0.30, 0.06}, {0.06, 0.30, 1.00, 1.00, 0.30, 0.06}, {0.03, 0.10, 0.30, 0.30, 0.10, 0.03}, {0.01, 0.03, 0.06, 0.06, 0.03, 0.01} }; coordinate = subtract(scalar(2.5), coordinate); coordinate = (vector){.x = round(coordinate.x), .y = round(coordinate.y)}; for (size_t x = 0; x < sizeof nib / sizeof *nib; ++x) { for (size_t y = 0; y < sizeof nib[x] / sizeof *nib[x]; ++y) { const vector position = add(coordinate, (vector){.x = x, .y = y}); const double mark = getbitmap(image, position.x, position.y).grey[level] - ( (image->clear.grey[level] - ink.grey[level]) * nib[x][y] * pressure ); image = setbitmap(image, position.x, position.y, (colour){ .grey[level] = round(mark > 0.0 ? (mark <= 255.0 ? mark : 255.0) : 0.0) }); } } return image; } struct bitmap *line(struct bitmap *image, const vector from, const vector to, const colour ink, double pressure) { const vector length = subtract(from, to); double steps = fabs(length.x) >= fabs(length.y) ? fabs(length.x) : fabs(length.y); const vector increment = divide(length, scalar(steps)); const double lift = (pressure * (any(500) / 1000.0)) / steps; for (vector point = from; steps > 0.0; --steps, point = add(increment, point)) image = plot(image, point, ink, pressure -= lift); image = plot(image, to, ink, pressure); return image; }