kopia lustrzana https://github.com/villares/sketch-a-day
day 80
rodzic
6aaf7635b8
commit
c4280722ab
|
@ -1,6 +1,6 @@
|
|||
|
||||
"""
|
||||
sketch 78 180319 - Alexandre B A Villares
|
||||
sketch 79 180320 - Alexandre B A Villares
|
||||
https://abav.lugaralgum.com/sketch-a-day
|
||||
|
||||
Based on Recursive Tree by Daniel Shiffman.
|
||||
|
@ -25,10 +25,8 @@ def setup():
|
|||
|
||||
def draw():
|
||||
global b, c, d
|
||||
background(0)
|
||||
background(200)
|
||||
frameRate(30)
|
||||
stroke(0)
|
||||
strokeWeight(2)
|
||||
|
||||
a = A.value() # Angle
|
||||
b = B.value() # branch size randomization
|
||||
|
@ -42,26 +40,54 @@ def draw():
|
|||
# #uncomment next lines to export GIF
|
||||
if not frameCount % 10: gif_export(GifMaker,
|
||||
frames=2000,
|
||||
filename="s078")
|
||||
filename="s079")
|
||||
|
||||
def branch(gen, theta, branch_size):
|
||||
strokeWeight(gen)
|
||||
cor = (map(gen,0,d,255,0) + frameCount) % 256
|
||||
stroke(cor,255,100)
|
||||
strokeWeight(2)
|
||||
# All recursive functions must have an exit condition!!!!
|
||||
if gen > 1:# and branch_size > 1:
|
||||
with pushMatrix():
|
||||
stroke(0)
|
||||
h = branch_size * (1 - random(b/3,b) / 15)
|
||||
rotate(theta + c * random(1)) # Rotate by theta
|
||||
line(0, 0, 0, -h) # Draw the branch
|
||||
arrow(0, 0, 0, -h) # Draw the branch
|
||||
translate(0, -h) # Move to the end of the branch
|
||||
# Ok, now call myself to draw two branches!!
|
||||
with pushStyle():
|
||||
branch(gen - 1, theta, h)
|
||||
with pushMatrix():
|
||||
stroke(255)
|
||||
h = branch_size * (1 - random(b/3, b) / 15)
|
||||
rotate(-theta + c * random(1))
|
||||
line(0, 0, 0, -h)
|
||||
arrow(0, 0, 0, -h)
|
||||
translate(0, -h)
|
||||
with pushStyle():
|
||||
branch(gen - 1, theta, h)
|
||||
|
||||
|
||||
def arrow(x1, y1, x2, y2, shorter=0, head=None,
|
||||
tail_func=None, tail_size=None):
|
||||
"""
|
||||
O código para fazer as setas, dois pares (x, y),
|
||||
um parâmetro de encurtamento: shorter
|
||||
e para o tamanho da cabeça da seta: head
|
||||
"""
|
||||
rectMode(CENTER)
|
||||
L = dist(x1, y1, x2, y2)
|
||||
if not head:
|
||||
head = max(L / 10, 10)
|
||||
with pushMatrix():
|
||||
translate(x1, y1)
|
||||
angle = atan2(x1 - x2, y2 - y1)
|
||||
rotate(angle)
|
||||
offset = shorter / 2
|
||||
strokeCap(ROUND)
|
||||
line(0, L - offset, -head / 3, L - offset - head)
|
||||
line(0, L - offset, head / 3, L - offset - head)
|
||||
strokeCap(SQUARE)
|
||||
line(0, offset, 0, L - offset)
|
||||
|
||||
if tail_func:
|
||||
if not tail_size:
|
||||
tail_size = head
|
||||
tail_func(0, 0, tail_size, tail_size)
|
||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -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()
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 1.4 MiB |
|
@ -0,0 +1,97 @@
|
|||
SKETCH_NAME = "s080"
|
||||
"""
|
||||
sketch 80 180321 - Alexandre B A Villares
|
||||
https://abav.lugaralgum.com/sketch-a-day
|
||||
|
||||
Based on Recursive Tree by Daniel Shiffman.
|
||||
"""
|
||||
|
||||
add_library('gifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
from slider import Slider
|
||||
|
||||
A = Slider(0, HALF_PI, QUARTER_PI)
|
||||
B = Slider(0, 10, 0)
|
||||
C = Slider(-2, 2, 0)
|
||||
D = Slider(2, 10, 10)
|
||||
|
||||
def setup():
|
||||
size(600, 600, P2D)
|
||||
colorMode(HSB)
|
||||
noFill()
|
||||
A.position(20, height - 60)
|
||||
B.position(20, height - 30)
|
||||
C.position(width - 180, height - 60)
|
||||
D.position(width - 180, height - 30)
|
||||
|
||||
def draw():
|
||||
global b, c, d
|
||||
background(200)
|
||||
frameRate(30)
|
||||
|
||||
a = A.value() # Angle
|
||||
b = B.value() # branch size randomization
|
||||
c = C.value() # angle randomization
|
||||
d = D.value() # recursion depth
|
||||
|
||||
randomSeed(int(d*10))
|
||||
translate(width / 2, height / 2)
|
||||
branch(int(d), a, width/20 + (width/75)*b)
|
||||
|
||||
# #uncomment next lines to export GIF
|
||||
if not frameCount % 10: gif_export(GifMaker,
|
||||
frames=2000,
|
||||
filename=SKETCH_NAME)
|
||||
|
||||
def branch(gen, theta, branch_size):
|
||||
strokeWeight(2)
|
||||
# All recursive functions must have an exit condition!!!!
|
||||
if gen > 1:# and branch_size > 1:
|
||||
with pushMatrix():
|
||||
stroke(255 * (gen % 2))
|
||||
h = branch_size * (1 - random(b/3,b) / 15)
|
||||
rotate(theta + c * random(1)) # Rotate by theta
|
||||
arrow(0, 0, 0, -h, tail_func=ellipse) # Draw the branch
|
||||
translate(0, -h) # Move to the end of the branch
|
||||
# Ok, now call myself to draw two branches!!
|
||||
with pushStyle():
|
||||
branch(gen - 1, theta, h)
|
||||
with pushMatrix():
|
||||
stroke(255 * (gen % 2))
|
||||
h = branch_size * (1 - random(b/3, b) / 15)
|
||||
rotate(-theta + c * random(1))
|
||||
arrow(0, 0, 0, -h, tail_func=ellipse)
|
||||
translate(0, -h)
|
||||
with pushStyle():
|
||||
branch(gen - 1, theta, h)
|
||||
|
||||
|
||||
def arrow(x1, y1, x2, y2,
|
||||
shorter=10,
|
||||
head=None,
|
||||
tail_func=None,
|
||||
tail_size=None):
|
||||
"""
|
||||
O código para fazer as setas, dois pares (x, y),
|
||||
um parâmetro de encurtamento: shorter
|
||||
e para o tamanho da cabeça da seta: head
|
||||
"""
|
||||
rectMode(CENTER)
|
||||
L = dist(x1, y1, x2, y2)
|
||||
if not head:
|
||||
head = max(L / 10, 5)
|
||||
with pushMatrix():
|
||||
translate(x1, y1)
|
||||
angle = atan2(x1 - x2, y2 - y1)
|
||||
rotate(angle)
|
||||
offset = shorter / 2
|
||||
strokeCap(ROUND)
|
||||
line(0, L - offset, -head / 3, L - offset - head)
|
||||
line(0, L - offset, head / 3, L - offset - head)
|
||||
strokeCap(SQUARE)
|
||||
line(0, offset, 0, L - offset)
|
||||
|
||||
if tail_func:
|
||||
if not tail_size:
|
||||
tail_size = head
|
||||
tail_func(0, 0, tail_size, tail_size)
|
|
@ -0,0 +1,2 @@
|
|||
mode=Python
|
||||
mode.id=jycessing.mode.PythonMode
|
Plik binarny nie jest wyświetlany.
|
@ -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(250)
|
||||
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
|
Ładowanie…
Reference in New Issue