Alexandre B A Villares 2018-03-12 22:29:33 -03:00
rodzic 4fda882285
commit 92eba2569d
9 zmienionych plików z 169 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,15 @@ Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can ma
If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HCGAKACDMVNV2) or with [Patreon](https://patreon.com/arteprog)
----
![s071](s071/s071.gif)
071: [code](https://github.com/villares/sketch-a-day/tree/master/s071) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Thicker and with a saturation slider (no more scale offset)
----
![s070](s070/s070.gif)

Wyświetl plik

@ -15,10 +15,10 @@ def gif_export(GifMaker, # gets a reference to the library
quality=255, # 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:
global gifExporter
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -0,0 +1,33 @@
"""
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 add_library('gifAnimation') at the start of your sketch
and add gif_export(GifMaker) at the end of draw()
"""
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=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)
gifExporter.addFrame()
if (frames == 0 and keyPressed or frameCount >= 100000) \
or (frames != 0 and frameCount >= frames):
gifExporter.finish()
print("gif saved")
exit()

BIN
s071/s071.gif 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.9 MiB

71
s071/s071.pyde 100644
Wyświetl plik

@ -0,0 +1,71 @@
"""
sketch 71 180312 - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
"""
from __future__ import division
from slider import Slider
add_library('gifAnimation')
from gif_exporter import gif_export
# slider_object = Slider(lowest, highest, initial value)
i = Slider(PI / 6, TWO_PI / 3, QUARTER_PI) # angle, changes number of sides
j = Slider(1, 4, 2) # depth, changes number of recursions (fiddled afterwards)
k = Slider(0, 10, 0) # random
l = Slider(0, TWO_PI, 0) # rotation
I, J, K, L = 1, 1, 1, 1 # dummy initial slider global values
# ^ I need these globals because I want to read/draw sliders
# at the end of the draw loop so they draw on top
# I should 'decouple' reading and drawing the sliders...
def setup():
size(600, 600)
colorMode(HSB) # makes it easy to cycle colors through Hues...
noFill()
# Position Sliders (x, y)
i.position(20, 20)
j.position(20, 60)
k.position(20, 100)
l.position(20, 140)
frameRate(10)
def draw():
global I, J, K, L
background(200)
poly_shape(width / 2, height / 2, I, J, K, L)
# Read and update sliders
I = i.value() # from PI/6 to TWO_PI/3
j.high = 2 + I * 1.5 # change J's upper limit...
J = j.value() # 1 to 3 + I * 1.5
K = k.value() # 10 to 50
L = l.value() # 0 to TWO_PI
# uncomment the next line to save frames!
if not frameCount % 10: gif_export(GifMaker, frames=3000)
def poly_shape(x, y, angle, D, sat, rotation):
stroke((frameCount / 2 * D) % 256, sat, 0, 255)
strokeWeight(D)
with pushMatrix():
translate(x, y)
rotate(rotation)
radius = D * 40
# create a polygon on a ps PShape object
ps = createShape()
ps.beginShape()
a = 0
while a < TWO_PI:
sx = cos(a) * radius
sy = sin(a) * radius
ps.vertex(sx + random(-K, K), sy + random(-K, K))
a += angle
ps.endShape(CLOSE) # end of PShape creation
shape(ps, 0, 0) # Draw the PShape
if D > 1: # if the recursion 'distance'/'depth' allows...
for i in range(ps.getVertexCount()):
# for each vertex
pv = ps.getVertex(i) # gets vertex as a PVector
# recusively call poly_shape with a smaller D
poly_shape(pv.x, pv.y, angle, D - 1, sat, rotation)

Wyświetl plik

@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode

Plik binarny nie jest wyświetlany.

53
s071/slider.py 100644
Wyświetl plik

@ -0,0 +1,53 @@
"""
Slider code based on Peter Farell's htts://twitter.com/hackingmath
https://github.com/hackingmath/python-sliders http://farrellpolymath.com/
"""
class Slider:
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
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 value(self):
'''updates the slider and returns value'''
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 dist(mouseX, mouseY, self.rectx + 5, self.recty + 10) < 20:
fill(200)
textSize(10)
text(str(self.val), self.rectx, self.recty + 35)
if mousePressed:
self.rectx = mouseX
# 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)
# draw label
popStyle()
return self.val