kopia lustrzana https://github.com/villares/sketch-a-day
104 wiersze
2.3 KiB
Python
104 wiersze
2.3 KiB
Python
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
|
# Quaternary combinations
|
|
|
|
from __future__ import division
|
|
from arcs import var_bar
|
|
|
|
order = 16 # for a grid with 256 positions
|
|
alt = False
|
|
|
|
def setup():
|
|
size(720, 720)
|
|
noFill() # fill(0)
|
|
textAlign(CENTER, CENTER)
|
|
strokeWeight(2)
|
|
smooth(4)
|
|
colorMode(HSB)
|
|
# blendMode(MULTIPLY)
|
|
|
|
def draw():
|
|
background(240)
|
|
siz = width / order
|
|
if alt:
|
|
grid(siz, draw_quatB)
|
|
else:
|
|
grid(siz, draw_quatA)
|
|
|
|
def grid(siz, func):
|
|
i = 0
|
|
for x in range(order):
|
|
for y in range(order):
|
|
with pushMatrix():
|
|
translate(siz / 2 + x * siz,
|
|
siz / 2 + y * siz)
|
|
#text(quat(i, pad=4), 0, 0)
|
|
func(quat(i))
|
|
i += 1
|
|
|
|
def draw_quatA(quats):
|
|
siz = 8
|
|
pos = [(-siz, -siz),
|
|
(+siz, -siz),
|
|
(-siz, +siz),
|
|
(+siz, +siz)]
|
|
noFill()
|
|
for i, qd in enumerate(quats):
|
|
q = (int(qd) + i) % 4
|
|
stroke(63 + i * 64, 255, 128)
|
|
var_bar(pos[i][0], pos[i][1],
|
|
pos[q][0], pos[q][1],
|
|
0, 7)
|
|
|
|
def draw_quatB(quats):
|
|
siz = 8
|
|
pos = [(-siz, -siz),
|
|
(+siz, -siz),
|
|
(-siz, +siz),
|
|
(+siz, +siz)]
|
|
noFill()
|
|
for i, qd in enumerate(quats):
|
|
q = (int(qd) + i) % 4
|
|
stroke(63 + i * 64, 255, 128)
|
|
var_bar(pos[i][0], pos[i][1],
|
|
pos[q][0], pos[q][1],
|
|
7, 0)
|
|
|
|
|
|
def to_base(num, base):
|
|
# inverse of int(str, base)
|
|
BS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
result = ""
|
|
while num:
|
|
result += BS[num % base]
|
|
num //= base
|
|
return result[::-1] or "0"
|
|
|
|
def quat(n, pad=4):
|
|
s = to_base(n, 4)
|
|
while len(s) < pad:
|
|
s = "0" + s
|
|
return s[::-1]
|
|
|
|
|
|
def keyPressed():
|
|
global alt, p
|
|
|
|
if key == "s":
|
|
saveFrame("###.png")
|
|
if key == "a":
|
|
alt = not alt
|
|
|
|
|
|
def settings():
|
|
from os import path
|
|
global SKETCH_NAME
|
|
SKETCH_NAME = path.basename(sketchPath())
|
|
OUTPUT = ".png"
|
|
println(
|
|
"""
|
|

|
|
|
|
[{0}](https://github.com/villares/sketch-a-day/tree/master/2019/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
|
""".format(SKETCH_NAME, OUTPUT)
|
|
)
|