kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
de9da3b1f2
commit
ef38b9eab1
|
@ -3,8 +3,8 @@
|
|||
|
||||
from random import shuffle
|
||||
from itertools import product, combinations, permutations, combinations_with_replacement
|
||||
# from gif_exporter import gif_export
|
||||
# add_library('GifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
add_library('GifAnimation')
|
||||
|
||||
space, border = 40, 40
|
||||
position = 0 # initial position
|
||||
|
@ -16,7 +16,7 @@ def setup():
|
|||
frameRate(1)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(1.5)
|
||||
grid = product(range(-1, 2), repeat=2) # 2X2
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# all line permutations on a grid
|
||||
lines = permutations(grid, 2)
|
||||
# allow only some lines
|
||||
|
@ -53,7 +53,7 @@ def draw():
|
|||
popMatrix()
|
||||
i += 1
|
||||
if i < len(line_combos):
|
||||
# gif_export(GifMaker, SKETCH_NAME)
|
||||
gif_export(GifMaker, SKETCH_NAME)
|
||||
# gif_export(GifMaker, SKETCH_NAME[:-1] + "b") # B option
|
||||
position += H * W
|
||||
# else:
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
"""
|
||||
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
|
||||
|
||||
A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0
|
||||
Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip
|
||||
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
|
||||
|
||||
# add at the start of your sketch:
|
||||
add_library('gifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
# add at the end of draw():
|
||||
gif_export(GifMaker)
|
||||
"""
|
||||
|
||||
def gif_export(GifMaker, # gets a reference to the library
|
||||
filename="exported", # .gif will be added
|
||||
repeat=0, # 0 makes it an "endless" animation
|
||||
quality=255, # quality range 0 - 255
|
||||
delay=1000, # this is quick
|
||||
frames=0, # 0 will stop on keyPressed or frameCount >= 100000
|
||||
finish=False): # force stop
|
||||
global gifExporter
|
||||
try:
|
||||
gifExporter
|
||||
except NameError:
|
||||
gifExporter = GifMaker(this, filename + ".gif")
|
||||
gifExporter.setRepeat(repeat)
|
||||
gifExporter.setQuality(quality)
|
||||
gifExporter.setDelay(delay)
|
||||
|
||||
gifExporter.addFrame()
|
||||
|
||||
if frames == 0:
|
||||
if keyPressed and key == "e":
|
||||
finish = True
|
||||
|
||||
if finish:
|
||||
gifExporter.finish()
|
||||
print("gif saved")
|
||||
exit()
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 243 KiB |
|
@ -0,0 +1,133 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
# More explorations of lines in grids
|
||||
|
||||
from random import shuffle
|
||||
from itertools import product, combinations, permutations, combinations_with_replacement
|
||||
from gif_exporter import gif_export
|
||||
add_library('GifAnimation')
|
||||
|
||||
space, border = 20, 20
|
||||
position = 0 # initial position
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
size(800, 660)
|
||||
frameRate(1)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(1.5)
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# all line permutations on a grid
|
||||
possible_lines = list(combinations(grid, 3))
|
||||
# allow only some lines
|
||||
# possible_lines = []
|
||||
# for l in lines:
|
||||
# (x0, y0), (x1, y1) = l[0], l[1]
|
||||
# if dist(x0, y0, x1, y1) < 2: # rule defined here...
|
||||
# possible_lines.append(l)
|
||||
num_possible_lines = len(possible_lines)
|
||||
println("Number of possible lines: {}".format(num_possible_lines))
|
||||
# main stuff
|
||||
line_combos = list(combinations(possible_lines, 2))
|
||||
# shuffle(line_combos) # ucomment to shuffle!
|
||||
num = len(line_combos)
|
||||
println("Number of permutations: {}".format(num))
|
||||
W = (width - border * 2) // space
|
||||
H = (height - border * 2) // space
|
||||
println("Cols: {} Rows: {} Visible grid: {}".format(W, H, W * H))
|
||||
|
||||
|
||||
def draw():
|
||||
global position
|
||||
background(240)
|
||||
i = position
|
||||
for y in range(H):
|
||||
for x in range(W):
|
||||
if i < len(line_combos):
|
||||
pushMatrix()
|
||||
translate(border / 2 + space + space * x,
|
||||
border / 2 + space + space * y)
|
||||
# translate(border + space + space * x,
|
||||
# border + space + space * y)
|
||||
draw_combo(i)
|
||||
popMatrix()
|
||||
i += 1
|
||||
if i < len(line_combos):
|
||||
gif_export(GifMaker, SKETCH_NAME)
|
||||
gif_export(GifMaker, SKETCH_NAME[:-1] + "b") # B option
|
||||
position += H * W
|
||||
# else:
|
||||
# gif_export(GifMaker, finish=True)
|
||||
|
||||
def draw_combo(n):
|
||||
colorMode(RGB)
|
||||
siz = space/2
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB)
|
||||
stroke(i * 128, 128, 128)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
noFill()
|
||||
var_bar(x0 * siz, y0 * siz, x1 * siz, y1 * siz, siz / 8, siz / 4)
|
||||
|
||||
def keyPressed():
|
||||
global W, H
|
||||
if key == "s":
|
||||
saveFrame("####.png")
|
||||
|
||||
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/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
""".format(SKETCH_NAME, OUTPUT, year())
|
||||
)
|
||||
|
||||
def var_bar(p1x, p1y, p2x, p2y, r1, r2=None):
|
||||
"""
|
||||
Tangent/tangent shape on 2 circles of arbitrary radius
|
||||
"""
|
||||
if r2 is None:
|
||||
r2 = r1
|
||||
#line(p1x, p1y, p2x, p2y)
|
||||
d = dist(p1x, p1y, p2x, p2y)
|
||||
ri = r1 - r2
|
||||
if d > abs(ri):
|
||||
rid = (r1 - r2) / d
|
||||
if rid > 1:
|
||||
rid = 1
|
||||
if rid < -1:
|
||||
rid = -1
|
||||
beta = asin(rid) + HALF_PI
|
||||
with pushMatrix():
|
||||
translate(p1x, p1y)
|
||||
angle = atan2(p1x - p2x, p2y - p1y)
|
||||
rotate(angle + HALF_PI)
|
||||
x1 = cos(beta) * r1
|
||||
y1 = sin(beta) * r1
|
||||
x2 = cos(beta) * r2
|
||||
y2 = sin(beta) * r2
|
||||
#print((d, beta, ri, x1, y1, x2, y2))
|
||||
with pushStyle():
|
||||
noStroke()
|
||||
beginShape()
|
||||
vertex(-x1, -y1)
|
||||
vertex(d - x2, -y2)
|
||||
vertex(d, 0)
|
||||
vertex(d - x2, +y2)
|
||||
vertex(-x1, +y1)
|
||||
vertex(0, 0)
|
||||
endShape(CLOSE)
|
||||
line(-x1, -y1, d - x2, -y2)
|
||||
line(-x1, +y1, d - x2, +y2)
|
||||
arc(0, 0, r1 * 2, r1 * 2,
|
||||
-beta - PI, beta - PI)
|
||||
arc(d, 0, r2 * 2, r2 * 2,
|
||||
beta - PI, PI - beta)
|
||||
else:
|
||||
ellipse(p1x, p1y, r1 * 2, r1 * 2)
|
||||
ellipse(p2x, p2y, r2 * 2, r2 * 2)
|
10
README.md
10
README.md
|
@ -24,6 +24,16 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_190531a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190531a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
- Number of possible lines: 84
|
||||
- Number of combinations: 3486
|
||||
- Cols: 38 Rows: 31 Visible grid: 1178
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_190530b](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190530a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
Ładowanie…
Reference in New Issue