Alexandre B A Villares 2021-02-22 19:15:37 -03:00
rodzic 35cbf2f1e7
commit 1a507081c7
9 zmienionych plików z 71 dodań i 3 usunięć

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 32 KiB

Wyświetl plik

@ -17,6 +17,7 @@ def setup():
starting = tuple(sample('01234567', 8))
positions = [{item} for item in starting]
all_perms = permutations(starting)
print(len(list(all_perms)))
mutual_derrangements = [starting]
for p in all_perms:
@ -25,15 +26,15 @@ def setup():
for i, item in enumerate(p):
positions[i].add(item)
w = 100
shuffle(mutual_derrangements)
# shuffle(mutual_derrangements)
for i, d in enumerate(mutual_derrangements):
for j, item in enumerate(d):
fill(int(item) * 32, 200, 200)
text(item, w / 2 + i * w - 2, w / 2 + j * w - 6)
text(item, w / 2 + i * w - 2, w / 2 + j * w - 8)
# rectMode(CENTER)
# circle(w / 2 + i * w, w / 2 + j * w, w * 0.66)
saveFrame("sketch_2021_02_20_derangements.png")
saveFrame("_sketch_2021_02_20_derangements.png")
"""
Normal derrangements:
starting = tuple('ABCD')

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 136 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 138 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 141 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 143 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 282 KiB

Wyświetl plik

@ -0,0 +1,61 @@
"""
Looking for multually deranged derangements
"""
from itertools import permutations
from random import sample, shuffle
from villares.arcs import var_bar
eight_ways = ((-1, -1), (0, -1), (1, -1),
(-1, 0), (1, 0),
(-1, 1), (0, 1), (1, 1))
def setup():
global mutual_derrangements
size(900, 900)
background(240)
colorMode(HSB)
f = createFont("Tomorrow Bold",80)
textFont(f)
textAlign(CENTER, CENTER)
starting = tuple(sample('01234567', 8))
positions = [{item} for item in starting]
all_perms = permutations(starting)
print(len(list(all_perms)))
mutual_derrangements = [starting]
for p in all_perms:
if not any(item in positions[i] for i, item in enumerate(p)):
mutual_derrangements.append(p)
for i, item in enumerate(p):
positions[i].add(item)
w = 100
# shuffle(mutual_derrangements)
translate(50, 50)
for i, d in enumerate(mutual_derrangements):
for j, item in enumerate(d):
strokeWeight(5)
pos = int(item)
# stroke(pos * 32, 200, 200)
fill(pos * 32, 200, 200)
x0, y0 = w / 2 + i * w , w / 2 + j * w
x = x0 + eight_ways[pos][0] * w / 2
y = y0 + eight_ways[pos][1] * w / 2
circle(x, y, 20)
x0 = x0 - eight_ways[pos][0] * w / 2
y0 = y0 - eight_ways[pos][1] * w / 2
circle(x0, y0, 20)
noFill()
var_bar(x0, y0, x, y, w / 6, w / 3)
saveFrame("_sketch_2021_02_21_derangements_D.png")
"""
Normal derrangements:
starting = tuple('ABCD')
all_perms = permutations(starting)
derangements = (p for p in all_perms
if not any(item == starting[i] for i, item
in enumerate(p)))
"""

Wyświetl plik

@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
---
![_sketch_2021_02_21_derangements_D](2021/_sketch_2021_02_21_derangements_D/_sketch_2021_02_21_derangements_D.png)
[_sketch_2021_02_21_derangements_D](https://github.com/villares/sketch-a-day/tree/master/2021/_sketch_2021_02_21_derangements_D) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_2021_02_20_derangements](2021/sketch_2021_02_20_derangements/sketch_2021_02_20_derangements.png)
[sketch_2021_02_20_derangements](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_02_20_derangements) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]