kopia lustrzana https://github.com/villares/sketch-a-day
more 84
rodzic
8368cef193
commit
36f177597a
|
@ -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
s084/s084.gif
BIN
s084/s084.gif
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 50 KiB Po Szerokość: | Wysokość: | Rozmiar: 4.8 MiB |
|
@ -6,14 +6,14 @@ https://abav.lugaralgum.com/sketch-a-day
|
|||
|
||||
import random as rnd
|
||||
|
||||
#add_library('gifAnimation')
|
||||
#from gif_exporter import gif_export
|
||||
add_library('gifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
from slider import Slider
|
||||
|
||||
A = Slider(1, 40, 10) #, 'q', 'a')
|
||||
B = Slider(1, 40, 10) #, 'w', 's')
|
||||
C = Slider(1, 40, 10) #, 'e', 'd')
|
||||
D = Slider(1, 40, 10) #, 'r', 'f')
|
||||
A = Slider(1, 40, 10, 'q', 'a')
|
||||
B = Slider(1, 40, 10, 'w', 's')
|
||||
C = Slider(1, 40, 10, 'e', 'd')
|
||||
D = Slider(1, 40, 10, 'r', 'f')
|
||||
# I need these globals because I want to call the sliders after drawing
|
||||
a, b, c, d = 1, 1, 1, 1
|
||||
|
||||
|
@ -72,10 +72,11 @@ def draw():
|
|||
d = int(D.value()) # grid num
|
||||
|
||||
# uncomment next lines to export GIF
|
||||
# if not frameCount % 10:
|
||||
# gif_export(GifMaker,
|
||||
# frames=2000,
|
||||
# filename=SKETCH_NAME)
|
||||
if not frameCount % 10:
|
||||
gif_export(GifMaker,
|
||||
frames=2000,
|
||||
delay=340,
|
||||
filename=SKETCH_NAME)
|
||||
|
||||
def grid(x, y, num, size_, space, func):
|
||||
for i in range(x, x + num * space, space):
|
||||
|
@ -86,5 +87,5 @@ def rnd_choice(collection):
|
|||
i = int(random(len(collection)))
|
||||
return collection[i]
|
||||
|
||||
def keyPressed():
|
||||
saveFrame(SKETCH_NAME + '_###.gif')
|
||||
# def keyPressed():
|
||||
# saveFrame(SKETCH_NAME + '_###.gif')
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 50 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 7.0 MiB |
|
@ -1,42 +1,63 @@
|
|||
"""
|
||||
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):
|
||||
|
||||
def __init__(self, low, high, default, more_key, less_key):
|
||||
'''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):
|
||||
self.more = more_key
|
||||
self.less = less_key
|
||||
|
||||
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)
|
||||
# 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'''
|
||||
#gray line behind slider
|
||||
|
||||
fill(0)
|
||||
rect(self.x,self.y-10,120, 20)
|
||||
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 mousePressed and dist(mouseX,mouseY,self.rectx,self.recty) < 20:
|
||||
self.rectx = mouseX
|
||||
#constrain rectangle
|
||||
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(self.val), self.rectx, self.recty + 35)
|
||||
if mousePressed:
|
||||
self.rectx = mouseX
|
||||
|
||||
# key usage
|
||||
if keyPressed:
|
||||
if key == self.more:
|
||||
self.rectx += 2
|
||||
if key == self.less:
|
||||
self.rectx -= 2
|
||||
|
||||
# constrain rectangle
|
||||
self.rectx = constrain(self.rectx, self.x, self.x + 120)
|
||||
#draw rectangle
|
||||
# draw rectangle
|
||||
strokeWeight(1)
|
||||
stroke(0)
|
||||
fill(self.val, 200, 200)
|
||||
rect(self.rectx,self.recty,10,20)
|
||||
self.val = map(self.rectx,self.x,self.x + 120,self.low,self.high)
|
||||
#draw label
|
||||
fill(0)
|
||||
textSize(10)
|
||||
text(int(self.val),self.rectx,self.recty + 35)
|
||||
return self.val
|
||||
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