kopia lustrzana https://github.com/villares/sketch-a-day
190506
rodzic
f219e7ab65
commit
88bd808979
|
@ -10,8 +10,8 @@
|
|||
<style> body, html, canvas {padding: 0; margin: 0; overflow: hidden;} </style>
|
||||
<script src="static/p5.js"></script>
|
||||
<script src="static/p5.dom.js"></script>
|
||||
<script src="static/constants.js"></script>
|
||||
<script src="target/sketch_190505b.js" type="module"></script>
|
||||
<!-- <script src="static/constants.js"></script>
|
||||
--> <script src="target/sketch_190505b.js" type="module"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from pytop5js import *
|
||||
|
||||
|
||||
w = h = d = 1
|
||||
|
||||
# Cubo
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-06 00:01:48
|
||||
// Transcrypt'ed from Python, 2019-05-06 22:22:54
|
||||
var __name__ = 'org.transcrypt.__runtime__';
|
||||
export var __envir__ = {};
|
||||
__envir__.interpreter_name = 'python';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Transcrypt'ed from Python, 2019-05-06 00:01:48
|
||||
// Transcrypt'ed from Python, 2019-05-06 22:22:55
|
||||
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __proxy__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, all, any, assert, bool, bytearray, bytes, callable, chr, deepcopy, delattr, dict, dir, divmod, enumerate, getattr, hasattr, input, isinstance, issubclass, len, list, object, ord, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, setattr, sorted, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
|
||||
var __name__ = 'pytop5js';
|
||||
export var _P5_INSTANCE = null;
|
||||
|
@ -993,6 +993,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;
|
||||
|
@ -1031,7 +1042,6 @@ export var mouseButton = null;
|
|||
export var mouseIsPressed = null;
|
||||
export var touches = null;
|
||||
export var pixels = null;
|
||||
export var CLOSE = null;
|
||||
export var pre_draw = function (p5_instance, draw_func) {
|
||||
HALF_PI = p5_instance.HALF_PI;
|
||||
PI = p5_instance.PI;
|
||||
|
@ -1040,6 +1050,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;
|
||||
|
@ -1078,7 +1099,6 @@ export var pre_draw = function (p5_instance, draw_func) {
|
|||
mouseIsPressed = p5_instance.mouseIsPressed;
|
||||
touches = p5_instance.touches;
|
||||
pixels = p5_instance.pixels;
|
||||
CLOSE = p5_instance.CLOSE;
|
||||
return draw_func ();
|
||||
};
|
||||
export var global_p5_injection = function (p5_sketch) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -747,6 +747,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
|
||||
|
@ -785,13 +796,12 @@ mouseButton = None
|
|||
mouseIsPressed = None
|
||||
touches = None
|
||||
pixels = None
|
||||
CLOSE = 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, CLOSE
|
||||
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
|
||||
|
@ -800,6 +810,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
|
||||
|
@ -838,7 +859,6 @@ def pre_draw(p5_instance, draw_func):
|
|||
mouseIsPressed = p5_instance.mouseIsPressed
|
||||
touches = p5_instance.touches
|
||||
pixels = p5_instance.pixels
|
||||
CLOSE = p5_instance.CLOSE
|
||||
|
||||
return draw_func()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Transcrypt'ed from Python, 2019-05-06 00:01:48
|
||||
// Transcrypt'ed from Python, 2019-05-06 22:22:55
|
||||
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 {CLOSE, 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, shuffle, sin, smooth, specularMaterial, sphere, splice, splitTokens, sq, sqrt, square, start_p5, str, stroke, strokeCap, strokeJoin, strokeWeight, subset, tan, text, textAlign, textAscent, textDescent, textFont, textLeading, textSize, textStyle, textWidth, texture, textureMode, textureWrap, tint, torus, touchEnded, touchMoved, touchStarted, touches, translate, triangle, trim, turnAxis, unchar, unhex, updatePixels, vertex, width, winMouseX, winMouseY, windowHeight, windowResized, windowWidth, year} from './pytop5js.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, 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, shuffle, sin, smooth, specularMaterial, sphere, splice, splitTokens, sq, sqrt, square, start_p5, str, stroke, strokeCap, strokeJoin, strokeWeight, subset, tan, text, textAlign, textAscent, textDescent, textFont, textLeading, textSize, textStyle, textWidth, texture, textureMode, textureWrap, tint, torus, touchEnded, touchMoved, touchStarted, touches, translate, triangle, trim, turnAxis, unchar, unhex, updatePixels, vertex, width, winMouseX, winMouseY, windowHeight, windowResized, windowWidth, year} from './pytop5js.js';
|
||||
var __name__ = '__main__';
|
||||
var __left0__ = 1;
|
||||
export var w = __left0__;
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
"sources": [
|
||||
"sketch_190505b.py"
|
||||
],
|
||||
"mappings": "AAAA;AAAA;AAAA;AAAA;AAGA;AAAA;AAAA;AAAA;AAGA;AACA;AACA;AAOA;AAEA;AACA;AACA;AACA;AAAA;AAEA;AAEA;AAGA;AACA;AAEA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAIA;AA9CA"
|
||||
"mappings": "AAAA;AAAA;AAAA;AAAA;AAEA;AAAA;AAAA;AAAA;AAGA;AACA;AACA;AAOA;AAEA;AACA;AACA;AACA;AAAA;AAEA;AAEA;AAGA;AACA;AAEA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAAA;AAEA;AACA;AAAA;AAAA;AAIA;AA7CA"
|
||||
}
|
Plik binarny nie jest wyświetlany.
|
@ -1,6 +1,5 @@
|
|||
from pytop5js import *
|
||||
|
||||
|
||||
w = h = d = 1
|
||||
|
||||
# Cubo
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
"""
|
||||
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
|
||||
|
||||
A helper for the Processing gifAnimation library (https://github.com/jordanorelli)
|
||||
ported to Processing 3 by 01010101 (https://github.com/01010101)
|
||||
Download the library from https://github.com/01010101/GifAnimation/archive/master.zip
|
||||
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
|
||||
|
||||
Put at the start of your sketch:
|
||||
add_library('gifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
and 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=182, # quality range 0 - 255
|
||||
delay=170, # this is quick
|
||||
frames=0): # 0 will stop on keyPressed or frameCount >= 100000
|
||||
global gifExporter
|
||||
try:
|
||||
gifExporter
|
||||
except NameError:
|
||||
gifExporter = GifMaker(this, filename + ".gif")
|
||||
gifExporter.setRepeat(repeat)
|
||||
gifExporter.setQuality(quality)
|
||||
gifExporter.setDelay(delay)
|
||||
gif_export._frame = frameCount
|
||||
print("gif start")
|
||||
|
||||
gifExporter.addFrame()
|
||||
|
||||
if (frames == 0 and keyPressed or frameCount - gif_export._frame >= 100000) \
|
||||
or (frames != 0 and frameCount - gif_export._frame >= frames):
|
||||
gifExporter.finish()
|
||||
background(255)
|
||||
print("gif saved")
|
||||
del(gifExporter)
|
||||
return False
|
||||
else:
|
||||
return True
|
|
@ -0,0 +1,132 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from javax.swing import JOptionPane
|
||||
|
||||
"""
|
||||
This will hpefully switch between Arduino (Firmata) variable input and
|
||||
nice sliders based on Peter Farell's Sliders htts://twitter.com/hackingmath
|
||||
https://github.com/hackingmath/python-sliders http://farrellpolymath.com/
|
||||
"""
|
||||
class Input:
|
||||
|
||||
def __init__(self):
|
||||
# start, end, default
|
||||
A = Slider(0, 1023, 128)
|
||||
B = Slider(0, 1023, 128)
|
||||
C = Slider(0, 1023, 128)
|
||||
D = Slider(0, 1023, 128)
|
||||
A.position(40, height - 70)
|
||||
B.position(40, height - 30)
|
||||
C.position(width - 140, height - 70)
|
||||
D.position(width - 140, height - 30)
|
||||
self.sliders = {1: A, 2: B, 3: C, 4: D}
|
||||
|
||||
def analog(self, pin):
|
||||
return self.sliders[pin].val
|
||||
|
||||
def update(self):
|
||||
for pin, slider in self.sliders.iteritems():
|
||||
slider.update()
|
||||
|
||||
def keyPressed(self):
|
||||
if key == 'a':
|
||||
self.sliders[1].down = True
|
||||
if key == 'd':
|
||||
self.sliders[1].up = True
|
||||
if key == 's':
|
||||
self.sliders[2].down = True
|
||||
if key == 'w':
|
||||
self.sliders[2].up = True
|
||||
if keyCode == LEFT:
|
||||
self.sliders[3].down = True
|
||||
if keyCode == RIGHT:
|
||||
self.sliders[3].up = True
|
||||
if keyCode == DOWN:
|
||||
self.sliders[4].down = True
|
||||
if keyCode == UP:
|
||||
self.sliders[4].up = True
|
||||
|
||||
def keyReleased(self):
|
||||
if key == 'a':
|
||||
self.sliders[1].down = False
|
||||
if key == 'd':
|
||||
self.sliders[1].up = False
|
||||
if key == 's':
|
||||
self.sliders[2].down = False
|
||||
if key == 'w':
|
||||
self.sliders[2].up = False
|
||||
if keyCode == LEFT:
|
||||
self.sliders[3].down = False
|
||||
if keyCode == RIGHT:
|
||||
self.sliders[3].up = False
|
||||
if keyCode == DOWN:
|
||||
self.sliders[4].down = False
|
||||
if keyCode == UP:
|
||||
self.sliders[4].up = False
|
||||
|
||||
def digital(self, pin):
|
||||
space_pressed = keyPressed and key == ' '
|
||||
if self.source:
|
||||
if pin == 13:
|
||||
return self.arduino.digitalRead(13) or space_pressed
|
||||
else:
|
||||
return arduino.digitalRead(pin)
|
||||
else:
|
||||
return space_pressed
|
||||
|
||||
|
||||
class Slider:
|
||||
|
||||
SLIDERS = []
|
||||
|
||||
def __init__(self, low, high, default):
|
||||
'''slider has range from low to high
|
||||
and is set to default'''
|
||||
self.low = low
|
||||
self.high = high
|
||||
self.val = default
|
||||
self.clicked = False
|
||||
self.up, self.down = False, False
|
||||
Slider.SLIDERS.append(self)
|
||||
|
||||
def position(self, x, y):
|
||||
'''slider's position on screen'''
|
||||
self.x = x
|
||||
self.y = y
|
||||
# the position of the rect you slide:
|
||||
self.rectx = self.x + map(self.val, self.low, self.high, 0, 120)
|
||||
self.recty = self.y - 10
|
||||
|
||||
def update(self):
|
||||
'''updates the slider'''
|
||||
pushStyle()
|
||||
rectMode(CENTER)
|
||||
# black translucid rect behind slider
|
||||
fill(0, 100)
|
||||
noStroke()
|
||||
rect(self.x + 60, self.y, 130, 20)
|
||||
# gray line behind slider
|
||||
strokeWeight(4)
|
||||
stroke(200)
|
||||
line(self.x, self.y, self.x + 120, self.y)
|
||||
# press mouse to move slider
|
||||
if (self.x < mouseX < self.x + 120 and
|
||||
self.y < mouseY < self.y + 20):
|
||||
fill(250)
|
||||
textSize(10)
|
||||
text(str(int(self.val)), self.rectx, self.recty + 35)
|
||||
if mousePressed:
|
||||
self.rectx = mouseX
|
||||
# key usage
|
||||
if self.up:
|
||||
self.rectx += 1
|
||||
if self.down:
|
||||
self.rectx -= 1
|
||||
# constrain rectangle
|
||||
self.rectx = constrain(self.rectx, self.x, self.x + 120)
|
||||
# draw rectangle
|
||||
strokeWeight(1)
|
||||
fill(255)
|
||||
rect(self.rectx, self.recty + 10, 10, 20)
|
||||
self.val = map(self.rectx, self.x, self.x + 120, self.low, self.high)
|
||||
popStyle()
|
|
@ -0,0 +1,87 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
# Based on s097 - 180407
|
||||
|
||||
add_library('GifAnimation')
|
||||
|
||||
from gif_exporter import *
|
||||
from inputs import *
|
||||
|
||||
def setup():
|
||||
global input, GIF_EXPORT
|
||||
fullScreen()
|
||||
#size(600, 600)
|
||||
rectMode(CENTER) # retângulos desenhados pelo centro
|
||||
colorMode(HSB) # linha em preto
|
||||
strokeWeight(2) # espessura de linha 2px
|
||||
noFill() # sem preenchimento
|
||||
frameRate(30) # deixa um pouco mais lento
|
||||
GIF_EXPORT = False
|
||||
input = Input()
|
||||
|
||||
def draw():
|
||||
background(200) # fundo cinza claro
|
||||
|
||||
# 0 a 63, número de linhas e colunas na grade
|
||||
grid_elem = int(input.analog(1) / 16)
|
||||
# 0 a 63, tamanho base de cada quadrado
|
||||
elem_size = int(input.analog(2) / 16)
|
||||
# 0 a 63, ativa faixa entre -64 e 63 para randomizar tamanho
|
||||
rand_size = int(input.analog(3) / 16)
|
||||
# 0 a 63, ativa faixa equivalente para randomizar a posição
|
||||
rand_posi = int(input.analog(4) / 16)
|
||||
|
||||
# trava a randomização entre os ciclos de draw
|
||||
# mas varia com o número de colunas na grade
|
||||
randomSeed(int(input.analog(1)) / 4)
|
||||
# calcula o espaçamento entre os quadrandos
|
||||
spac_size = int(width / (grid_elem + 1))
|
||||
# para cada coluna um x
|
||||
for x in range(spac_size / 2, width, spac_size):
|
||||
# para cada linha um y
|
||||
for y in range(spac_size / 2, width, spac_size):
|
||||
# sorteia um tamanho (se o rand_size > 0)
|
||||
square_size = elem_size + rand_size * random(-1, 1)
|
||||
stroke(square_size * 3, 255, 128)
|
||||
rect(x + rand_posi * random(-1, 1), # desenha um quadrado
|
||||
y + rand_posi * random(-1, 1),
|
||||
square_size,
|
||||
square_size)
|
||||
|
||||
# uncomment next lines to export GIF
|
||||
global GIF_EXPORT
|
||||
if not frameCount % 20 and GIF_EXPORT:
|
||||
GIF_EXPORT = gif_export(GifMaker,
|
||||
frames=1000,
|
||||
delay=300,
|
||||
filename=SKETCH_NAME)
|
||||
|
||||
# Updates reading or draws sliders and checks mouse dragging / keystrokes
|
||||
input.update()
|
||||
|
||||
|
||||
def keyPressed():
|
||||
global GIF_EXPORT
|
||||
if key == 'p': # save PNG
|
||||
saveFrame("####.png")
|
||||
if key == 'g': # save GIF
|
||||
GIF_EXPORT = True
|
||||
if key == 'h':
|
||||
input.help()
|
||||
|
||||
input.keyPressed()
|
||||
|
||||
def keyReleased():
|
||||
input.keyReleased()
|
||||
|
||||
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/2019/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
""".format(SKETCH_NAME, OUTPUT)
|
||||
)
|
Ładowanie…
Reference in New Issue