aboutsummaryrefslogtreecommitdiff
path: root/unit_circle.cc
blob: aa12bf71d502f305b0fb9260c304f0b6b3ee2679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <imgen.h>

#include <cmath>
#include <vector>
#include <algorithm>

double p_norm(double p, int x, int y) {
	return std::pow(
		  std::pow(std::abs(x), p)
		+ std::pow(std::abs(y), p),
		1.0 / p
	);
}

void generate_p_unit_circle(
	const double lower,
	const double upper,
	const double epsilon
) {
	for ( double p = lower; p < upper + epsilon; p = p + epsilon ) {
		imgen::write_ppm(
			"unit_circle_" + std::to_string(p) + ".ppm",
			128,
			128,
			[p](std::ptrdiff_t x, std::ptrdiff_t y) -> imgen::color {
				if ( p_norm(p, x, y) <= 32.0 ) {
					return imgen::black();
				} else {
					return imgen::white();
				}
			}
		);
	}
}

int main(int, char*[]) {
	generate_p_unit_circle(1.0, 3.0, 0.05);
}