Alexandre B A Villares 2018-01-20 19:25:19 -02:00
rodzic 70cf99fc34
commit c8bf4d14c6
10 zmienionych plików z 156 dodań i 70 usunięć

Wyświetl plik

@ -4,6 +4,11 @@
Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can make one small program (*sketch*) a day.
![s180120b](sketch_180120b/sketch_180120b.gif)
020: [sketch_180120b](https://github.com/villares/sketch-a-day/tree/master/sketch_180120b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
20a (still working on DBN conversion) didn't generate a nice visual output, so this is 20b...
![s180119a](sketch_180119a/sketch_180119a.png)
019: [sketch_180119a](https://github.com/villares/sketch-a-day/tree/master/sketch_180119a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] DBN Letters: Now working on a new approach, generating vertex/Shape code, not there yet...

Wyświetl plik

@ -0,0 +1,25 @@
"""
s18019 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
Converting some of Maeda's Design by Number
dbnletters.dbn code -> Processing
"""
from dbn_polys import *
def setup():
size(300, 300)
noLoop()
def draw():
strokeCap(PROJECT)
scale(3, 3)
dbn_test()
def dbn_test():
for y in range(0, 5):
for x in range(1, 6):
dbn_letter[x + y * 5](x * 12, -20 - y * 12)
dbn_letterZ(x * 12 + 12, -32 - y * 12)

Wyświetl plik

@ -0,0 +1,69 @@
"""
s18019 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
This script generates code on console for dbn_letters.py
Converting some of Maeda's Design by Number
dbnletters.dbn code -> Processing
"""
def setup():
noLoop()
println('''"""
s18019 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
This code was generated by dbn_generata_poly.py
Converting some of Maeda's Design by Number
dbnletters.dbn code -> Processing
"""''')
println("dbn_letter = {} # Dict of functions")
println("")
convert_dbn_source("data/dbnletters.dbn")
def convert_dbn_source(file_path):
with open(file_path, "r") as f:
dbn_source = f.readlines()
inside_block = False
command_name = ""
command_block = []
for ln in dbn_source:
if ln.count("command"):
command_name = ln[14:15]
elif ln.count("{"):
inside_block = True
elif ln.count("}"):
if command_name in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
def_dbn_letter(command_block, command_name)
command_block = [] # empty block
inside_block = False
elif inside_block:
command_block.append(ln.lstrip())
def def_dbn_letter(dbn_block, func_key):
p_block = []
println("# " + func_key)
println("def dbn_letter" + func_key + "(h, v):")
println(" pushMatrix()")
println(" scale(1, -1)")
println(" beginShape()")
for dbn_line in dbn_block:
if dbn_line:
p_block.append(" " + dbn_line
.replace("line ", "vertex(")
.replace(" ", ",", 1)
.replace(" ", "$", 1)
.replace(" ", ",")
.replace("$", ")\n vertex(", 1)
.replace("//", "#")
.strip()
+ ")")
for py_processing_line in p_block:
println(py_processing_line)
println(" endShape()")
println(" popMatrix()")
println("dbn_letter['"+ func_key +"'] = dbn_letter" + func_key)
println("dbn_letter["+ str(ord(func_key)-64) +"] = dbn_letter" + func_key)
#println("")

Wyświetl plik

@ -47,7 +47,7 @@ def def_dbn_letter(dbn_block, key_):
for dbn_line in dbn_block:
if dbn_line:
p_block.append(" " + dbn_line
p_lines =(" " + dbn_line
.replace("line ", "vertex(")
.replace(" ", ",", 1)
.replace(" ", "$", 1)
@ -56,14 +56,19 @@ def def_dbn_letter(dbn_block, key_):
.replace("//", "#")
.strip()
+ ")")
p_block.append(p_lines.split("\n")[0])
p_block.append(p_lines.split("\n")[1])
with open("dbn_polys.py", 'a') as out:
out.write("# " + key_ + "\n")
out.write("def dbn_letter" + key_ + "(h, v):\n")
out.write(" pushMatrix()\n")
out.write(" scale(1, -1)\n")
out.write(" beginShape()\n")
for py_processing_line in p_block:
out.write(py_processing_line + "\n")
out.write(p_block[0] + "\n")
for i, line_ in enumerate(p_block[1:]):
if line_ != p_block[i-1]:
out.write(line_ + "\n")
out.write(" endShape()\n")
out.write(" popMatrix()\n")
out.write("dbn_letter['" + key_ + "'] = dbn_letter" + key_ + "\n")

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -56,7 +56,6 @@ def dbn_letterC(h, v):
beginShape()
vertex((h+4),v)
vertex((h+10),v)
vertex((h+4),v)
vertex(h,(v+4))
vertex(h,(v+4))
vertex(h,(v+9))
@ -72,8 +71,6 @@ def dbn_letterD(h, v):
scale(1, -1)
beginShape()
vertex(h,v)
vertex(h,(v+10))
vertex(h,v)
vertex((h+8),v)
vertex((h+8),v)
vertex((h+10),(v+2))
@ -94,7 +91,6 @@ def dbn_letterE(h, v):
beginShape()
vertex(h,(v+3))
vertex(h,(v+10))
vertex(h,(v+3))
vertex((h+3),v)
vertex((h+3),v)
vertex((h+10),v)
@ -128,7 +124,6 @@ def dbn_letterG(h, v):
beginShape()
vertex((h+4),v)
vertex((h+9),v)
vertex((h+4),v)
vertex(h,(v+4))
vertex(h,(v+4))
vertex(h,(v+9))
@ -209,7 +204,6 @@ def dbn_letterL(h, v):
beginShape()
vertex(h,v)
vertex(h,(v+10))
vertex(h,v)
vertex((h+10),v)
endShape()
popMatrix()
@ -258,7 +252,6 @@ def dbn_letterO(h, v):
beginShape()
vertex((h+4),v)
vertex((h+9),v)
vertex((h+4),v)
vertex(h,(v+4))
vertex(h,(v+4))
vertex(h,(v+9))
@ -286,7 +279,6 @@ def dbn_letterP(h, v):
vertex((h+10),(v+6))
vertex((h+8),(v+4))
vertex(h,(v+4))
vertex((h+8),(v+4))
endShape()
popMatrix()
dbn_letter['P'] = dbn_letterP
@ -298,7 +290,6 @@ def dbn_letterQ(h, v):
beginShape()
vertex((h+4),v)
vertex((h+8),v)
vertex((h+4),v)
vertex(h,(v+4))
vertex(h,(v+4))
vertex(h,(v+9))
@ -328,7 +319,6 @@ def dbn_letterR(h, v):
vertex((h+10),(v+6))
vertex((h+8),(v+4))
vertex(h,(v+4))
vertex((h+8),(v+4))
vertex((h+6),(v+4))
vertex((h+10),v)
endShape()

Wyświetl plik

@ -2,70 +2,24 @@
s18020 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
This script generates code on console for dbn_letters.py
Converting some of Maeda's Design by Number
dbnletters.dbn code -> Processing
"""
from dbn_polys import *
def setup():
size(300, 300)
noLoop()
convert_dbn_source("data/dbnletters.dbn")
def convert_dbn_source(file_path):
with open("dbn_polys.py", 'w') as out:
out.write('"""\n')
out.write("s18019 - Alexandre B A Villares\n")
out.write("https://abav.lugaralgum.com/sketch-a-day\n")
out.write("This code was generated by dbn_generata_poly.py\n")
out.write("Converting some of Maeda's Design by Number\n")
out.write('dbnletters.dbn code -> Processing\n"""\n')
out.write("dbn_letter = {} # Dict of functions\n")
out.write("\n")
with open(file_path, "r") as f:
dbn_source = f.readlines()
inside_block = False
command_name = ""
command_block = []
for ln in dbn_source:
if ln.count("command"):
command_name = ln[14:15]
elif ln.count("{"):
inside_block = True
elif ln.count("}"):
if command_name in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
def_dbn_letter(command_block, command_name)
command_block = [] # empty block
inside_block = False
elif inside_block:
command_block.append(ln.lstrip())
def draw():
strokeCap(PROJECT)
scale(3, 3)
dbn_test()
def def_dbn_letter(dbn_block, key_):
p_block = []
for dbn_line in dbn_block:
if dbn_line:
p_block.append(" " + dbn_line
.replace("line ", "vertex(")
.replace(" ", ",", 1)
.replace(" ", "$", 1)
.replace(" ", ",")
.replace("$", ")\n vertex(", 1)
.replace("//", "#")
.strip()
+ ")")
with open("dbn_polys.py", 'a') as out:
out.write("# " + key_ + "\n")
out.write("def dbn_letter" + key_ + "(h, v):\n")
out.write(" pushMatrix()\n")
out.write(" scale(1, -1)\n")
out.write(" beginShape()\n")
for py_processing_line in p_block:
out.write(py_processing_line + "\n")
out.write(" endShape()\n")
out.write(" popMatrix()\n")
out.write("dbn_letter['" + key_ + "'] = dbn_letter" + key_ + "\n")
out.write("dbn_letter[" + str(ord(key_) - 64)
+ "] = dbn_letter" + key_ + "\n")
def dbn_test():
for y in range(0, 5):
for x in range(1, 6):
dbn_letter[x + y * 5](x * 12, -20 - y * 12)
dbn_letterZ(x * 12 + 12, -32 - y * 12)

Wyświetl plik

@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.2 MiB

Wyświetl plik

@ -0,0 +1,36 @@
"""
s18020b - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
Playing with HSB color mode and varying fill
"""
def setup():
noStroke()
colorMode(HSB)
size(500, 500, P2D)
background(0)
#noLoop()
def draw():
background(0)
translate(width / 2, height / 2)
npoints, r1, r2 = 3, mouseX, mouseY
angle = TWO_PI / npoints
beginShape()
#vertex(0, 0)
a = 0
while a <= TWO_PI:
sx = cos(a) * r2
sy = sin(a) * r2
cor = map(a, 0, TWO_PI, 0, 255)
fill(cor, 255, 255)
vertex(sx, sy)
sx = cos(a + angle / 2) * r1
sy = sin(a + angle / 2) * r1
vertex(sx, sy)
a += angle
endShape(CLOSE)
if not frameCount % 10 and frameCount < 500:
saveFrame("###.png")