Compute division of Lake Constance

This commit is contained in:
Peter J. Holzer 2024-04-28 20:08:18 +02:00
commit a60c66b30b
9 changed files with 79 additions and 0 deletions

37
bodensee-borders Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/python3
from PIL import Image
im = Image.open("bodensee-m3.png")
print(im.format, im.size, im.mode)
region_colors = {
( 0, 0, 255, 255),
( 0, 255, 255, 255),
( 0, 255, 0, 255),
(255, 255, 0, 255),
(255, 0, 0, 255),
}
seeds = {c: [] for c in region_colors}
for y in range(0, im.size[1]):
for x in range(0, im.size[0]):
p = im.getpixel((x, y))
if p in region_colors:
seeds[p].append((x, y))
for y in range(0, im.size[1]):
print(f"{y}")
for x in range(0, im.size[0]):
p = im.getpixel((x, y))
if p[3] == 0:
best_color = (0, 0, 0, 255)
min_d2 = 10_000_000
for color, points in seeds.items():
for p in points:
dx = p[0] - x
dy = p[1] - y
d2 = dx * dx + dy * dy
if d2 < min_d2:
best_color = color
min_d2 = d2
best_color = (*best_color[:3], 127)
im.putpixel((x, y), best_color)
im.save("bodensee-r3.png")

BIN
bodensee-m1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee-m2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee-m3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee-r1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee-r2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee-r3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
bodensee.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

42
trintignant.times Normal file
View File

@ -0,0 +1,42 @@
pypy3 ./bodensee-borders 2.90s user 0.05s system 99% cpu 2.949 total
/usr/bin/python3 ./bodensee-borders 141.92s user 0.12s system 99% cpu 2:23.27 total
pypy3 ./bodensee-borders 2.21s user 0.04s system 99% cpu 2.254 total
/usr/bin/python3 ./bodensee-borders 150.12s user 0.37s system 95% cpu 2:36.91 total
pypy3 ./bodensee-borders 4.98s user 0.10s system 94% cpu 5.359 total
/usr/bin/python3 ./bodensee-borders 214.28s user 0.82s system 95% cpu 3:44.37 total
pypy3 ./bodensee-borders 2.11s user 0.04s system 99% cpu 2.148 total
/usr/bin/python3 ./bodensee-borders 119.05s user 0.09s system 99% cpu 1:59.57 total
pypy3 ./bodensee-borders 2.06s user 0.07s system 99% cpu 2.131 total
/usr/bin/python3 ./bodensee-borders 98.09s user 0.05s system 99% cpu 1:38.19 total
pypy3 ./bodensee-borders 2.01s user 0.06s system 99% cpu 2.072 total
/usr/bin/python3 ./bodensee-borders 95.76s user 0.02s system 99% cpu 1:35.79 total
pypy3 ./bodensee-borders 2.03s user 0.06s system 99% cpu 2.093 total
/usr/bin/python3 ./bodensee-borders 91.87s user 0.06s system 99% cpu 1:31.96 total
pypy3 ./bodensee-borders 2.06s user 0.05s system 99% cpu 2.109 total
/usr/bin/python3 ./bodensee-borders 117.41s user 0.05s system 99% cpu 1:58.12 total
pypy3 ./bodensee-borders 2.08s user 0.05s system 99% cpu 2.125 total
/usr/bin/python3 ./bodensee-borders 98.99s user 0.06s system 99% cpu 1:39.08 total
% pypy3 --version
Python 3.8.13 (7.3.9+dfsg-1ubuntu0.1, Nov 15 2022, 06:22:50)
[PyPy 7.3.9 with GCC 11.3.0]
/usr/bin/python3 --version
Python 3.10.12
% lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
(screen-sizes) trintignant:~/tmp/bodensee 19:50 :-) 1073% egrep 'vendor_id|cpu family|model|stepping|cpu MHz|cache size' /proc/cpuinfo | sort | uniq -c
4 cache size : 4096 KB
3 cpu MHz : 1600.000
1 cpu MHz : 578.717
4 cpu family : 6
4 model : 142
4 model name : Intel(R) Core(TM) i5-7Y54 CPU @ 1.20GHz
4 stepping : 9
4 vendor_id : GenuineIntel