kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
bce2d602f7
commit
b10e1fa030
|
@ -62,10 +62,9 @@ def draw():
|
|||
gif_export(GifMaker, SKETCH_NAME + "-" + str(num))
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
def draw_combo(n):
|
||||
siz = space / 4 - 2
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB)
|
||||
# stroke(i * 32, 200, 200)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
|
|
|
@ -58,13 +58,13 @@ def draw():
|
|||
gif_export(GifMaker, SKETCH_NAME + "-" + str(num))
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
def draw_combo(n):
|
||||
colorMode(RGB)
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for stroke_number, stroke_line in enumerate(line_combos[n]):
|
||||
colorMode(HSB)
|
||||
stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
stroke(stroke_number * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = stroke_line[0], stroke_line[1]
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
|
||||
def keyPressed():
|
||||
|
|
|
@ -58,10 +58,9 @@ def draw():
|
|||
gif_export(GifMaker, SKETCH_NAME + "-" + str(num))
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
def draw_combo(n):
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB)
|
||||
stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
|
|
|
@ -56,10 +56,9 @@ def draw():
|
|||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
def draw_combo(n):
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB, 255, 255, 255)
|
||||
stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 331 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 375 KiB |
|
@ -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=200, # 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: 627 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 323 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 322 KiB |
|
@ -0,0 +1,83 @@
|
|||
# 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 = 10
|
||||
position = 0 # initial position
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
size(1340, 560)
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(1)
|
||||
# grid = product(range(-1, 1), repeat=2) # 2X2
|
||||
# grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
grid = product(range(-2, 2), repeat=2) # 4X4
|
||||
|
||||
# all possible lines
|
||||
lines = combinations(grid, 2)
|
||||
# colect only short lines
|
||||
short_lines = []
|
||||
for l in lines:
|
||||
(x0, y0), (x1, y1) = l[0], l[1]
|
||||
if dist(x0, y0, x1, y1) > 3: # short as defined here...
|
||||
short_lines.append(l)
|
||||
num_short_lines = len(short_lines)
|
||||
println("Number of possible lines: {}".format(num_short_lines))
|
||||
# main stuff
|
||||
line_combos = list(combinations(short_lines, 4))
|
||||
# shuffle(line_combos) # ucomment to shuffle!
|
||||
num = len(line_combos)
|
||||
println(num)
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
println((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(space + space * x, space + space * y)
|
||||
draw_combo(i)
|
||||
popMatrix()
|
||||
i += 1
|
||||
else: noLoop()
|
||||
if i < len(line_combos):
|
||||
# gif_export(GifMaker, SKETCH_NAME + "-" + str(num))
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
colorMode(HSB)
|
||||
# stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
|
||||
def keyPressed():
|
||||
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())
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:47:20
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, abs, all, any, assert, bool, bytearray, bytes, callable, chr, copy, deepcopy, delattr, dict, dir, divmod, enumerate, filter, float, getattr, hasattr, input, int, isinstance, issubclass, len, list, map, max, min, object, ord, print, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, round, set, setattr, sorted, str, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
var __name__ = 'math';
|
||||
export var pi = Math.PI;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 10:40:31
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:47:19
|
||||
var __name__ = 'org.transcrypt.__runtime__';
|
||||
export var __envir__ = {};
|
||||
__envir__.interpreter_name = 'python';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:47:20
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, all, any, assert, bool, bytearray, bytes, callable, chr, deepcopy, delattr, dict, dir, divmod, enumerate, getattr, hasattr, input, isinstance, issubclass, len, list, object, ord, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, setattr, sorted, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
var __name__ = 'pytop5js';
|
||||
export var _P5_INSTANCE = null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:47:20
|
||||
var math = {};
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, abs, all, any, assert, bool, bytearray, bytes, callable, chr, copy, deepcopy, delattr, dict, dir, divmod, enumerate, filter, float, getattr, hasattr, input, int, isinstance, issubclass, len, list, map, max, min, object, ord, pow, print, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, round, set, setattr, sorted, str, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
import * as __module_math__ from './math.js';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:47:20
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, all, any, assert, bool, bytearray, bytes, callable, chr, deepcopy, delattr, dict, dir, divmod, enumerate, getattr, hasattr, input, isinstance, issubclass, len, list, object, ord, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, setattr, sorted, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
import {combinations, combinations_with_replacement, permutations, product} from './itertools.js';
|
||||
import {shuffle} from './random.js';
|
||||
|
@ -60,10 +60,9 @@ export var draw = function () {
|
|||
position += W;
|
||||
}
|
||||
};
|
||||
export var draw_combo = function (i) {
|
||||
colorMode (RGB);
|
||||
export var draw_combo = function (n) {
|
||||
var siz = space / 3.0;
|
||||
for (var [i, sl] of enumerate (line_combos [i])) {
|
||||
for (var [i, sl] of enumerate (line_combos [n])) {
|
||||
colorMode (HSB, 255, 255, 255);
|
||||
stroke (i * 64, 160, 160);
|
||||
var __left0__ = tuple ([sl [0], sl [1]]);
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
"sources": [
|
||||
"sketch_190525b.py"
|
||||
],
|
||||
"mappings": "AAAA;AAGA;AAQA;AADA;AAPA;AAHA;AAKA;AACA;AACA;AACA;AAIA;AACA;AAGA;AAEA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AAAA;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AAAA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAEA;AAAA;AAAA;AAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AACA;AAAA;AAAA;AAEA;AACA;AACA;AAAA;AAAA;AAIA;AACA;AAvEA"
|
||||
"mappings": "AAAA;AAGA;AAQA;AADA;AAPA;AAHA;AAKA;AACA;AACA;AACA;AAIA;AACA;AAGA;AAEA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AAAA;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AAAA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAEA;AAAA;AAAA;AAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AACA;AAAA;AAAA;AAEA;AACA;AACA;AAAA;AAAA;AAIA;AACA;AAtEA"
|
||||
}
|
|
@ -56,10 +56,9 @@ def draw():
|
|||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
def draw_combo(n):
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB, 255, 255, 255)
|
||||
stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
|
|
|
@ -56,13 +56,13 @@ def draw():
|
|||
# gif_export(GifMaker, SKETCH_NAME + "-" + str(num))
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
def draw_combo(combo_n):
|
||||
colorMode(RGB)
|
||||
siz = space / 2.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
for stroke_n, stroke_line in enumerate(line_combos[combo_n]):
|
||||
colorMode(HSB)
|
||||
stroke(i * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = sl[0], sl[1]
|
||||
stroke(stroke_n * 64, 160, 160)
|
||||
(x0, y0), (x1, y1) = stroke_line[0], stroke_line[1]
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
|
||||
def keyPressed():
|
||||
|
|
|
@ -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=25, # quality range 0 - 255
|
||||
delay=200, # 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: 3.5 MiB |
|
@ -0,0 +1,98 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
# More explorations of combinations 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 = 10
|
||||
position = 0 # initial position
|
||||
mode = 0
|
||||
|
||||
def setup():
|
||||
global possible_lines, line_combos, W, H, position, num
|
||||
size(1340, 560)
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
# grid = product(range(-1, 1), repeat=2) # 2X2
|
||||
# grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
grid = product(range(-2, 2), repeat=2) # 4X4
|
||||
|
||||
# all line cmbinations
|
||||
grid_lines = combinations(grid, 2)
|
||||
# colect only some lines
|
||||
possible_lines = []
|
||||
for l in grid_lines:
|
||||
(x0, y0), (x1, y1) = l[0], l[1]
|
||||
if dist(x0, y0, x1, y1) > 3: # with 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, 4))
|
||||
num = len(line_combos)
|
||||
println("Number of combinations: {}".format(num))
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
println("Cols: {} Lines: {} 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(space + space * x, space + space * y)
|
||||
draw_combo(i)
|
||||
popMatrix()
|
||||
i += 1
|
||||
else: noLoop()
|
||||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(combo_n):
|
||||
colorMode(HSB)
|
||||
siz0 = space / 3. -0.5
|
||||
siz1 = space / 3.
|
||||
for stroke_n, stroke_line in enumerate(line_combos[combo_n]):
|
||||
if mode < 2:
|
||||
stroke(0)
|
||||
else:
|
||||
stroke(stroke_n * 64, 160, 160)
|
||||
if mode > 0:
|
||||
siz = siz1
|
||||
else:
|
||||
siz = siz0
|
||||
(x0, y0), (x1, y1) = stroke_line[0], stroke_line[1]
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
|
||||
|
||||
def keyPressed():
|
||||
global mode
|
||||
if key == "s":
|
||||
saveFrame("####.png")
|
||||
if key == "g":
|
||||
gif_export(GifMaker, SKETCH_NAME, delay=1200)
|
||||
if key == "m":
|
||||
mode = (mode + 1) % 3
|
||||
if key == "r":
|
||||
shuffle(line_combos) # ucomment to shuffle!
|
||||
if key == "R":
|
||||
line_combos[:] = list(combinations(possible_lines, 4))
|
||||
|
||||
|
||||
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())
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<!-- pyp5js index.html boilerplate -->
|
||||
<html lang="">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>teste - pyp5js</title>
|
||||
<style> body, html, canvas {padding: 0; margin: 0; overflow: hidden;} </style>
|
||||
|
||||
<script src="static/p5.js"></script>
|
||||
<script src="target/teste.js" type="module"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="sketch-holder">
|
||||
<!-- You sketch will go here! -->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
Plik diff jest za duży
Load Diff
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,285 @@
|
|||
# Transcrypt runtime module
|
||||
|
||||
#__pragma__ ('js', 'export var __envir__ = {{}};\n{}', __include__ ('org/transcrypt/__envir__.js'))
|
||||
#__pragma__ ('js', '{}', __include__ ('org/transcrypt/__core__.js'))
|
||||
#__pragma__ ('js', '{}', __include__ ('org/transcrypt/__builtin__.js'))
|
||||
|
||||
#__pragma__ ('skip')
|
||||
copy = Math = __typeof__ = __repr__ = document = console = window = 0
|
||||
#__pragma__ ('noskip')
|
||||
|
||||
#__pragma__ ('notconv') # !!! tconv gives a problem with __terminal__, needs investigation
|
||||
#__pragma__ ('nokwargs')
|
||||
#__pragma__ ('noalias', 'sort')
|
||||
|
||||
class BaseException:
|
||||
pass
|
||||
|
||||
class Exception (BaseException):
|
||||
#__pragma__ ('kwargs')
|
||||
def __init__ (self, *args, **kwargs):
|
||||
self.__args__ = args
|
||||
try:
|
||||
self.stack = kwargs.error.stack # Integrate with JavaScript Error object
|
||||
except:
|
||||
self.stack = 'No stack trace available'
|
||||
#__pragma__ ('nokwargs')
|
||||
|
||||
def __repr__ (self):
|
||||
if len (self.__args__) > 1:
|
||||
return '{}{}'.format (self.__class__.__name__, repr (tuple (self.__args__)))
|
||||
elif len (self.__args__):
|
||||
return '{}({})'.format (self.__class__.__name__, repr (self.__args__ [0]))
|
||||
else:
|
||||
return '{}()'.format (self.__class__.__name__)
|
||||
|
||||
def __str__ (self):
|
||||
if len (self.__args__) > 1:
|
||||
return str (tuple (self.__args__))
|
||||
elif len (self.__args__):
|
||||
return str (self.__args__ [0])
|
||||
else:
|
||||
return ''
|
||||
|
||||
class IterableError (Exception):
|
||||
def __init__ (self, error):
|
||||
Exception.__init__ (self, 'Can\'t iterate over non-iterable', error = error)
|
||||
|
||||
class StopIteration (Exception):
|
||||
def __init__ (self, error):
|
||||
Exception.__init__ (self, 'Iterator exhausted', error = error)
|
||||
|
||||
class ValueError (Exception):
|
||||
def __init__ (self, message, error):
|
||||
Exception.__init__ (self, message, error = error)
|
||||
|
||||
class KeyError (Exception):
|
||||
def __init__ (self, message, error):
|
||||
Exception.__init__ (self, message, error = error)
|
||||
|
||||
class AssertionError (Exception):
|
||||
def __init__ (self, message, error):
|
||||
if message:
|
||||
Exception.__init__ (self, message, error = error)
|
||||
else:
|
||||
Exception.__init__ (self, error = error)
|
||||
|
||||
class NotImplementedError (Exception):
|
||||
def __init__(self, message, error):
|
||||
Exception.__init__(self, message, error = error)
|
||||
|
||||
class IndexError (Exception):
|
||||
def __init__(self, message, error):
|
||||
Exception.__init__(self, message, error = error)
|
||||
|
||||
class AttributeError (Exception):
|
||||
def __init__(self, message, error):
|
||||
Exception.__init__(self, message, error = error)
|
||||
|
||||
class TypeError (Exception):
|
||||
def __init__(self, message, error):
|
||||
Exception.__init__(self, message, error = error)
|
||||
|
||||
# Warnings Exceptions
|
||||
# N.B. This is a limited subset of the warnings defined in
|
||||
# the cpython implementation to keep things small for now.
|
||||
|
||||
class Warning (Exception):
|
||||
''' Warning Base Class
|
||||
'''
|
||||
pass
|
||||
|
||||
class UserWarning (Warning):
|
||||
pass
|
||||
|
||||
class DeprecationWarning (Warning):
|
||||
pass
|
||||
|
||||
class RuntimeWarning (Warning):
|
||||
pass
|
||||
|
||||
#__pragma__ ('kwargs')
|
||||
|
||||
def __sort__ (iterable, key = None, reverse = False): # Used by py_sort, can deal with kwargs
|
||||
if key:
|
||||
iterable.sort (lambda a, b: 1 if key (a) > key (b) else -1) # JavaScript sort, case '==' is irrelevant for sorting
|
||||
else:
|
||||
iterable.sort () # JavaScript sort
|
||||
|
||||
if reverse:
|
||||
iterable.reverse ()
|
||||
|
||||
def sorted (iterable, key = None, reverse = False):
|
||||
if type (iterable) == dict:
|
||||
result = copy (iterable.keys ())
|
||||
else:
|
||||
result = copy (iterable)
|
||||
|
||||
__sort__ (result, key, reverse)
|
||||
return result
|
||||
|
||||
#__pragma__ ('nokwargs')
|
||||
|
||||
def map (func, iterable):
|
||||
return [func (item) for item in iterable]
|
||||
|
||||
|
||||
def filter (func, iterable):
|
||||
if func == None:
|
||||
func = bool
|
||||
return [item for item in iterable if func (item)]
|
||||
|
||||
def divmod (n, d):
|
||||
return n // d, n % d
|
||||
|
||||
#__pragma__ ('ifdef', '__complex__')
|
||||
|
||||
class complex:
|
||||
def __init__ (self, real, imag = None):
|
||||
if imag == None:
|
||||
if type (real) == complex:
|
||||
self.real = real.real
|
||||
self.imag = real.imag
|
||||
else:
|
||||
self.real = real
|
||||
self.imag = 0
|
||||
else:
|
||||
self.real = real
|
||||
self.imag = imag
|
||||
|
||||
def __neg__ (self):
|
||||
return complex (-self.real, -self.imag)
|
||||
|
||||
def __exp__ (self):
|
||||
modulus = Math.exp (self.real)
|
||||
return complex (modulus * Math.cos (self.imag), modulus * Math.sin (self.imag))
|
||||
|
||||
def __log__ (self):
|
||||
return complex (Math.log (Math.sqrt (self.real * self.real + self.imag * self.imag)), Math.atan2 (self.imag, self.real))
|
||||
|
||||
def __pow__ (self, other): # a ** b = exp (b log a)
|
||||
return (self.__log__ () .__mul__ (other)) .__exp__ ()
|
||||
|
||||
def __rpow__ (self, real): # real ** comp -> comp.__rpow__ (real)
|
||||
return self.__mul__ (Math.log (real)) .__exp__ ()
|
||||
|
||||
def __mul__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return complex (self.real * other, self.imag * other)
|
||||
else:
|
||||
return complex (self.real * other.real - self.imag * other.imag, self.real * other.imag + self.imag * other.real)
|
||||
|
||||
def __rmul__ (self, real): # real + comp -> comp.__rmul__ (real)
|
||||
return complex (self.real * real, self.imag * real)
|
||||
|
||||
def __div__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return complex (self.real / other, self.imag / other)
|
||||
else:
|
||||
denom = other.real * other.real + other.imag * other.imag
|
||||
return complex (
|
||||
(self.real * other.real + self.imag * other.imag) / denom,
|
||||
(self.imag * other.real - self.real * other.imag) / denom
|
||||
)
|
||||
|
||||
def __rdiv__ (self, real): # real / comp -> comp.__rdiv__ (real)
|
||||
denom = self.real * self.real
|
||||
return complex (
|
||||
(real * self.real) / denom,
|
||||
(real * self.imag) / denom
|
||||
)
|
||||
|
||||
def __add__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return complex (self.real + other, self.imag)
|
||||
else: # Assume other is complex
|
||||
return complex (self.real + other.real, self.imag + other.imag)
|
||||
|
||||
def __radd__ (self, real): # real + comp -> comp.__radd__ (real)
|
||||
return complex (self.real + real, self.imag)
|
||||
|
||||
def __sub__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return complex (self.real - other, self.imag)
|
||||
else:
|
||||
return complex (self.real - other.real, self.imag - other.imag)
|
||||
|
||||
def __rsub__ (self, real): # real - comp -> comp.__rsub__ (real)
|
||||
return complex (real - self.real, -self.imag)
|
||||
|
||||
def __repr__ (self):
|
||||
return '({}{}{}j)'.format (self.real, '+' if self.imag >= 0 else '', self.imag)
|
||||
|
||||
def __str__ (self):
|
||||
return __repr__ (self) [1 : -1]
|
||||
|
||||
def __eq__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return self.real == other
|
||||
else:
|
||||
return self.real == other.real and self.imag == other.imag
|
||||
|
||||
def __ne__ (self, other):
|
||||
if __typeof__ (other) is 'number':
|
||||
return self.real != other
|
||||
else:
|
||||
return self.real != other.real or self.imag != other.imag
|
||||
|
||||
def conjugate (self):
|
||||
return complex (self.real, -self.imag)
|
||||
|
||||
def __conj__ (aNumber):
|
||||
if isinstance (aNumber, complex):
|
||||
return complex (aNumber.real, -aNumber.imag)
|
||||
else:
|
||||
return complex (aNumber, 0)
|
||||
|
||||
#__pragma__ ('endif')
|
||||
|
||||
class __Terminal__:
|
||||
'''
|
||||
Printing to either the console or to html happens async, but is blocked by calling window.prompt.
|
||||
So while all input and print statements are encountered in normal order, the print's exit immediately without yet having actually printed
|
||||
This means the next input takes control, blocking actual printing and so on indefinitely
|
||||
The effect is that everything's only printed after all inputs are done
|
||||
To prevent that, what's needed is to only execute the next window.prompt after actual printing has been done
|
||||
Since we've no way to find out when that is, a timeout is used.
|
||||
'''
|
||||
|
||||
def __init__ (self):
|
||||
self.buffer = ''
|
||||
|
||||
try:
|
||||
self.element = document.getElementById ('__terminal__')
|
||||
except:
|
||||
self.element = None
|
||||
|
||||
if self.element:
|
||||
self.element.style.overflowX = 'auto'
|
||||
self.element.style.boxSizing = 'border-box'
|
||||
self.element.style.padding = '5px'
|
||||
self.element.innerHTML = '_'
|
||||
|
||||
#__pragma__ ('kwargs')
|
||||
|
||||
def print (self, *args, sep = ' ', end = '\n'):
|
||||
self.buffer = '{}{}{}'.format (self.buffer, sep.join ([str (arg) for arg in args]), end) [-4096 : ]
|
||||
|
||||
if self.element:
|
||||
self.element.innerHTML = self.buffer.replace ('\n', '<br>') .replace (' ', ' ')
|
||||
self.element.scrollTop = self.element.scrollHeight
|
||||
else:
|
||||
console.log (sep.join ([str (arg) for arg in args]))
|
||||
|
||||
def input (self, question):
|
||||
self.print ('{}'.format (question), end = '')
|
||||
answer = window.prompt ('\n'.join (self.buffer.split ('\n') [-8:]))
|
||||
self.print (answer)
|
||||
return answer
|
||||
|
||||
#__pragma__ ('nokwargs')
|
||||
|
||||
__terminal__ = __Terminal__ ()
|
||||
|
||||
print = __terminal__.print
|
||||
input = __terminal__.input
|
Plik diff jest za duży
Load Diff
File diff suppressed because one or more lines are too long
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,17 @@
|
|||
// Transcrypt'ed from Python, 2019-05-27 12:21:38
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, all, any, assert, bool, bytearray, bytes, callable, chr, deepcopy, delattr, dict, dir, divmod, enumerate, getattr, hasattr, input, isinstance, issubclass, len, list, object, ord, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, setattr, sorted, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
import {ADD, ALT, ARROW, AUTO, AXES, BACKSPACE, BASELINE, BEVEL, BEZIER, BLEND, BLUR, BOLD, BOLDITALIC, BOTTOM, BURN, CENTER, CHORD, CLAMP, CLOSE, CONTROL, CORNER, CORNERS, CROSS, CURVE, DARKEST, DEGREES, DEG_TO_RAD, DELETE, DIFFERENCE, DILATE, DODGE, DOWN_ARROW, ENTER, ERODE, ESCAPE, EXCLUSION, FILL, GRAY, GRID, HALF_PI, HAND, HARD_LIGHT, HSB, HSL, IMAGE, IMMEDIATE, INVERT, ITALIC, LANDSCAPE, LEFT, LEFT_ARROW, LIGHTEST, LINEAR, LINES, LINE_LOOP, LINE_STRIP, MIRROR, MITER, MOVE, MULTIPLY, NEAREST, NORMAL, OPAQUE, OPEN, OPTION, OVERLAY, P2D, PI, PIE, POINTS, PORTRAIT, POSTERIZE, PROJECT, QUADRATIC, QUADS, QUAD_STRIP, QUARTER_PI, RADIANS, RADIUS, RAD_TO_DEG, REPEAT, REPLACE, RETURN, RGB, RIGHT, RIGHT_ARROW, ROUND, SCREEN, SHIFT, SOFT_LIGHT, SQUARE, STROKE, SUBTRACT, TAB, TAU, TEXT, TEXTURE, THRESHOLD, TOP, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, TWO_PI, UP_ARROW, WAIT, WEBGL, _CTX_MIDDLE, _DEFAULT_FILL, _DEFAULT_LEADMULT, _DEFAULT_STROKE, _DEFAULT_TEXT_FILL, _P5_INSTANCE, abs, accelerationX, accelerationY, accelerationZ, acos, alpha, ambientLight, ambientMaterial, angleMode, append, applyMatrix, arc, arrayCopy, asin, atan, atan2, background, beginContour, beginShape, bezier, bezierDetail, bezierPoint, bezierTangent, bezierVertex, blend, blendMode, blue, boolean, box, brightness, byte, camera, ceil, char, circle, color, colorMode, concat, cone, constrain, copy, cos, createCamera, createCanvas, createGraphics, createImage, createNumberDict, createShader, createStringDict, createVector, createWriter, cursor, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, cylinder, day, debugMode, degrees, deviceOrientation, directionalLight, disableFriendlyErrors, displayDensity, displayHeight, displayWidth, dist, ellipse, ellipseMode, ellipsoid, endContour, endShape, exp, fill, filter, float, floor, focused, frameCount, frameRate, fullscreen, getURL, getURLParams, getURLPath, global_p5_injection, green, height, hex, hour, httpDo, httpGet, httpPost, hue, image, imageMode, int, join, key, keyCode, keyIsDown, keyIsPressed, lerp, lerpColor, lightness, lights, line, loadBytes, loadFont, loadImage, loadJSON, loadModel, loadPixels, loadShader, loadStrings, loadTable, loadXML, log, loop, mag, map, match, matchAll, max, millis, min, minute, model, month, mouseButton, mouseIsPressed, mouseX, mouseY, nf, nfc, nfp, nfs, noCanvas, noCursor, noDebugMode, noFill, noLoop, noSmooth, noStroke, noTint, noise, noiseDetail, noiseSeed, norm, normalMaterial, orbitControl, ortho, pAccelerationX, pAccelerationY, pAccelerationZ, pRotationX, pRotationY, pRotationZ, perspective, pixelDensity, pixels, plane, pmouseX, pmouseY, point, pointLight, pow, pre_draw, preload, print, push, pwinMouseX, pwinMouseY, py_clear, py_get, py_pop, py_sort, py_split, quad, quadraticVertex, radians, random, randomGaussian, randomSeed, rect, rectMode, red, redraw, remove, resetMatrix, resetShader, resizeCanvas, reverse, rotate, rotateX, rotateY, rotateZ, rotationX, rotationY, rotationZ, round, saturation, save, saveCanvas, saveFrames, saveJSON, saveStrings, saveTable, scale, second, set, setAttributes, setCamera, setMoveThreshold, setShakeThreshold, shader, shearX, shearY, shininess, shorten, shuffle, sin, smooth, specularMaterial, sphere, splice, splitTokens, sq, sqrt, square, start_p5, str, stroke, strokeCap, strokeJoin, strokeWeight, subset, tan, text, textAlign, textAscent, textDescent, textFont, textLeading, textSize, textStyle, textWidth, texture, textureMode, textureWrap, tint, torus, touches, translate, triangle, trim, turnAxis, unchar, unhex, updatePixels, vertex, width, winMouseX, winMouseY, windowHeight, windowWidth, year} from './pytop5js.js';
|
||||
var __name__ = '__main__';
|
||||
export var setup = function () {
|
||||
colorMode (HSB);
|
||||
createCanvas (500, 500);
|
||||
};
|
||||
export var draw = function () {
|
||||
push ();
|
||||
rect (10, 10, 100, 100);
|
||||
py_pop ();
|
||||
};
|
||||
export var event_functions = dict ({});
|
||||
start_p5 (setup, draw, event_functions);
|
||||
|
||||
//# sourceMappingURL=teste.map
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "teste.js",
|
||||
"sources": [
|
||||
"teste.py"
|
||||
],
|
||||
"mappings": "AAAA;AAAA;AAAA;AAAA;AAEA;AACA;AACA;AAAA;AAGA;AACA;AACA;AACA;AAAA;AAKA;AAGA;AAlBA"
|
||||
}
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,19 @@
|
|||
from pytop5js import *
|
||||
|
||||
def setup():
|
||||
colorMode(HSB)
|
||||
createCanvas(500, 500)
|
||||
|
||||
|
||||
def draw():
|
||||
push()
|
||||
rect(10, 10, 100, 100)
|
||||
pop()
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
|
||||
# Register your events functions here
|
||||
event_functions = {
|
||||
# "keyPressed": keyPressed, as an example
|
||||
}
|
||||
start_p5(setup, draw, event_functions)
|
|
@ -0,0 +1,19 @@
|
|||
from pytop5js import *
|
||||
|
||||
def setup():
|
||||
colorMode(HSB)
|
||||
createCanvas(500, 500)
|
||||
|
||||
|
||||
def draw():
|
||||
push()
|
||||
rect(10, 10, 100, 100)
|
||||
pop()
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
|
||||
# Register your events functions here
|
||||
event_functions = {
|
||||
# "keyPressed": keyPressed, as an example
|
||||
}
|
||||
start_p5(setup, draw, event_functions)
|
11
README.md
11
README.md
|
@ -24,6 +24,17 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_190527a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190527a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
Variations: isolated/merged color/b&w ordered/shuffled
|
||||
Number of possible long lines on 4x4 grid: 22
|
||||
Number of combinations: 7315
|
||||
Cols: 133 Lines: 55 Visible grid: 7315
|
||||
|
||||
---
|
||||
|
||||

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