|
@ -1,20 +1,25 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
# More explorations of lines in grids
|
||||
|
||||
from pyp5js import *
|
||||
from pytop5js import *
|
||||
|
||||
num = None
|
||||
H = None
|
||||
W = None
|
||||
line_combos = None
|
||||
|
||||
from random import shuffle
|
||||
from itertools import product, combinations, permutations, combinations_with_replacement
|
||||
space = 15
|
||||
position = 0 # initial position
|
||||
W = None
|
||||
H = None
|
||||
num = None
|
||||
line_combos = None
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
createCanvas(1045, 700)
|
||||
width, height = 1045, 700
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(2)
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# all possible lines
|
||||
|
@ -32,7 +37,7 @@ def setup():
|
|||
shuffle(line_combos)
|
||||
num = len(line_combos)
|
||||
print(num)
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
W, H = (width - space) // space, (height - space) // space
|
||||
print((W, H, W * H))
|
||||
|
||||
|
||||
|
@ -51,20 +56,20 @@ def draw():
|
|||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(n):
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[n]):
|
||||
colorMode(HSB)
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
colorMode(HSB, 255, 255, 255)
|
||||
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 keyPressed():
|
||||
if key == "s":
|
||||
saveFrame("####.png")
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
# Register your events functions here
|
||||
event_functions = {'keyPressed': 'keyPressed'}
|
||||
start_p5(setup, draw, event_functions)
|
||||
event_functions = {"keyPressed" : keyPressed, }
|
||||
start_p5(setup, draw, event_functions)
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-26 00:13:39
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
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-26 00:13:39
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:40:31
|
||||
var __name__ = 'org.transcrypt.__runtime__';
|
||||
export var __envir__ = {};
|
||||
__envir__.interpreter_name = 'python';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Transcrypt'ed from Python, 2019-05-26 00:13:40
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
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__ = 'pyp5js';
|
||||
var __name__ = 'pytop5js';
|
||||
export var _P5_INSTANCE = null;
|
||||
export var alpha = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
|
@ -254,10 +254,6 @@ export var noCursor = function () {
|
|||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.noCursor (...args);
|
||||
};
|
||||
export var windowResized = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.windowResized (...args);
|
||||
};
|
||||
export var fullscreen = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.fullscreen (...args);
|
||||
|
@ -310,10 +306,6 @@ export var push = function () {
|
|||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.push (...args);
|
||||
};
|
||||
export var py_pop = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.py_pop (...args);
|
||||
};
|
||||
export var redraw = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.redraw (...args);
|
||||
|
@ -510,74 +502,10 @@ export var setShakeThreshold = function () {
|
|||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.setShakeThreshold (...args);
|
||||
};
|
||||
export var deviceMoved = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.deviceMoved (...args);
|
||||
};
|
||||
export var deviceTurned = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.deviceTurned (...args);
|
||||
};
|
||||
export var deviceShaken = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.deviceShaken (...args);
|
||||
};
|
||||
export var keyPressed = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.keyPressed (...args);
|
||||
};
|
||||
export var keyReleased = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.keyReleased (...args);
|
||||
};
|
||||
export var keyTyped = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.keyTyped (...args);
|
||||
};
|
||||
export var keyIsDown = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.keyIsDown (...args);
|
||||
};
|
||||
export var mouseMoved = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mouseMoved (...args);
|
||||
};
|
||||
export var mouseDragged = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mouseDragged (...args);
|
||||
};
|
||||
export var mousePressed = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mousePressed (...args);
|
||||
};
|
||||
export var mouseReleased = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mouseReleased (...args);
|
||||
};
|
||||
export var mouseClicked = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mouseClicked (...args);
|
||||
};
|
||||
export var doubleClicked = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.doubleClicked (...args);
|
||||
};
|
||||
export var mouseWheel = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.mouseWheel (...args);
|
||||
};
|
||||
export var touchStarted = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.touchStarted (...args);
|
||||
};
|
||||
export var touchMoved = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.touchMoved (...args);
|
||||
};
|
||||
export var touchEnded = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.touchEnded (...args);
|
||||
};
|
||||
export var createImage = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.createImage (...args);
|
||||
|
@ -986,6 +914,11 @@ export var setCamera = function () {
|
|||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
return _P5_INSTANCE.setCamera (...args);
|
||||
};
|
||||
export var py_pop = function () {
|
||||
var args = tuple ([].slice.apply (arguments).slice (0));
|
||||
var p5_pop = _P5_INSTANCE.pop (...args);
|
||||
return p5_pop;
|
||||
};
|
||||
export var HALF_PI = null;
|
||||
export var PI = null;
|
||||
export var QUARTER_PI = null;
|
||||
|
@ -993,6 +926,17 @@ export var TAU = null;
|
|||
export var TWO_PI = null;
|
||||
export var DEGREES = null;
|
||||
export var RADIANS = null;
|
||||
export var CLOSE = null;
|
||||
export var RGB = null;
|
||||
export var HSB = null;
|
||||
export var CMYK = null;
|
||||
export var TOP = null;
|
||||
export var BOTTOM = null;
|
||||
export var CENTER = null;
|
||||
export var LEFT = null;
|
||||
export var RIGHT = null;
|
||||
export var SHIFT = null;
|
||||
export var WEBGL = null;
|
||||
export var frameCount = null;
|
||||
export var focused = null;
|
||||
export var displayWidth = null;
|
||||
|
@ -1039,6 +983,17 @@ export var pre_draw = function (p5_instance, draw_func) {
|
|||
TWO_PI = p5_instance.TWO_PI;
|
||||
DEGREES = p5_instance.DEGREES;
|
||||
RADIANS = p5_instance.RADIANS;
|
||||
CLOSE = p5_instance.CLOSE;
|
||||
RGB = p5_instance.RGB;
|
||||
HSB = p5_instance.HSB;
|
||||
CMYK = p5_instance.CMYK;
|
||||
TOP = p5_instance.TOP;
|
||||
BOTTOM = p5_instance.BOTTOM;
|
||||
CENTER = p5_instance.CENTER;
|
||||
LEFT = p5_instance.LEFT;
|
||||
RIGHT = p5_instance.RIGHT;
|
||||
SHIFT = p5_instance.SHIFT;
|
||||
WEBGL = p5_instance.WEBGL;
|
||||
frameCount = p5_instance.frameCount;
|
||||
focused = p5_instance.focused;
|
||||
displayWidth = p5_instance.displayWidth;
|
||||
|
@ -1089,12 +1044,26 @@ export var global_p5_injection = function (p5_sketch) {
|
|||
};
|
||||
return decorator;
|
||||
};
|
||||
export var start_p5 = function (setup_func, draw_func) {
|
||||
export var start_p5 = function (setup_func, draw_func, event_functions) {
|
||||
var sketch_setup = function (p5_sketch) {
|
||||
p5_sketch.setup = global_p5_injection (p5_sketch) (setup_func);
|
||||
p5_sketch.draw = global_p5_injection (p5_sketch) (draw_func);
|
||||
};
|
||||
return new p5 (sketch_setup, 'sketch-holder');
|
||||
var instance = new p5 (sketch_setup, 'sketch-holder');
|
||||
var event_function_names = list (['deviceMoved', 'deviceTurned', 'deviceShaken', 'keyPressed', 'keyReleased', 'keyTyped', 'mouseMoved', 'mouseDragged', 'mousePressed', 'mouseReleased', 'mouseClicked', 'doubleClicked', 'mouseWheel', 'touchStarted', 'touchMoved', 'touchEnded', 'windowResized']);
|
||||
for (var f_name of (function () {
|
||||
var __accu0__ = [];
|
||||
for (var f of event_function_names) {
|
||||
if (__in__ (f, event_functions)) {
|
||||
__accu0__.append (f);
|
||||
}
|
||||
}
|
||||
return __accu0__;
|
||||
}) ()) {
|
||||
var func = event_functions [f_name];
|
||||
var event_func = global_p5_injection (instance) (func);
|
||||
setattr (instance, f_name, event_func);
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=pyp5js.map
|
||||
//# sourceMappingURL=pytop5js.map
|
|
@ -190,9 +190,6 @@ def frameRate(*args):
|
|||
def noCursor(*args):
|
||||
return _P5_INSTANCE.noCursor(*args)
|
||||
|
||||
def windowResized(*args):
|
||||
return _P5_INSTANCE.windowResized(*args)
|
||||
|
||||
def fullscreen(*args):
|
||||
return _P5_INSTANCE.fullscreen(*args)
|
||||
|
||||
|
@ -232,9 +229,6 @@ def loop(*args):
|
|||
def push(*args):
|
||||
return _P5_INSTANCE.push(*args)
|
||||
|
||||
def pop(*args):
|
||||
return _P5_INSTANCE.pop(*args)
|
||||
|
||||
def redraw(*args):
|
||||
return _P5_INSTANCE.redraw(*args)
|
||||
|
||||
|
@ -382,57 +376,9 @@ def setMoveThreshold(*args):
|
|||
def setShakeThreshold(*args):
|
||||
return _P5_INSTANCE.setShakeThreshold(*args)
|
||||
|
||||
def deviceMoved(*args):
|
||||
return _P5_INSTANCE.deviceMoved(*args)
|
||||
|
||||
def deviceTurned(*args):
|
||||
return _P5_INSTANCE.deviceTurned(*args)
|
||||
|
||||
def deviceShaken(*args):
|
||||
return _P5_INSTANCE.deviceShaken(*args)
|
||||
|
||||
def keyPressed(*args):
|
||||
return _P5_INSTANCE.keyPressed(*args)
|
||||
|
||||
def keyReleased(*args):
|
||||
return _P5_INSTANCE.keyReleased(*args)
|
||||
|
||||
def keyTyped(*args):
|
||||
return _P5_INSTANCE.keyTyped(*args)
|
||||
|
||||
def keyIsDown(*args):
|
||||
return _P5_INSTANCE.keyIsDown(*args)
|
||||
|
||||
def mouseMoved(*args):
|
||||
return _P5_INSTANCE.mouseMoved(*args)
|
||||
|
||||
def mouseDragged(*args):
|
||||
return _P5_INSTANCE.mouseDragged(*args)
|
||||
|
||||
def mousePressed(*args):
|
||||
return _P5_INSTANCE.mousePressed(*args)
|
||||
|
||||
def mouseReleased(*args):
|
||||
return _P5_INSTANCE.mouseReleased(*args)
|
||||
|
||||
def mouseClicked(*args):
|
||||
return _P5_INSTANCE.mouseClicked(*args)
|
||||
|
||||
def doubleClicked(*args):
|
||||
return _P5_INSTANCE.doubleClicked(*args)
|
||||
|
||||
def mouseWheel(*args):
|
||||
return _P5_INSTANCE.mouseWheel(*args)
|
||||
|
||||
def touchStarted(*args):
|
||||
return _P5_INSTANCE.touchStarted(*args)
|
||||
|
||||
def touchMoved(*args):
|
||||
return _P5_INSTANCE.touchMoved(*args)
|
||||
|
||||
def touchEnded(*args):
|
||||
return _P5_INSTANCE.touchEnded(*args)
|
||||
|
||||
def createImage(*args):
|
||||
return _P5_INSTANCE.createImage(*args)
|
||||
|
||||
|
@ -740,6 +686,13 @@ def setCamera(*args):
|
|||
return _P5_INSTANCE.setCamera(*args)
|
||||
|
||||
|
||||
|
||||
def pop(*args):
|
||||
__pragma__('noalias', 'pop')
|
||||
p5_pop = _P5_INSTANCE.pop(*args)
|
||||
__pragma__('alias', 'pop', 'py_pop')
|
||||
return p5_pop
|
||||
|
||||
HALF_PI = None
|
||||
PI = None
|
||||
QUARTER_PI = None
|
||||
|
@ -747,6 +700,17 @@ TAU = None
|
|||
TWO_PI = None
|
||||
DEGREES = None
|
||||
RADIANS = None
|
||||
CLOSE = None
|
||||
RGB = None
|
||||
HSB = None
|
||||
CMYK = None
|
||||
TOP = None
|
||||
BOTTOM = None
|
||||
CENTER = None
|
||||
LEFT = None
|
||||
RIGHT = None
|
||||
SHIFT = None
|
||||
WEBGL = None
|
||||
frameCount = None
|
||||
focused = None
|
||||
displayWidth = None
|
||||
|
@ -790,7 +754,7 @@ def pre_draw(p5_instance, draw_func):
|
|||
"""
|
||||
We need to run this before the actual draw to insert and update p5 env variables
|
||||
"""
|
||||
global HALF_PI, PI, QUARTER_PI, TAU, TWO_PI, DEGREES, RADIANS, frameCount, focused, displayWidth, displayHeight, windowWidth, windowHeight, width, height, disableFriendlyErrors, deviceOrientation, accelerationX, accelerationY, accelerationZ, pAccelerationX, pAccelerationY, pAccelerationZ, rotationX, rotationY, rotationZ, pRotationX, pRotationY, pRotationZ, turnAxis, keyIsPressed, key, keyCode, mouseX, mouseY, pmouseX, pmouseY, winMouseX, winMouseY, pwinMouseX, pwinMouseY, mouseButton, mouseIsPressed, touches, pixels
|
||||
global HALF_PI, PI, QUARTER_PI, TAU, TWO_PI, DEGREES, RADIANS, CLOSE, RGB, HSB, CMYK, TOP, BOTTOM, CENTER, LEFT, RIGHT, SHIFT, WEBGL, frameCount, focused, displayWidth, displayHeight, windowWidth, windowHeight, width, height, disableFriendlyErrors, deviceOrientation, accelerationX, accelerationY, accelerationZ, pAccelerationX, pAccelerationY, pAccelerationZ, rotationX, rotationY, rotationZ, pRotationX, pRotationY, pRotationZ, turnAxis, keyIsPressed, key, keyCode, mouseX, mouseY, pmouseX, pmouseY, winMouseX, winMouseY, pwinMouseX, pwinMouseY, mouseButton, mouseIsPressed, touches, pixels
|
||||
|
||||
HALF_PI = p5_instance.HALF_PI
|
||||
PI = p5_instance.PI
|
||||
|
@ -799,6 +763,17 @@ def pre_draw(p5_instance, draw_func):
|
|||
TWO_PI = p5_instance.TWO_PI
|
||||
DEGREES = p5_instance.DEGREES
|
||||
RADIANS = p5_instance.RADIANS
|
||||
CLOSE = p5_instance.CLOSE
|
||||
RGB = p5_instance.RGB
|
||||
HSB = p5_instance.HSB
|
||||
CMYK = p5_instance.CMYK
|
||||
TOP = p5_instance.TOP
|
||||
BOTTOM = p5_instance.BOTTOM
|
||||
CENTER = p5_instance.CENTER
|
||||
LEFT = p5_instance.LEFT
|
||||
RIGHT = p5_instance.RIGHT
|
||||
SHIFT = p5_instance.SHIFT
|
||||
WEBGL = p5_instance.WEBGL
|
||||
frameCount = p5_instance.frameCount
|
||||
focused = p5_instance.focused
|
||||
displayWidth = p5_instance.displayWidth
|
||||
|
@ -857,12 +832,14 @@ def global_p5_injection(p5_sketch):
|
|||
return decorator
|
||||
|
||||
|
||||
def start_p5(setup_func, draw_func):
|
||||
def start_p5(setup_func, draw_func, event_functions):
|
||||
"""
|
||||
This is the entrypoint function. It accepts 2 parameters:
|
||||
|
||||
- setup_func: a Python setup callable
|
||||
- draw_func: a Python draw callable
|
||||
- event_functions: a config dict for the event functions in the format:
|
||||
{"eventFunctionName": python_event_function}
|
||||
|
||||
This method gets the p5js's sketch instance and injects them
|
||||
"""
|
||||
|
@ -871,4 +848,12 @@ def start_p5(setup_func, draw_func):
|
|||
p5_sketch.setup = global_p5_injection(p5_sketch)(setup_func)
|
||||
p5_sketch.draw = global_p5_injection(p5_sketch)(draw_func)
|
||||
|
||||
return __new__ (p5(sketch_setup, 'sketch-holder'))
|
||||
instance = __new__ (p5(sketch_setup, 'sketch-holder'))
|
||||
|
||||
# inject event functions into p5
|
||||
event_function_names = ["deviceMoved", "deviceTurned", "deviceShaken", "keyPressed", "keyReleased", "keyTyped", "mouseMoved", "mouseDragged", "mousePressed", "mouseReleased", "mouseClicked", "doubleClicked", "mouseWheel", "touchStarted", "touchMoved", "touchEnded", "windowResized", ]
|
||||
|
||||
for f_name in [f for f in event_function_names if f in event_functions]:
|
||||
func = event_functions[f_name]
|
||||
event_func = global_p5_injection(instance)(func)
|
||||
setattr(instance, f_name, event_func)
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-26 00:13:39
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
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,18 +1,22 @@
|
|||
// Transcrypt'ed from Python, 2019-05-26 00:13:39
|
||||
// Transcrypt'ed from Python, 2019-05-27 10:40:32
|
||||
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';
|
||||
import {DEGREES, HALF_PI, PI, QUARTER_PI, RADIANS, TAU, TWO_PI, _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, deviceMoved, deviceOrientation, deviceShaken, deviceTurned, directionalLight, disableFriendlyErrors, displayDensity, displayHeight, displayWidth, dist, doubleClicked, 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, keyPressed, keyReleased, keyTyped, 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, mouseClicked, mouseDragged, mouseIsPressed, mouseMoved, mousePressed, mouseReleased, mouseWheel, 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, 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, touchEnded, touchMoved, touchStarted, touches, translate, triangle, trim, turnAxis, unchar, unhex, updatePixels, vertex, width, winMouseX, winMouseY, windowHeight, windowResized, windowWidth, year} from './pyp5js.js';
|
||||
import {BOTTOM, CENTER, CLOSE, CMYK, DEGREES, HALF_PI, HSB, LEFT, PI, QUARTER_PI, RADIANS, RGB, RIGHT, SHIFT, TAU, TOP, TWO_PI, WEBGL, _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, 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 W = null;
|
||||
export var H = null;
|
||||
export var num = null;
|
||||
export var H = null;
|
||||
export var W = null;
|
||||
export var line_combos = null;
|
||||
export var space = 15;
|
||||
export var position = 0;
|
||||
export var setup = function () {
|
||||
createCanvas (1045, 700);
|
||||
var __left0__ = tuple ([1045, 700]);
|
||||
var width = __left0__ [0];
|
||||
var height = __left0__ [1];
|
||||
frameRate (5);
|
||||
rectMode (CENTER);
|
||||
strokeWeight (2);
|
||||
var grid = product (range (-(1), 2), __kwargtrans__ ({repeat: 2}));
|
||||
var lines = combinations (grid, 2);
|
||||
|
@ -33,7 +37,7 @@ export var setup = function () {
|
|||
shuffle (line_combos);
|
||||
num = len (line_combos);
|
||||
print (num);
|
||||
var __left0__ = tuple ([(width - space) / space, (height - space) / space]);
|
||||
var __left0__ = tuple ([Math.floor ((width - space) / space), Math.floor ((height - space) / space)]);
|
||||
W = __left0__ [0];
|
||||
H = __left0__ [1];
|
||||
print (tuple ([W, H, W * H]));
|
||||
|
@ -57,9 +61,10 @@ export var draw = function () {
|
|||
}
|
||||
};
|
||||
export var draw_combo = function (i) {
|
||||
colorMode (RGB);
|
||||
var siz = space / 3.0;
|
||||
for (var [i, sl] of enumerate (line_combos [i])) {
|
||||
colorMode (p5.HSB);
|
||||
colorMode (HSB, 255, 255, 255);
|
||||
stroke (i * 64, 160, 160);
|
||||
var __left0__ = tuple ([sl [0], sl [1]]);
|
||||
var x0 = __left0__ [0][0];
|
||||
|
@ -69,7 +74,12 @@ export var draw_combo = function (i) {
|
|||
line (x0 * siz, y0 * siz, x1 * siz, y1 * siz);
|
||||
}
|
||||
};
|
||||
export var event_functions = dict ({'keyPressed': 'keyPressed'});
|
||||
export var keyPressed = function () {
|
||||
if (key == 's') {
|
||||
saveFrame ('####.png');
|
||||
}
|
||||
};
|
||||
export var event_functions = dict ({'keyPressed': keyPressed});
|
||||
start_p5 (setup, draw, event_functions);
|
||||
|
||||
//# sourceMappingURL=sketch_190525b.map
|
|
@ -4,5 +4,5 @@
|
|||
"sources": [
|
||||
"sketch_190525b.py"
|
||||
],
|
||||
"mappings": "AAAA;AAGA;AASA;AADA;AARA;AAHA;AAKA;AACA;AACA;AACA;AAKA;AACA;AAGA;AAEA;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;AASA;AACA;AAtEA"
|
||||
"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"
|
||||
}
|
|
@ -1,14 +1,13 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
# More explorations of lines in grids
|
||||
|
||||
from pyp5js import *
|
||||
from pytop5js import *
|
||||
|
||||
W = None
|
||||
H = None
|
||||
num = None
|
||||
H = None
|
||||
W = None
|
||||
line_combos = None
|
||||
|
||||
|
||||
from random import shuffle
|
||||
from itertools import product, combinations, permutations, combinations_with_replacement
|
||||
space = 15
|
||||
|
@ -18,7 +17,9 @@ position = 0 # initial position
|
|||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
createCanvas(1045, 700)
|
||||
width, height = 1045, 700
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(2)
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# all possible lines
|
||||
|
@ -36,7 +37,7 @@ def setup():
|
|||
shuffle(line_combos)
|
||||
num = len(line_combos)
|
||||
print(num)
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
W, H = (width - space) // space, (height - space) // space
|
||||
print((W, H, W * H))
|
||||
|
||||
|
||||
|
@ -56,19 +57,19 @@ def draw():
|
|||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
colorMode(RGB)
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
colorMode(p5.HSB)
|
||||
colorMode(HSB, 255, 255, 255)
|
||||
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 keyPressed():
|
||||
if key == "s":
|
||||
saveFrame("####.png")
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
# Register your events functions here
|
||||
event_functions = {'keyPressed': 'keyPressed'}
|
||||
start_p5(setup, draw, event_functions)
|
||||
event_functions = {"keyPressed" : keyPressed, }
|
||||
start_p5(setup, draw, event_functions)
|
Po Szerokość: | Wysokość: | Rozmiar: 331 KiB |
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()
|
Po Szerokość: | Wysokość: | Rozmiar: 627 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 323 KiB |
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())
|
||||
)
|
Po Szerokość: | Wysokość: | Rozmiar: 331 KiB |
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()
|
Po Szerokość: | Wysokość: | Rozmiar: 627 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 323 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 322 KiB |
|
@ -0,0 +1,84 @@
|
|||
# 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(620, 630)
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(2)
|
||||
# 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) > 2: # 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(permutations(short_lines, 2))
|
||||
# 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)
|
||||
if i: stroke(0, 0, 128)
|
||||
else: stroke(0)
|
||||
(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())
|
||||
)
|