kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
498b49dbbc
commit
8e62a8d551
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 157 KiB |
|
@ -12,7 +12,7 @@ position = 0 # initial position
|
|||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
size(1025, 720)
|
||||
size(1045, 700)
|
||||
frameRate(5)
|
||||
rectMode(CENTER)
|
||||
strokeWeight(2)
|
||||
|
@ -38,16 +38,13 @@ def setup():
|
|||
# shuffle(line_combos)
|
||||
num = len(line_combos)
|
||||
print line_combos
|
||||
W, H = (width - 20 - space) / space, (height - 20 - space) / space
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
print(W, H)
|
||||
|
||||
|
||||
def draw():
|
||||
global position
|
||||
background(240)
|
||||
# fill(0)
|
||||
# textSize(24)
|
||||
# text(str(num), space, height - space/4)
|
||||
i = position
|
||||
for y in range(H):
|
||||
for x in range(W):
|
||||
|
|
|
@ -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: 2.3 MiB |
|
@ -0,0 +1,85 @@
|
|||
# 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 = 15
|
||||
position = 0 # initial position
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
size(1045, 700)
|
||||
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) < 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))
|
||||
# line_combos = []
|
||||
# for n in range(9):
|
||||
# line_combos += list(combinations(short_lines, n))
|
||||
shuffle(line_combos)
|
||||
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
|
||||
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 = ".gif"
|
||||
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>sketch_190525b - pyp5js</title>
|
||||
<style> body, html, canvas {padding: 0; margin: 0; overflow: hidden;} </style>
|
||||
|
||||
<script src="static/p5.js"></script>
|
||||
<script src="target/sketch_190525b.js" type="module"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="sketch-holder">
|
||||
<!-- You sketch will go here! -->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,72 @@
|
|||
from pyp5js import *
|
||||
W = None
|
||||
H = None
|
||||
position = None
|
||||
num = None
|
||||
line_combos = None
|
||||
# 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
|
||||
space = 15
|
||||
position = 0 # initial position
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
createCanvas(1045, 700)
|
||||
frameRate(5)
|
||||
strokeWeight(2)
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# 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)
|
||||
print("Number of possible lines: {}".format(num_short_lines))
|
||||
# main stuff
|
||||
line_combos = list(combinations(short_lines, 4))
|
||||
shuffle(line_combos)
|
||||
num = len(line_combos)
|
||||
print(num)
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
print((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):
|
||||
push()
|
||||
translate(space + space * x, space + space * y)
|
||||
draw_combo(i)
|
||||
P5.pop()
|
||||
i += 1
|
||||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
colorMode(p5.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")
|
||||
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
# Register your events functions here
|
||||
event_functions = {'keyPressed': 'keyPressed'}
|
||||
start_p5(setup, draw, event_functions)
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,298 @@
|
|||
import {list, tuple, len, __kwargtrans__, set} from './org.transcrypt.__runtime__.js';
|
||||
|
||||
var __name__ = 'itertools';
|
||||
|
||||
export var count = function* (start, step) {
|
||||
if (start == undefined) {
|
||||
start = 0;
|
||||
}
|
||||
if (step == undefined) {
|
||||
step = 1;
|
||||
}
|
||||
while (true) {
|
||||
yield start;
|
||||
start += step;
|
||||
}
|
||||
}
|
||||
export var cycle = function* (iterable) {
|
||||
let buffer = Array.from (iterable); // Can't reset, Chrome can't obtain iter from gener
|
||||
while (true) {
|
||||
for (let item of buffer) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var repeat = function* (item, n) {
|
||||
if (typeof n == 'undefined') {
|
||||
while (true) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let index = 0; index < n; index++) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var accumulate = function* (iterable, func) {
|
||||
let sum;
|
||||
let first = true;
|
||||
if (func) {
|
||||
for (let item of iterable) {
|
||||
if (first) {
|
||||
sum = item;
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
sum = func (sum, item);
|
||||
}
|
||||
yield sum;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let item of iterable) {
|
||||
if (first) {
|
||||
sum = item;
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
sum = sum + item;
|
||||
}
|
||||
yield sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var chain = function* () {
|
||||
let args = [] .slice.apply (arguments);
|
||||
for (let arg of args) {
|
||||
for (let item of arg) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
chain.from_iterable = function* (iterable) {
|
||||
for (let item of iterable) {
|
||||
for (let subItem of item) {
|
||||
yield subItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var compress = function* (data, selectors) {
|
||||
let dataIterator = data [Symbol.iterator] .call (data);
|
||||
let selectorsIterator = selectors [Symbol.iterator] ();
|
||||
while (true) {
|
||||
let dataItem = dataIterator.next ();
|
||||
let selectorsItem = selectorsIterator.next ();
|
||||
if (dataItem.done || selectorsItem.done) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (selectorsItem.value) {
|
||||
yield dataItem.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export var dropwhile = function* (pred, seq) {
|
||||
let started = false;
|
||||
for (let item of seq) {
|
||||
if (started) {
|
||||
yield item;
|
||||
}
|
||||
else if (!pred (item)) {
|
||||
started = true;
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var filterfalse = function* (pred, seq) {
|
||||
for (let item of seq) {
|
||||
if (!pred (item)) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var groupby = function* (iterable, keyfunc) {
|
||||
let anIterator = iterable [Symbol.iterator] ();
|
||||
let item = anIterator.next ();
|
||||
|
||||
if (item.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
let groupKey = keyfunc (item.value);
|
||||
let more = true;
|
||||
|
||||
function* group () {
|
||||
while (true) {
|
||||
yield (item.value);
|
||||
item = anIterator.next ();
|
||||
|
||||
if (item.done) {
|
||||
more = false;
|
||||
return;
|
||||
}
|
||||
|
||||
let key = keyfunc (item.value);
|
||||
|
||||
if (key != groupKey) {
|
||||
groupKey = key;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (more) {
|
||||
yield tuple ([groupKey, group ()]);
|
||||
}
|
||||
}
|
||||
export var islice = function* () {
|
||||
let start; // Have to be defined at function level, or Closure compiler will loose them after a yield
|
||||
let stop; //
|
||||
let step; //
|
||||
|
||||
let args = [] .slice.apply (arguments);
|
||||
let anIterator = args [0][Symbol.iterator] ();
|
||||
if (args.length == 2) {
|
||||
stop = args [1];
|
||||
start = 0;
|
||||
step = 1;
|
||||
}
|
||||
else {
|
||||
start = args [1];
|
||||
stop = args [2];
|
||||
if (args.length == 4) {
|
||||
step = args [3];
|
||||
}
|
||||
else {
|
||||
step = 1;
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < start; index++) {
|
||||
if (anIterator.next (). done) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < stop - start; index++) {
|
||||
let next = anIterator.next ();
|
||||
if (next.done) {
|
||||
return;
|
||||
}
|
||||
if (index % step == 0) {
|
||||
yield next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var starmap = function* (func, seq) {
|
||||
let anIterator = seq [Symbol.iterator] ();
|
||||
while (true) {
|
||||
let next = anIterator.next ()
|
||||
if (next.done) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
yield func (...next.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
export var takewhile = function* (pred, seq) {
|
||||
for (let item of seq) {
|
||||
if (pred (item)) {
|
||||
yield item;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
export var tee = function (iterable, n) {
|
||||
if (n == undefined) {
|
||||
n = 2;
|
||||
}
|
||||
let all = []; // Don't return iterator since destructuring assignment cannot yet deal with that
|
||||
let one = list (iterable);
|
||||
for (let i = 0; i < n; i++) {
|
||||
all.append (one [Symbol.iterator] ()); // Iterator rather than list, exhaustable for semantic equivalence
|
||||
}
|
||||
return list (all);
|
||||
}
|
||||
|
||||
export var product = function () {
|
||||
let args = [] .slice.apply (arguments);
|
||||
if (args.length && args [args.length - 1] .hasOwnProperty ('__kwargtrans__')) {
|
||||
var repeat = args.pop () ['repeat'];
|
||||
}
|
||||
else {
|
||||
var repeat = 1;
|
||||
}
|
||||
|
||||
let oldMolecules = [tuple ([])];
|
||||
for (let i = 0; i < repeat; i++) {
|
||||
for (let arg of args) {
|
||||
let newMolecules = [];
|
||||
for (let oldMolecule of oldMolecules) {
|
||||
for (let atom of arg) {
|
||||
newMolecules.append (tuple (oldMolecule.concat (atom)));
|
||||
}
|
||||
}
|
||||
oldMolecules = newMolecules;
|
||||
}
|
||||
}
|
||||
return list (oldMolecules); // Also works if args is emptpy
|
||||
}
|
||||
export var permutations = function (iterable, r) {
|
||||
if (r == undefined) {
|
||||
try {
|
||||
r = len (iterable);
|
||||
}
|
||||
catch (exception) {
|
||||
r = len (list (iterable));
|
||||
}
|
||||
}
|
||||
let aProduct = product (iterable, __kwargtrans__ ({repeat: r}));
|
||||
let result = [];
|
||||
for (let molecule of aProduct) {
|
||||
if (len (set (molecule)) == r) { // Weed out doubles
|
||||
result.append (molecule);
|
||||
}
|
||||
}
|
||||
return list (result);
|
||||
}
|
||||
export var combinations = function (iterable, r) {
|
||||
let tail = list (iterable);
|
||||
function recurse (tail, molecule, rNext) {
|
||||
for (let index = 0; index < len (tail) - rNext; index++) {
|
||||
let newMolecule = molecule.concat (tail.slice (index, index + 1));
|
||||
|
||||
if (rNext) {
|
||||
recurse (tail.slice (index + 1), newMolecule, rNext - 1);
|
||||
}
|
||||
else {
|
||||
result.append (tuple (newMolecule));
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = [];
|
||||
recurse (tail, tail.slice (0, 0), r - 1);
|
||||
return list (result);
|
||||
}
|
||||
export var combinations_with_replacement = function (iterable, r) {
|
||||
let tail = list (iterable);
|
||||
function recurse (tail, molecule, rNext) {
|
||||
for (let index = 0; index < len (tail); index++) {
|
||||
let newMolecule = molecule.concat (tail.slice (index, index + 1));
|
||||
|
||||
if (rNext) {
|
||||
recurse (tail.slice (index), newMolecule, rNext - 1);
|
||||
}
|
||||
else {
|
||||
result.append (tuple (newMolecule));
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = [];
|
||||
recurse (tail, tail.slice (0, 0), r - 1);
|
||||
return list (result);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=itertools.map
|
|
@ -0,0 +1,58 @@
|
|||
// Transcrypt'ed from Python, 2019-05-25 23:56:17
|
||||
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;
|
||||
export var e = Math.E;
|
||||
export var exp = Math.exp;
|
||||
export var expm1 = function (x) {
|
||||
return Math.exp (x) - 1;
|
||||
};
|
||||
export var log = function (x, base) {
|
||||
return (base === undefined ? Math.log (x) : Math.log (x) / Math.log (base));
|
||||
};
|
||||
export var log1p = function (x) {
|
||||
return Math.log (x + 1);
|
||||
};
|
||||
export var log2 = function (x) {
|
||||
return Math.log (x) / Math.LN2;
|
||||
};
|
||||
export var log10 = function (x) {
|
||||
return Math.log (x) / Math.LN10;
|
||||
};
|
||||
export var pow = Math.pow;
|
||||
export var sqrt = Math.sqrt;
|
||||
export var sin = Math.sin;
|
||||
export var cos = Math.cos;
|
||||
export var tan = Math.tan;
|
||||
export var asin = Math.asin;
|
||||
export var acos = Math.acos;
|
||||
export var atan = Math.atan;
|
||||
export var atan2 = Math.atan2;
|
||||
export var hypot = Math.hypot;
|
||||
export var degrees = function (x) {
|
||||
return (x * 180) / Math.PI;
|
||||
};
|
||||
export var radians = function (x) {
|
||||
return (x * Math.PI) / 180;
|
||||
};
|
||||
export var sinh = Math.sinh;
|
||||
export var cosh = Math.cosh;
|
||||
export var tanh = Math.tanh;
|
||||
export var asinh = Math.asinh;
|
||||
export var acosh = Math.acosh;
|
||||
export var atanh = Math.atanh;
|
||||
export var floor = Math.floor;
|
||||
export var ceil = Math.ceil;
|
||||
export var trunc = Math.trunc;
|
||||
export var isnan = isNaN;
|
||||
export var inf = Infinity;
|
||||
export var nan = NaN;
|
||||
export var modf = function (n) {
|
||||
var sign = (n >= 0 ? 1 : -(1));
|
||||
var __left0__ = divmod (abs (n), 1);
|
||||
var f = __left0__ [0];
|
||||
var mod = __left0__ [1];
|
||||
return tuple ([mod * sign, f * sign]);
|
||||
};
|
||||
|
||||
//# sourceMappingURL=math.map
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "math.js",
|
||||
"sources": [
|
||||
"math.py"
|
||||
],
|
||||
"mappings": "AAAA;AA4DA;AA5DA;AAAA;AACA;AAEA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AAAA;AAAA;AACA;AAAA;AAAA"
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
pi = Math.PI
|
||||
e = Math.E
|
||||
|
||||
exp = Math.exp
|
||||
|
||||
def expm1 (x): # IE workaround
|
||||
return Math.exp (x) - 1
|
||||
|
||||
def log (x, base):
|
||||
return Math.log (x) if base is js_undefined else Math.log (x) / Math.log (base)
|
||||
|
||||
def log1p (x): # IE workaround
|
||||
return Math.log (x + 1)
|
||||
|
||||
def log2 (x): # IE workaround
|
||||
return Math.log (x) / Math.LN2
|
||||
|
||||
def log10 (x): # IE workaround
|
||||
return Math.log (x) / Math.LN10
|
||||
|
||||
pow = Math.pow
|
||||
sqrt = Math.sqrt
|
||||
|
||||
sin = Math.sin
|
||||
cos = Math.cos
|
||||
tan = Math.tan
|
||||
|
||||
asin = Math.asin
|
||||
acos = Math.acos
|
||||
atan = Math.atan
|
||||
atan2 = Math.atan2
|
||||
|
||||
hypot = Math.hypot
|
||||
|
||||
def degrees (x):
|
||||
return x * 180 / Math.PI
|
||||
|
||||
def radians (x):
|
||||
return x * Math.PI / 180
|
||||
|
||||
sinh = Math.sinh
|
||||
cosh = Math.cosh
|
||||
tanh = Math.tanh
|
||||
|
||||
asinh = Math.asinh
|
||||
acosh = Math.acosh
|
||||
atanh = Math.atanh
|
||||
|
||||
floor = Math.floor
|
||||
ceil = Math.ceil
|
||||
trunc = Math.trunc
|
||||
|
||||
isnan = js_isNaN
|
||||
|
||||
inf = js_Infinity
|
||||
nan = js_NaN
|
||||
|
||||
def modf(n):
|
||||
sign = 1 if n >= 0 else -1
|
||||
f, mod = divmod (abs(n), 1)
|
||||
return mod * sign, f * sign
|
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
|
@ -0,0 +1,874 @@
|
|||
_P5_INSTANCE = None
|
||||
|
||||
|
||||
def alpha(*args):
|
||||
return _P5_INSTANCE.alpha(*args)
|
||||
|
||||
def blue(*args):
|
||||
return _P5_INSTANCE.blue(*args)
|
||||
|
||||
def brightness(*args):
|
||||
return _P5_INSTANCE.brightness(*args)
|
||||
|
||||
def color(*args):
|
||||
return _P5_INSTANCE.color(*args)
|
||||
|
||||
def green(*args):
|
||||
return _P5_INSTANCE.green(*args)
|
||||
|
||||
def hue(*args):
|
||||
return _P5_INSTANCE.hue(*args)
|
||||
|
||||
def lerpColor(*args):
|
||||
return _P5_INSTANCE.lerpColor(*args)
|
||||
|
||||
def lightness(*args):
|
||||
return _P5_INSTANCE.lightness(*args)
|
||||
|
||||
def red(*args):
|
||||
return _P5_INSTANCE.red(*args)
|
||||
|
||||
def saturation(*args):
|
||||
return _P5_INSTANCE.saturation(*args)
|
||||
|
||||
def background(*args):
|
||||
return _P5_INSTANCE.background(*args)
|
||||
|
||||
def clear(*args):
|
||||
return _P5_INSTANCE.clear(*args)
|
||||
|
||||
def colorMode(*args):
|
||||
return _P5_INSTANCE.colorMode(*args)
|
||||
|
||||
def fill(*args):
|
||||
return _P5_INSTANCE.fill(*args)
|
||||
|
||||
def noFill(*args):
|
||||
return _P5_INSTANCE.noFill(*args)
|
||||
|
||||
def noStroke(*args):
|
||||
return _P5_INSTANCE.noStroke(*args)
|
||||
|
||||
def stroke(*args):
|
||||
return _P5_INSTANCE.stroke(*args)
|
||||
|
||||
def arc(*args):
|
||||
return _P5_INSTANCE.arc(*args)
|
||||
|
||||
def ellipse(*args):
|
||||
return _P5_INSTANCE.ellipse(*args)
|
||||
|
||||
def circle(*args):
|
||||
return _P5_INSTANCE.circle(*args)
|
||||
|
||||
def line(*args):
|
||||
return _P5_INSTANCE.line(*args)
|
||||
|
||||
def point(*args):
|
||||
return _P5_INSTANCE.point(*args)
|
||||
|
||||
def quad(*args):
|
||||
return _P5_INSTANCE.quad(*args)
|
||||
|
||||
def rect(*args):
|
||||
return _P5_INSTANCE.rect(*args)
|
||||
|
||||
def square(*args):
|
||||
return _P5_INSTANCE.square(*args)
|
||||
|
||||
def triangle(*args):
|
||||
return _P5_INSTANCE.triangle(*args)
|
||||
|
||||
def plane(*args):
|
||||
return _P5_INSTANCE.plane(*args)
|
||||
|
||||
def box(*args):
|
||||
return _P5_INSTANCE.box(*args)
|
||||
|
||||
def sphere(*args):
|
||||
return _P5_INSTANCE.sphere(*args)
|
||||
|
||||
def cylinder(*args):
|
||||
return _P5_INSTANCE.cylinder(*args)
|
||||
|
||||
def cone(*args):
|
||||
return _P5_INSTANCE.cone(*args)
|
||||
|
||||
def ellipsoid(*args):
|
||||
return _P5_INSTANCE.ellipsoid(*args)
|
||||
|
||||
def torus(*args):
|
||||
return _P5_INSTANCE.torus(*args)
|
||||
|
||||
def loadModel(*args):
|
||||
return _P5_INSTANCE.loadModel(*args)
|
||||
|
||||
def model(*args):
|
||||
return _P5_INSTANCE.model(*args)
|
||||
|
||||
def ellipseMode(*args):
|
||||
return _P5_INSTANCE.ellipseMode(*args)
|
||||
|
||||
def noSmooth(*args):
|
||||
return _P5_INSTANCE.noSmooth(*args)
|
||||
|
||||
def rectMode(*args):
|
||||
return _P5_INSTANCE.rectMode(*args)
|
||||
|
||||
def smooth(*args):
|
||||
return _P5_INSTANCE.smooth(*args)
|
||||
|
||||
def strokeCap(*args):
|
||||
return _P5_INSTANCE.strokeCap(*args)
|
||||
|
||||
def strokeJoin(*args):
|
||||
return _P5_INSTANCE.strokeJoin(*args)
|
||||
|
||||
def strokeWeight(*args):
|
||||
return _P5_INSTANCE.strokeWeight(*args)
|
||||
|
||||
def bezier(*args):
|
||||
return _P5_INSTANCE.bezier(*args)
|
||||
|
||||
def bezierDetail(*args):
|
||||
return _P5_INSTANCE.bezierDetail(*args)
|
||||
|
||||
def bezierPoint(*args):
|
||||
return _P5_INSTANCE.bezierPoint(*args)
|
||||
|
||||
def bezierTangent(*args):
|
||||
return _P5_INSTANCE.bezierTangent(*args)
|
||||
|
||||
def curve(*args):
|
||||
return _P5_INSTANCE.curve(*args)
|
||||
|
||||
def curveDetail(*args):
|
||||
return _P5_INSTANCE.curveDetail(*args)
|
||||
|
||||
def curveTightness(*args):
|
||||
return _P5_INSTANCE.curveTightness(*args)
|
||||
|
||||
def curvePoint(*args):
|
||||
return _P5_INSTANCE.curvePoint(*args)
|
||||
|
||||
def curveTangent(*args):
|
||||
return _P5_INSTANCE.curveTangent(*args)
|
||||
|
||||
def beginContour(*args):
|
||||
return _P5_INSTANCE.beginContour(*args)
|
||||
|
||||
def beginShape(*args):
|
||||
return _P5_INSTANCE.beginShape(*args)
|
||||
|
||||
def bezierVertex(*args):
|
||||
return _P5_INSTANCE.bezierVertex(*args)
|
||||
|
||||
def curveVertex(*args):
|
||||
return _P5_INSTANCE.curveVertex(*args)
|
||||
|
||||
def endContour(*args):
|
||||
return _P5_INSTANCE.endContour(*args)
|
||||
|
||||
def endShape(*args):
|
||||
return _P5_INSTANCE.endShape(*args)
|
||||
|
||||
def quadraticVertex(*args):
|
||||
return _P5_INSTANCE.quadraticVertex(*args)
|
||||
|
||||
def vertex(*args):
|
||||
return _P5_INSTANCE.vertex(*args)
|
||||
|
||||
def print(*args):
|
||||
return _P5_INSTANCE.print(*args)
|
||||
|
||||
def cursor(*args):
|
||||
return _P5_INSTANCE.cursor(*args)
|
||||
|
||||
def frameRate(*args):
|
||||
return _P5_INSTANCE.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)
|
||||
|
||||
def pixelDensity(*args):
|
||||
return _P5_INSTANCE.pixelDensity(*args)
|
||||
|
||||
def displayDensity(*args):
|
||||
return _P5_INSTANCE.displayDensity(*args)
|
||||
|
||||
def getURL(*args):
|
||||
return _P5_INSTANCE.getURL(*args)
|
||||
|
||||
def getURLPath(*args):
|
||||
return _P5_INSTANCE.getURLPath(*args)
|
||||
|
||||
def getURLParams(*args):
|
||||
return _P5_INSTANCE.getURLParams(*args)
|
||||
|
||||
def preload(*args):
|
||||
return _P5_INSTANCE.preload(*args)
|
||||
|
||||
def setup(*args):
|
||||
return _P5_INSTANCE.setup(*args)
|
||||
|
||||
def draw(*args):
|
||||
return _P5_INSTANCE.draw(*args)
|
||||
|
||||
def remove(*args):
|
||||
return _P5_INSTANCE.remove(*args)
|
||||
|
||||
def noLoop(*args):
|
||||
return _P5_INSTANCE.noLoop(*args)
|
||||
|
||||
def loop(*args):
|
||||
return _P5_INSTANCE.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)
|
||||
|
||||
def createCanvas(*args):
|
||||
return _P5_INSTANCE.createCanvas(*args)
|
||||
|
||||
def resizeCanvas(*args):
|
||||
return _P5_INSTANCE.resizeCanvas(*args)
|
||||
|
||||
def noCanvas(*args):
|
||||
return _P5_INSTANCE.noCanvas(*args)
|
||||
|
||||
def createGraphics(*args):
|
||||
return _P5_INSTANCE.createGraphics(*args)
|
||||
|
||||
def blendMode(*args):
|
||||
return _P5_INSTANCE.blendMode(*args)
|
||||
|
||||
def setAttributes(*args):
|
||||
return _P5_INSTANCE.setAttributes(*args)
|
||||
|
||||
def applyMatrix(*args):
|
||||
return _P5_INSTANCE.applyMatrix(*args)
|
||||
|
||||
def resetMatrix(*args):
|
||||
return _P5_INSTANCE.resetMatrix(*args)
|
||||
|
||||
def rotate(*args):
|
||||
return _P5_INSTANCE.rotate(*args)
|
||||
|
||||
def rotateX(*args):
|
||||
return _P5_INSTANCE.rotateX(*args)
|
||||
|
||||
def rotateY(*args):
|
||||
return _P5_INSTANCE.rotateY(*args)
|
||||
|
||||
def rotateZ(*args):
|
||||
return _P5_INSTANCE.rotateZ(*args)
|
||||
|
||||
def scale(*args):
|
||||
return _P5_INSTANCE.scale(*args)
|
||||
|
||||
def shearX(*args):
|
||||
return _P5_INSTANCE.shearX(*args)
|
||||
|
||||
def shearY(*args):
|
||||
return _P5_INSTANCE.shearY(*args)
|
||||
|
||||
def translate(*args):
|
||||
return _P5_INSTANCE.translate(*args)
|
||||
|
||||
def createStringDict(*args):
|
||||
return _P5_INSTANCE.createStringDict(*args)
|
||||
|
||||
def createNumberDict(*args):
|
||||
return _P5_INSTANCE.createNumberDict(*args)
|
||||
|
||||
def append(*args):
|
||||
return _P5_INSTANCE.append(*args)
|
||||
|
||||
def arrayCopy(*args):
|
||||
return _P5_INSTANCE.arrayCopy(*args)
|
||||
|
||||
def concat(*args):
|
||||
return _P5_INSTANCE.concat(*args)
|
||||
|
||||
def reverse(*args):
|
||||
return _P5_INSTANCE.reverse(*args)
|
||||
|
||||
def shorten(*args):
|
||||
return _P5_INSTANCE.shorten(*args)
|
||||
|
||||
def shuffle(*args):
|
||||
return _P5_INSTANCE.shuffle(*args)
|
||||
|
||||
def sort(*args):
|
||||
return _P5_INSTANCE.sort(*args)
|
||||
|
||||
def splice(*args):
|
||||
return _P5_INSTANCE.splice(*args)
|
||||
|
||||
def subset(*args):
|
||||
return _P5_INSTANCE.subset(*args)
|
||||
|
||||
def float(*args):
|
||||
return _P5_INSTANCE.float(*args)
|
||||
|
||||
def int(*args):
|
||||
return _P5_INSTANCE.int(*args)
|
||||
|
||||
def str(*args):
|
||||
return _P5_INSTANCE.str(*args)
|
||||
|
||||
def boolean(*args):
|
||||
return _P5_INSTANCE.boolean(*args)
|
||||
|
||||
def byte(*args):
|
||||
return _P5_INSTANCE.byte(*args)
|
||||
|
||||
def char(*args):
|
||||
return _P5_INSTANCE.char(*args)
|
||||
|
||||
def unchar(*args):
|
||||
return _P5_INSTANCE.unchar(*args)
|
||||
|
||||
def hex(*args):
|
||||
return _P5_INSTANCE.hex(*args)
|
||||
|
||||
def unhex(*args):
|
||||
return _P5_INSTANCE.unhex(*args)
|
||||
|
||||
def join(*args):
|
||||
return _P5_INSTANCE.join(*args)
|
||||
|
||||
def match(*args):
|
||||
return _P5_INSTANCE.match(*args)
|
||||
|
||||
def matchAll(*args):
|
||||
return _P5_INSTANCE.matchAll(*args)
|
||||
|
||||
def nf(*args):
|
||||
return _P5_INSTANCE.nf(*args)
|
||||
|
||||
def nfc(*args):
|
||||
return _P5_INSTANCE.nfc(*args)
|
||||
|
||||
def nfp(*args):
|
||||
return _P5_INSTANCE.nfp(*args)
|
||||
|
||||
def nfs(*args):
|
||||
return _P5_INSTANCE.nfs(*args)
|
||||
|
||||
def split(*args):
|
||||
return _P5_INSTANCE.split(*args)
|
||||
|
||||
def splitTokens(*args):
|
||||
return _P5_INSTANCE.splitTokens(*args)
|
||||
|
||||
def trim(*args):
|
||||
return _P5_INSTANCE.trim(*args)
|
||||
|
||||
def setMoveThreshold(*args):
|
||||
return _P5_INSTANCE.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)
|
||||
|
||||
def saveCanvas(*args):
|
||||
return _P5_INSTANCE.saveCanvas(*args)
|
||||
|
||||
def saveFrames(*args):
|
||||
return _P5_INSTANCE.saveFrames(*args)
|
||||
|
||||
def loadImage(*args):
|
||||
return _P5_INSTANCE.loadImage(*args)
|
||||
|
||||
def image(*args):
|
||||
return _P5_INSTANCE.image(*args)
|
||||
|
||||
def tint(*args):
|
||||
return _P5_INSTANCE.tint(*args)
|
||||
|
||||
def noTint(*args):
|
||||
return _P5_INSTANCE.noTint(*args)
|
||||
|
||||
def imageMode(*args):
|
||||
return _P5_INSTANCE.imageMode(*args)
|
||||
|
||||
def blend(*args):
|
||||
return _P5_INSTANCE.blend(*args)
|
||||
|
||||
def copy(*args):
|
||||
return _P5_INSTANCE.copy(*args)
|
||||
|
||||
def filter(*args):
|
||||
return _P5_INSTANCE.filter(*args)
|
||||
|
||||
def get(*args):
|
||||
return _P5_INSTANCE.get(*args)
|
||||
|
||||
def loadPixels(*args):
|
||||
return _P5_INSTANCE.loadPixels(*args)
|
||||
|
||||
def set(*args):
|
||||
return _P5_INSTANCE.set(*args)
|
||||
|
||||
def updatePixels(*args):
|
||||
return _P5_INSTANCE.updatePixels(*args)
|
||||
|
||||
def loadJSON(*args):
|
||||
return _P5_INSTANCE.loadJSON(*args)
|
||||
|
||||
def loadStrings(*args):
|
||||
return _P5_INSTANCE.loadStrings(*args)
|
||||
|
||||
def loadTable(*args):
|
||||
return _P5_INSTANCE.loadTable(*args)
|
||||
|
||||
def loadXML(*args):
|
||||
return _P5_INSTANCE.loadXML(*args)
|
||||
|
||||
def loadBytes(*args):
|
||||
return _P5_INSTANCE.loadBytes(*args)
|
||||
|
||||
def httpGet(*args):
|
||||
return _P5_INSTANCE.httpGet(*args)
|
||||
|
||||
def httpPost(*args):
|
||||
return _P5_INSTANCE.httpPost(*args)
|
||||
|
||||
def httpDo(*args):
|
||||
return _P5_INSTANCE.httpDo(*args)
|
||||
|
||||
def createWriter(*args):
|
||||
return _P5_INSTANCE.createWriter(*args)
|
||||
|
||||
def save(*args):
|
||||
return _P5_INSTANCE.save(*args)
|
||||
|
||||
def saveJSON(*args):
|
||||
return _P5_INSTANCE.saveJSON(*args)
|
||||
|
||||
def saveStrings(*args):
|
||||
return _P5_INSTANCE.saveStrings(*args)
|
||||
|
||||
def saveTable(*args):
|
||||
return _P5_INSTANCE.saveTable(*args)
|
||||
|
||||
def day(*args):
|
||||
return _P5_INSTANCE.day(*args)
|
||||
|
||||
def hour(*args):
|
||||
return _P5_INSTANCE.hour(*args)
|
||||
|
||||
def minute(*args):
|
||||
return _P5_INSTANCE.minute(*args)
|
||||
|
||||
def millis(*args):
|
||||
return _P5_INSTANCE.millis(*args)
|
||||
|
||||
def month(*args):
|
||||
return _P5_INSTANCE.month(*args)
|
||||
|
||||
def second(*args):
|
||||
return _P5_INSTANCE.second(*args)
|
||||
|
||||
def year(*args):
|
||||
return _P5_INSTANCE.year(*args)
|
||||
|
||||
def createVector(*args):
|
||||
return _P5_INSTANCE.createVector(*args)
|
||||
|
||||
def abs(*args):
|
||||
return _P5_INSTANCE.abs(*args)
|
||||
|
||||
def ceil(*args):
|
||||
return _P5_INSTANCE.ceil(*args)
|
||||
|
||||
def constrain(*args):
|
||||
return _P5_INSTANCE.constrain(*args)
|
||||
|
||||
def dist(*args):
|
||||
return _P5_INSTANCE.dist(*args)
|
||||
|
||||
def exp(*args):
|
||||
return _P5_INSTANCE.exp(*args)
|
||||
|
||||
def floor(*args):
|
||||
return _P5_INSTANCE.floor(*args)
|
||||
|
||||
def lerp(*args):
|
||||
return _P5_INSTANCE.lerp(*args)
|
||||
|
||||
def log(*args):
|
||||
return _P5_INSTANCE.log(*args)
|
||||
|
||||
def mag(*args):
|
||||
return _P5_INSTANCE.mag(*args)
|
||||
|
||||
def map(*args):
|
||||
return _P5_INSTANCE.map(*args)
|
||||
|
||||
def max(*args):
|
||||
return _P5_INSTANCE.max(*args)
|
||||
|
||||
def min(*args):
|
||||
return _P5_INSTANCE.min(*args)
|
||||
|
||||
def norm(*args):
|
||||
return _P5_INSTANCE.norm(*args)
|
||||
|
||||
def pow(*args):
|
||||
return _P5_INSTANCE.pow(*args)
|
||||
|
||||
def round(*args):
|
||||
return _P5_INSTANCE.round(*args)
|
||||
|
||||
def sq(*args):
|
||||
return _P5_INSTANCE.sq(*args)
|
||||
|
||||
def sqrt(*args):
|
||||
return _P5_INSTANCE.sqrt(*args)
|
||||
|
||||
def noise(*args):
|
||||
return _P5_INSTANCE.noise(*args)
|
||||
|
||||
def noiseDetail(*args):
|
||||
return _P5_INSTANCE.noiseDetail(*args)
|
||||
|
||||
def noiseSeed(*args):
|
||||
return _P5_INSTANCE.noiseSeed(*args)
|
||||
|
||||
def randomSeed(*args):
|
||||
return _P5_INSTANCE.randomSeed(*args)
|
||||
|
||||
def random(*args):
|
||||
return _P5_INSTANCE.random(*args)
|
||||
|
||||
def randomGaussian(*args):
|
||||
return _P5_INSTANCE.randomGaussian(*args)
|
||||
|
||||
def acos(*args):
|
||||
return _P5_INSTANCE.acos(*args)
|
||||
|
||||
def asin(*args):
|
||||
return _P5_INSTANCE.asin(*args)
|
||||
|
||||
def atan(*args):
|
||||
return _P5_INSTANCE.atan(*args)
|
||||
|
||||
def atan2(*args):
|
||||
return _P5_INSTANCE.atan2(*args)
|
||||
|
||||
def cos(*args):
|
||||
return _P5_INSTANCE.cos(*args)
|
||||
|
||||
def sin(*args):
|
||||
return _P5_INSTANCE.sin(*args)
|
||||
|
||||
def tan(*args):
|
||||
return _P5_INSTANCE.tan(*args)
|
||||
|
||||
def degrees(*args):
|
||||
return _P5_INSTANCE.degrees(*args)
|
||||
|
||||
def radians(*args):
|
||||
return _P5_INSTANCE.radians(*args)
|
||||
|
||||
def angleMode(*args):
|
||||
return _P5_INSTANCE.angleMode(*args)
|
||||
|
||||
def textAlign(*args):
|
||||
return _P5_INSTANCE.textAlign(*args)
|
||||
|
||||
def textLeading(*args):
|
||||
return _P5_INSTANCE.textLeading(*args)
|
||||
|
||||
def textSize(*args):
|
||||
return _P5_INSTANCE.textSize(*args)
|
||||
|
||||
def textStyle(*args):
|
||||
return _P5_INSTANCE.textStyle(*args)
|
||||
|
||||
def textWidth(*args):
|
||||
return _P5_INSTANCE.textWidth(*args)
|
||||
|
||||
def textAscent(*args):
|
||||
return _P5_INSTANCE.textAscent(*args)
|
||||
|
||||
def textDescent(*args):
|
||||
return _P5_INSTANCE.textDescent(*args)
|
||||
|
||||
def loadFont(*args):
|
||||
return _P5_INSTANCE.loadFont(*args)
|
||||
|
||||
def text(*args):
|
||||
return _P5_INSTANCE.text(*args)
|
||||
|
||||
def textFont(*args):
|
||||
return _P5_INSTANCE.textFont(*args)
|
||||
|
||||
def orbitControl(*args):
|
||||
return _P5_INSTANCE.orbitControl(*args)
|
||||
|
||||
def debugMode(*args):
|
||||
return _P5_INSTANCE.debugMode(*args)
|
||||
|
||||
def noDebugMode(*args):
|
||||
return _P5_INSTANCE.noDebugMode(*args)
|
||||
|
||||
def ambientLight(*args):
|
||||
return _P5_INSTANCE.ambientLight(*args)
|
||||
|
||||
def directionalLight(*args):
|
||||
return _P5_INSTANCE.directionalLight(*args)
|
||||
|
||||
def pointLight(*args):
|
||||
return _P5_INSTANCE.pointLight(*args)
|
||||
|
||||
def lights(*args):
|
||||
return _P5_INSTANCE.lights(*args)
|
||||
|
||||
def loadShader(*args):
|
||||
return _P5_INSTANCE.loadShader(*args)
|
||||
|
||||
def createShader(*args):
|
||||
return _P5_INSTANCE.createShader(*args)
|
||||
|
||||
def shader(*args):
|
||||
return _P5_INSTANCE.shader(*args)
|
||||
|
||||
def resetShader(*args):
|
||||
return _P5_INSTANCE.resetShader(*args)
|
||||
|
||||
def normalMaterial(*args):
|
||||
return _P5_INSTANCE.normalMaterial(*args)
|
||||
|
||||
def texture(*args):
|
||||
return _P5_INSTANCE.texture(*args)
|
||||
|
||||
def textureMode(*args):
|
||||
return _P5_INSTANCE.textureMode(*args)
|
||||
|
||||
def textureWrap(*args):
|
||||
return _P5_INSTANCE.textureWrap(*args)
|
||||
|
||||
def ambientMaterial(*args):
|
||||
return _P5_INSTANCE.ambientMaterial(*args)
|
||||
|
||||
def specularMaterial(*args):
|
||||
return _P5_INSTANCE.specularMaterial(*args)
|
||||
|
||||
def shininess(*args):
|
||||
return _P5_INSTANCE.shininess(*args)
|
||||
|
||||
def camera(*args):
|
||||
return _P5_INSTANCE.camera(*args)
|
||||
|
||||
def perspective(*args):
|
||||
return _P5_INSTANCE.perspective(*args)
|
||||
|
||||
def ortho(*args):
|
||||
return _P5_INSTANCE.ortho(*args)
|
||||
|
||||
def createCamera(*args):
|
||||
return _P5_INSTANCE.createCamera(*args)
|
||||
|
||||
def setCamera(*args):
|
||||
return _P5_INSTANCE.setCamera(*args)
|
||||
|
||||
|
||||
HALF_PI = None
|
||||
PI = None
|
||||
QUARTER_PI = None
|
||||
TAU = None
|
||||
TWO_PI = None
|
||||
DEGREES = None
|
||||
RADIANS = None
|
||||
frameCount = None
|
||||
focused = None
|
||||
displayWidth = None
|
||||
displayHeight = None
|
||||
windowWidth = None
|
||||
windowHeight = None
|
||||
width = None
|
||||
height = None
|
||||
disableFriendlyErrors = None
|
||||
deviceOrientation = None
|
||||
accelerationX = None
|
||||
accelerationY = None
|
||||
accelerationZ = None
|
||||
pAccelerationX = None
|
||||
pAccelerationY = None
|
||||
pAccelerationZ = None
|
||||
rotationX = None
|
||||
rotationY = None
|
||||
rotationZ = None
|
||||
pRotationX = None
|
||||
pRotationY = None
|
||||
pRotationZ = None
|
||||
turnAxis = None
|
||||
keyIsPressed = None
|
||||
key = None
|
||||
keyCode = None
|
||||
mouseX = None
|
||||
mouseY = None
|
||||
pmouseX = None
|
||||
pmouseY = None
|
||||
winMouseX = None
|
||||
winMouseY = None
|
||||
pwinMouseX = None
|
||||
pwinMouseY = None
|
||||
mouseButton = None
|
||||
mouseIsPressed = None
|
||||
touches = None
|
||||
pixels = None
|
||||
|
||||
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
|
||||
|
||||
HALF_PI = p5_instance.HALF_PI
|
||||
PI = p5_instance.PI
|
||||
QUARTER_PI = p5_instance.QUARTER_PI
|
||||
TAU = p5_instance.TAU
|
||||
TWO_PI = p5_instance.TWO_PI
|
||||
DEGREES = p5_instance.DEGREES
|
||||
RADIANS = p5_instance.RADIANS
|
||||
frameCount = p5_instance.frameCount
|
||||
focused = p5_instance.focused
|
||||
displayWidth = p5_instance.displayWidth
|
||||
displayHeight = p5_instance.displayHeight
|
||||
windowWidth = p5_instance.windowWidth
|
||||
windowHeight = p5_instance.windowHeight
|
||||
width = p5_instance.width
|
||||
height = p5_instance.height
|
||||
disableFriendlyErrors = p5_instance.disableFriendlyErrors
|
||||
deviceOrientation = p5_instance.deviceOrientation
|
||||
accelerationX = p5_instance.accelerationX
|
||||
accelerationY = p5_instance.accelerationY
|
||||
accelerationZ = p5_instance.accelerationZ
|
||||
pAccelerationX = p5_instance.pAccelerationX
|
||||
pAccelerationY = p5_instance.pAccelerationY
|
||||
pAccelerationZ = p5_instance.pAccelerationZ
|
||||
rotationX = p5_instance.rotationX
|
||||
rotationY = p5_instance.rotationY
|
||||
rotationZ = p5_instance.rotationZ
|
||||
pRotationX = p5_instance.pRotationX
|
||||
pRotationY = p5_instance.pRotationY
|
||||
pRotationZ = p5_instance.pRotationZ
|
||||
turnAxis = p5_instance.turnAxis
|
||||
keyIsPressed = p5_instance.keyIsPressed
|
||||
key = p5_instance.key
|
||||
keyCode = p5_instance.keyCode
|
||||
mouseX = p5_instance.mouseX
|
||||
mouseY = p5_instance.mouseY
|
||||
pmouseX = p5_instance.pmouseX
|
||||
pmouseY = p5_instance.pmouseY
|
||||
winMouseX = p5_instance.winMouseX
|
||||
winMouseY = p5_instance.winMouseY
|
||||
pwinMouseX = p5_instance.pwinMouseX
|
||||
pwinMouseY = p5_instance.pwinMouseY
|
||||
mouseButton = p5_instance.mouseButton
|
||||
mouseIsPressed = p5_instance.mouseIsPressed
|
||||
touches = p5_instance.touches
|
||||
pixels = p5_instance.pixels
|
||||
|
||||
return draw_func()
|
||||
|
||||
|
||||
def global_p5_injection(p5_sketch):
|
||||
"""
|
||||
Injects the p5js's skecth instance as a global variable to setup and draw functions
|
||||
"""
|
||||
|
||||
def decorator(f):
|
||||
|
||||
def wrapper():
|
||||
global _P5_INSTANCE
|
||||
_P5_INSTANCE = p5_sketch
|
||||
return pre_draw(_P5_INSTANCE, f)
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def start_p5(setup_func, draw_func):
|
||||
"""
|
||||
This is the entrypoint function. It accepts 2 parameters:
|
||||
|
||||
- setup_func: a Python setup callable
|
||||
- draw_func: a Python draw callable
|
||||
|
||||
This method gets the p5js's sketch instance and injects them
|
||||
"""
|
||||
|
||||
def sketch_setup(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'))
|
|
@ -0,0 +1,67 @@
|
|||
// Transcrypt'ed from Python, 2019-05-25 23:56:17
|
||||
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';
|
||||
__nest__ (math, '', __module_math__);
|
||||
var __name__ = 'random';
|
||||
export var _array = (function () {
|
||||
var __accu0__ = [];
|
||||
for (var i = 0; i < 624; i++) {
|
||||
__accu0__.append (0);
|
||||
}
|
||||
return __accu0__;
|
||||
}) ();
|
||||
export var _index = 0;
|
||||
export var _bitmask1 = Math.pow (2, 32) - 1;
|
||||
export var _bitmask2 = Math.pow (2, 31);
|
||||
export var _bitmask3 = Math.pow (2, 31) - 1;
|
||||
export var _fill_array = function () {
|
||||
for (var i = 0; i < 624; i++) {
|
||||
var y = (_array [i] & _bitmask2) + (_array [__mod__ (i + 1, 624)] & _bitmask3);
|
||||
_array [i] = _array [__mod__ (i + 397, 624)] ^ y >> 1;
|
||||
if (__mod__ (y, 2) != 0) {
|
||||
_array [i] ^= 2567483615;
|
||||
}
|
||||
}
|
||||
};
|
||||
export var _random_integer = function () {
|
||||
if (_index == 0) {
|
||||
_fill_array ();
|
||||
}
|
||||
var y = _array [_index];
|
||||
y ^= y >> 11;
|
||||
y ^= y << 7 & 2636928640;
|
||||
y ^= y << 15 & 4022730752;
|
||||
y ^= y >> 18;
|
||||
_index = __mod__ (_index + 1, 624);
|
||||
return y;
|
||||
};
|
||||
export var seed = function (x) {
|
||||
if (typeof x == 'undefined' || (x != null && x.hasOwnProperty ("__kwargtrans__"))) {;
|
||||
var x = int (_bitmask3 * Math.random ());
|
||||
};
|
||||
_array [0] = x;
|
||||
for (var i = 1; i < 624; i++) {
|
||||
_array [i] = (1812433253 * _array [i - 1] ^ (_array [i - 1] >> 30) + i) & _bitmask1;
|
||||
}
|
||||
};
|
||||
export var randint = function (a, b) {
|
||||
return a + __mod__ (_random_integer (), (b - a) + 1);
|
||||
};
|
||||
export var choice = function (seq) {
|
||||
return seq [randint (0, len (seq) - 1)];
|
||||
};
|
||||
export var random = function () {
|
||||
return _random_integer () / _bitmask3;
|
||||
};
|
||||
export var shuffle = function (x) {
|
||||
for (var i = len (x) - 1; i > 0; i--) {
|
||||
var j = math.floor (random () * (i + 1));
|
||||
var temp = x [i];
|
||||
x [i] = x [j];
|
||||
x [j] = temp;
|
||||
}
|
||||
};
|
||||
seed ();
|
||||
|
||||
//# sourceMappingURL=random.map
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "random.js",
|
||||
"sources": [
|
||||
"random.py"
|
||||
],
|
||||
"mappings": "AAAA;AAEA;AAAA;AAAA;AAAA;AAFA;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAGA;AAGA;AACA;AAAA;AACA;AAAA;AAAA;AAAA;AAAA;AAMA;AACA;AAAA;AAEA;AAAA;AAAA;AAAA;AAGA;AACA;AACA;AAAA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAEA;AArDA"
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
# Mersenne-Twister random number algorithm
|
||||
|
||||
import math
|
||||
|
||||
_array = [0 for i in range (624)]
|
||||
_index = 0
|
||||
_bitmask1 = (2 ** 32) - 1
|
||||
_bitmask2 = 2 ** 31
|
||||
_bitmask3 = (2 ** 31) - 1
|
||||
|
||||
def _fill_array():
|
||||
global _array
|
||||
for i in range (624):
|
||||
y = (_array [i] & _bitmask2) + (_array [(i + 1) % 624] & _bitmask3)
|
||||
_array [i] = _array [(i + 397) % 624] ^ (y >> 1)
|
||||
if y % 2 != 0:
|
||||
_array[i] ^= 2567483615
|
||||
|
||||
def _random_integer ():
|
||||
global _index
|
||||
global _array
|
||||
if _index == 0:
|
||||
_fill_array ()
|
||||
y = _array [_index]
|
||||
y ^= y >> 11
|
||||
y ^= (y << 7) & 2636928640
|
||||
y ^= (y << 15) & 4022730752
|
||||
y ^= y >> 18
|
||||
|
||||
_index = (_index + 1) % 624
|
||||
return y
|
||||
|
||||
def seed (x = int (_bitmask3 * Math.random ())):
|
||||
global _array
|
||||
global _bitmask1
|
||||
_array [0] = x
|
||||
for i in range (1, 624):
|
||||
_array [i] = ((1812433253 * _array [i - 1]) ^ ((_array [i - 1] >> 30) + i)) & _bitmask1
|
||||
|
||||
def randint (a, b):
|
||||
return a + _random_integer () % (b - a + 1)
|
||||
|
||||
def choice (seq):
|
||||
return seq [randint (0, len (seq) - 1)]
|
||||
|
||||
def random ():
|
||||
return _random_integer () / _bitmask3
|
||||
|
||||
def shuffle (x): # Fisher-Yates unbiased shuffle
|
||||
for i in range (len (x) - 1, 0, -1):
|
||||
j = math.floor (random () * (i + 1))
|
||||
temp = x [i]
|
||||
x [i] = x [j]
|
||||
x [j] = temp
|
||||
|
||||
seed ()
|
|
@ -0,0 +1,81 @@
|
|||
// Transcrypt'ed from Python, 2019-05-25 23:56:17
|
||||
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, 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';
|
||||
var __name__ = '__main__';
|
||||
export var W = null;
|
||||
export var H = null;
|
||||
export var position = null;
|
||||
export var num = null;
|
||||
export var line_combos = null;
|
||||
export var space = 15;
|
||||
var position = 0;
|
||||
export var setup = function () {
|
||||
createCanvas (1045, 700);
|
||||
frameRate (5);
|
||||
strokeWeight (2);
|
||||
var grid = product (range (-(1), 2), __kwargtrans__ ({repeat: 2}));
|
||||
var lines = combinations (grid, 2);
|
||||
var short_lines = list ([]);
|
||||
for (var l of lines) {
|
||||
var __left0__ = tuple ([l [0], l [1]]);
|
||||
var x0 = __left0__ [0][0];
|
||||
var y0 = __left0__ [0][1];
|
||||
var x1 = __left0__ [1][0];
|
||||
var y1 = __left0__ [1][1];
|
||||
if (dist (x0, y0, x1, y1) < 3) {
|
||||
short_lines.append (l);
|
||||
}
|
||||
}
|
||||
var num_short_lines = len (short_lines);
|
||||
print ('Number of possible lines: {}'.format (num_short_lines));
|
||||
line_combos = list (combinations (short_lines, 4));
|
||||
shuffle (line_combos);
|
||||
num = len (line_combos);
|
||||
print (num);
|
||||
var __left0__ = tuple ([(width - space) / space, (height - space) / space]);
|
||||
W = __left0__ [0];
|
||||
H = __left0__ [1];
|
||||
print (tuple ([W, H, W * H]));
|
||||
};
|
||||
export var draw = function () {
|
||||
background (240);
|
||||
var i = position;
|
||||
for (var y = 0; y < H; y++) {
|
||||
for (var x = 0; x < W; x++) {
|
||||
if (i < len (line_combos)) {
|
||||
push ();
|
||||
translate (space + space * x, space + space * y);
|
||||
draw_combo (i);
|
||||
P5.py_pop ();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i < len (line_combos)) {
|
||||
position += W;
|
||||
}
|
||||
};
|
||||
export var draw_combo = function (i) {
|
||||
var siz = space / 3.0;
|
||||
for (var [i, sl] of enumerate (line_combos [i])) {
|
||||
colorMode (p5.HSB);
|
||||
stroke (i * 64, 160, 160);
|
||||
var __left0__ = tuple ([sl [0], sl [1]]);
|
||||
var x0 = __left0__ [0][0];
|
||||
var y0 = __left0__ [0][1];
|
||||
var x1 = __left0__ [1][0];
|
||||
var y1 = __left0__ [1][1];
|
||||
line (x0 * siz, y0 * siz, x1 * siz, y1 * siz);
|
||||
}
|
||||
};
|
||||
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
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "sketch_190525b.js",
|
||||
"sources": [
|
||||
"sketch_190525b.py"
|
||||
],
|
||||
"mappings": "AAAA;AAAA;AAUA;AADA;AATA;AAAA;AACA;AACA;AACA;AACA;AACA;AAMA;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;AAEA;AACA;AACA;AAAA;AAAA;AAKA;AACA;AAvEA"
|
||||
}
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,72 @@
|
|||
from pyp5js import *
|
||||
W = None
|
||||
H = None
|
||||
position = None
|
||||
num = None
|
||||
line_combos = None
|
||||
# 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
|
||||
space = 15
|
||||
position = 0 # initial position
|
||||
|
||||
|
||||
def setup():
|
||||
global line_combos, W, H, position, num
|
||||
createCanvas(1045, 700)
|
||||
frameRate(5)
|
||||
strokeWeight(2)
|
||||
grid = product(range(-1, 2), repeat=2) # 3X3
|
||||
# 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)
|
||||
print("Number of possible lines: {}".format(num_short_lines))
|
||||
# main stuff
|
||||
line_combos = list(combinations(short_lines, 4))
|
||||
shuffle(line_combos)
|
||||
num = len(line_combos)
|
||||
print(num)
|
||||
W, H = (width - space) / space, (height - space) / space
|
||||
print((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):
|
||||
push()
|
||||
translate(space + space * x, space + space * y)
|
||||
draw_combo(i)
|
||||
P5.pop()
|
||||
i += 1
|
||||
if i < len(line_combos):
|
||||
position += W
|
||||
|
||||
def draw_combo(i):
|
||||
siz = space / 3.
|
||||
for i, sl in enumerate(line_combos[i]):
|
||||
colorMode(p5.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")
|
||||
|
||||
|
||||
# ==== This is required by pyp5js to work
|
||||
# Register your events functions here
|
||||
event_functions = {'keyPressed': 'keyPressed'}
|
||||
start_p5(setup, draw, event_functions)
|
|
@ -28,7 +28,6 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o
|
|||
|
||||
[sketch_190524a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190524a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
|
||||
---
|
||||
|
||||

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