kopia lustrzana https://github.com/villares/sketch-a-day
sketch_2021_10_07_glyph
rodzic
04afccc807
commit
b54702d7a2
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,36 @@
|
|||
from villares.helpers import lerp_tuple
|
||||
|
||||
def my_line(xa, ya, xb, yb):
|
||||
if 35 > dist(xa, ya, xb, yb) > 15:
|
||||
xa2, ya2 = lerp_tuple((xa, ya), (xb, yb), 0.33)
|
||||
xb2, yb2 = lerp_tuple((xa, ya), (xb, yb), 0.66)
|
||||
line(xa, ya, xa2, ya2)
|
||||
line(xb2, yb2, xb, yb)
|
||||
else:
|
||||
line(xa, ya, xb, yb)
|
||||
|
||||
class Glyph:
|
||||
|
||||
module_size = 5
|
||||
glyphs = {}
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.glyphs[name] = self
|
||||
self.paths = []
|
||||
self.width = 5
|
||||
|
||||
def plot(self, ox=0, oy=0, module_size=None, **kwargs):
|
||||
sw = kwargs.pop('stroke_weight', 2)
|
||||
strokeWeight(sw)
|
||||
|
||||
ms = module_size or self.module_size
|
||||
for path in self.paths:
|
||||
noFill()
|
||||
push()
|
||||
translate(ox * ms, oy * ms)
|
||||
for (xa, ya, d), (xb, yb, d) in zip(path, path[1:]):
|
||||
my_line(xa * ms, ya * ms, xb * ms, yb *ms)
|
||||
pop()
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
from __future__ import division
|
||||
import pickle
|
||||
from glyphs import Glyph
|
||||
|
||||
ADD, MOVE, EDIT = modes = ("add", "move", "edit")
|
||||
mode = ADD
|
||||
current_glyph = None # None or Glyph object
|
||||
current_path = None # None or index to path
|
||||
current_vertex = None # index to vertex in path for EDIT or (px, py) for MOVE
|
||||
|
||||
keys_pressed = {}
|
||||
grid_size = 20
|
||||
OX, OY = 3, 10
|
||||
|
||||
phrase = u''
|
||||
|
||||
def mouse_released(mb):
|
||||
global current_vertex
|
||||
current_path = None
|
||||
|
||||
|
||||
|
||||
|
||||
def check_keys(*args, **kwargs):
|
||||
if kwargs.get('ANY'):
|
||||
return any(keys_pressed.get(k, False) for k in args)
|
||||
else:
|
||||
return all(keys_pressed.get(k, False) for k in args)
|
||||
|
||||
|
||||
def key_released(k, kc):
|
||||
global current_path, phrase
|
||||
if check_keys(ALT):
|
||||
pass
|
||||
elif check_keys(BACKSPACE, DELETE, ANY=True):
|
||||
if phrase:
|
||||
phrase = phrase[:-1]
|
||||
elif u'{}'.format(k) in 'abcdefghijklmnopqrstuvwxyz ':
|
||||
phrase += k
|
||||
print(phrase)
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 77 KiB |
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
A reboot of a simple poly / linerar glyphs editor
|
||||
"""
|
||||
|
||||
import pickle
|
||||
from glyphs import Glyph
|
||||
import interface
|
||||
|
||||
def setup():
|
||||
size(600 , 600)
|
||||
strokeJoin(ROUND)
|
||||
# interface.grid_size = 20
|
||||
with open("glyphs.pickle") as f:
|
||||
Glyph.glyphs = pickle.load(f)
|
||||
print('glyphs loaded')
|
||||
|
||||
|
||||
def draw():
|
||||
background(200)
|
||||
glyphs = Glyph.glyphs
|
||||
gs = 7
|
||||
t = interface.phrase
|
||||
ox, oy = interface.OX, interface.OY
|
||||
push()
|
||||
x = 200
|
||||
y = 10
|
||||
for c in t:
|
||||
gl = glyphs.get(c)
|
||||
if gl:
|
||||
gl.plot(ox + x, oy + y, gs, stroke_weight=4)
|
||||
x += gl.width
|
||||
else:
|
||||
x += 5
|
||||
if x * gs > width:
|
||||
x = 0
|
||||
y += 12
|
||||
|
||||
pop()
|
||||
translate(0, height / 2)
|
||||
x, y = 1 * gs, 2 * gs
|
||||
for gl in Glyph.glyphs.values():
|
||||
push()
|
||||
translate(x, y)
|
||||
s = 0.45
|
||||
gl.plot(module_size=gs * s, stroke_weight=1)
|
||||
pop()
|
||||
x += (gl.width + 1) * gs * s
|
||||
if x > width - 40:
|
||||
x = gs
|
||||
y += 4 * gs
|
||||
|
||||
def keyPressed():
|
||||
interface.keys_pressed[key if key != CODED else keyCode] = True
|
||||
|
||||
def keyReleased():
|
||||
interface.key_released(key, keyCode)
|
||||
interface.keys_pressed[key if key != CODED else keyCode] = False
|
|
@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
|
|||
## [2018](2018.md) | [2019](2019.md) | [2020](2020.md) | 2021
|
||||
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2021_10_07_glyph](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_10_07_glyph) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
|
Ładowanie…
Reference in New Issue