Alexandre B A Villares 2018-03-29 22:09:18 -03:00
rodzic 72ba44ef8e
commit 81e42b5ed2
12 zmienionych plików z 445 dodań i 26 usunięć

Wyświetl plik

@ -8,6 +8,22 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
----
![s088](s088/s088.gif)
088: [code](https://github.com/villares/sketch-a-day/tree/master/s087) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
FIlled rects, ellipses and losangles (without sktroke) and Xs
----
![s087](s087/s087.gif)
087: [code](https://github.com/villares/sketch-a-day/tree/master/s087) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
No fill again, less colours. Variable/random number of elements per grid.
----
![s086](s086/s086.gif)
086: [code](https://github.com/villares/sketch-a-day/tree/master/s086) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
@ -250,7 +266,7 @@ Revisited 54 and now I'm re-selecting random points_to nodes...
![s056](s056/s056.gif)
056: [code](https://github.com/villares/sketch-a-day/tree/master/s056) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
056: [code](https://github.com/villares/sketch-a-day/tree/master/s056) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Arrow grid moving in HSB colour space
@ -258,7 +274,7 @@ Arrow grid moving in HSB colour space
![s055](s055/s055.png)
055: [code](https://github.com/villares/sketch-a-day/tree/master/s055) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
055: [code](https://github.com/villares/sketch-a-day/tree/master/s055) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Grid revisited
@ -266,7 +282,7 @@ Grid revisited
![s054](s054/s054.gif)
054: [code](https://github.com/villares/sketch-a-day/tree/master/s054) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
054: [code](https://github.com/villares/sketch-a-day/tree/master/s054) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
New arrows! With a "Tail" parameter...
@ -274,7 +290,7 @@ New arrows! With a "Tail" parameter...
![s053](s053/s053.png)
053: [code](https://github.com/villares/sketch-a-day/tree/master/s053) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
053: [code](https://github.com/villares/sketch-a-day/tree/master/s053) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Big invisible refactor (no more point-grid to select from, now a list of possible X and Y positons to choose).
On the visible side, fewer elements, and non-pointing elements redrawn in red on top.
@ -283,7 +299,7 @@ On the visible side, fewer elements, and non-pointing elements redrawn in red on
![s052](s052/s052.png)
052: [code](https://github.com/villares/sketch-a-day/tree/master/s052) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
052: [code](https://github.com/villares/sketch-a-day/tree/master/s052) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
White lines first, black arrows on top.
@ -291,7 +307,7 @@ White lines first, black arrows on top.
![s051](s051/s051.gif)
051: [code](https://github.com/villares/sketch-a-day/tree/master/s051) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
051: [code](https://github.com/villares/sketch-a-day/tree/master/s051) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Points now on a grid.
@ -299,7 +315,7 @@ Points now on a grid.
![s050](s050/s050.gif)
050: [code](https://github.com/villares/sketch-a-day/tree/master/s050) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
050: [code](https://github.com/villares/sketch-a-day/tree/master/s050) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Arrows now...
@ -307,56 +323,56 @@ Arrows now...
![s049](s049/s049.gif)
049: [code](https://github.com/villares/sketch-a-day/tree/master/s049) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
049: [code](https://github.com/villares/sketch-a-day/tree/master/s049) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet more graphs
----
![s048](s048/s048.gif)
048: [code](https://github.com/villares/sketch-a-day/tree/master/s048) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
048: [code](https://github.com/villares/sketch-a-day/tree/master/s048) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet more graphs
----
![s047](s047/s047.gif)
047: [code](https://github.com/villares/sketch-a-day/tree/master/s047) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
047: [code](https://github.com/villares/sketch-a-day/tree/master/s047) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet more graphs
----
![s046](s046/s046.png)
046: [code](https://github.com/villares/sketch-a-day/tree/master/s046) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
046: [code](https://github.com/villares/sketch-a-day/tree/master/s046) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet more graphs
----
![s045](s045/s045.gif)
045: [code](https://github.com/villares/sketch-a-day/tree/master/s045) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
045: [code](https://github.com/villares/sketch-a-day/tree/master/s045) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet more graphs
----
![s044](s044/s044.gif)
044: [code](https://github.com/villares/sketch-a-day/tree/master/s044) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
044: [code](https://github.com/villares/sketch-a-day/tree/master/s044) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
More graphs
----
![s043](s043/s043.png)
043: [code](https://github.com/villares/sketch-a-day/tree/master/s043) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
043: [code](https://github.com/villares/sketch-a-day/tree/master/s043) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
More graphs
----
![s042](s042/s042.gif)
042: [code](https://github.com/villares/sketch-a-day/tree/master/s042) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
042: [code](https://github.com/villares/sketch-a-day/tree/master/s042) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet another interactive recursive thingy, the image on the right is shown with a key pressed
----
@ -364,7 +380,7 @@ Yet another interactive recursive thingy, the image on the right is shown with a
![s041](s041/s041.png)
041: [code](https://github.com/villares/sketch-a-day/tree/master/s041) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
041: [code](https://github.com/villares/sketch-a-day/tree/master/s041) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Yet another interactive recursive thingy, the image on the right is shown with a key pressed
----
@ -415,7 +431,7 @@ Preparing for "Carnahacking"
![034](sketch_180203c/sketch_180203c.gif)
034: [sketch_180203c](https://github.com/villares/sketch-a-day/tree/master/sketch_180203c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Like 33 but again with "w squared" circles
Like 33 but again with "w squared" circles
----
@ -472,14 +488,14 @@ Saving a list of points to animate colour... Mouse speed changes recorded colour
![26](sketch_180126c/sketch_180126c.png)
026: [sketch_180126c](https://github.com/villares/sketch-a-day/tree/master/sketch_180126c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
026: [sketch_180126c](https://github.com/villares/sketch-a-day/tree/master/sketch_180126c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Mouse speed changing colour & strokeWeight()
----
![25](sketch_180125c/sketch_180125c.png)
025c: [sketch_180125b](https://github.com/villares/sketch-a-day/tree/master/sketch_180125c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
025c: [sketch_180125b](https://github.com/villares/sketch-a-day/tree/master/sketch_180125c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Mouse speed changing strokeWeight()
----
@ -502,19 +518,19 @@ Mouse speed changing strokeWeight()
![21b](sketch_180121b/sketch_180121b.gif)
021b: [sketch_180121b](https://github.com/villares/sketch-a-day/tree/master/sketch_180121b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
021b: [sketch_180121b](https://github.com/villares/sketch-a-day/tree/master/sketch_180121b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Playing with Peter "[Hacking Math Class](http://twitter.com/hackingmath)" Farrel's Sliders!
----
![20b](sketch_180120b/sketch_180120b.gif)
020b: [sketch_180120b](https://github.com/villares/sketch-a-day/tree/master/sketch_180120b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
020b: [sketch_180120b](https://github.com/villares/sketch-a-day/tree/master/sketch_180120b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
I was stuck on my DBN conversion sketch 20a, so this HSB shape play is 20b...
![20a](sketch_180120a/sketch_180120a.png)
020a: [sketch_180120a](https://github.com/villares/sketch-a-day/tree/master/sketch_180120a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
020a: [sketch_180120a](https://github.com/villares/sketch-a-day/tree/master/sketch_180120a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Refactored the code generation, removed most of the repeated vertices... C D E G O R not nice yet…
----
@ -527,7 +543,7 @@ Refactored the code generation, removed most of the repeated vertices... C D E G
![18a](sketch_180118a/sketch_180118a.png)
018: [sketch_180118a](https://github.com/villares/sketch-a-day/tree/master/sketch_180118a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] DBN Color font? Nah…
018: [sketch_180118a](https://github.com/villares/sketch-a-day/tree/master/sketch_180118a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] DBN Color font? Nah…
----
@ -551,13 +567,13 @@ Refactored the code generation, removed most of the repeated vertices... C D E G
![14a](sketch_180114a/sketch_180114a.png)
014: [sketch_180114a](https://github.com/villares/sketch-a-day/tree/master/sketch_180114a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Another 3D Graph
014: [sketch_180114a](https://github.com/villares/sketch-a-day/tree/master/sketch_180114a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Another 3D Graph
----
![13a](sketch_180113a/sketch_180113a.png)
013: [s180113](https://github.com/villares/sketch-a-day/tree/master/sketch_180113a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] 3D Graph
013: [s180113](https://github.com/villares/sketch-a-day/tree/master/sketch_180113a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] 3D Graph
----
@ -603,7 +619,7 @@ Refactored the code generation, removed most of the repeated vertices... C D E G
----
005: [s180105](https://github.com/villares/sketch-a-day/tree/master/s180105) [[p5js](https://www.p5js.org)] Line Tetrahedrons in p5*js - [interactive](https://villares.github.io/sketch-a-day/s180105/s180105)
005: [s180105](https://github.com/villares/sketch-a-day/tree/master/s180105) [[p5js](https://www.p5js.org)] Line Tetrahedrons in p5*js - [interactive](https://villares.github.io/sketch-a-day/s180105/s180105)
----

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=32, # 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
s087/s087.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

75
s087/s087.pyde 100644
Wyświetl plik

@ -0,0 +1,75 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME = "s087" # 180328
add_library('gifAnimation')
from gif_exporter import gif_export
from slider import Slider
from shapes import *
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')
SHAPES = [ellipse,
rect,
exes,
losang]
COLORS = [color(0), color(0), color(0),
color(255), color(255),
color(200, 0, 100),
]
def setup():
size(600, 600, P2D)
colorMode(HSB)
rectMode(CENTER)
A.position(40, height - 70)
B.position(40, height - 30)
C.position(width - 140, height - 70)
D.position(width - 140, height - 30)
def draw():
background(200)
noFill()
a = int(A.val) # number of elements
b = int(B.val) # size of elements
c = int(C.val) # space between elements
d = int(D.val) # number of grids
randomSeed(int(d * 100)) # a different random seed
for i in range(d):
tam = a * c
x = int(random(width - tam) / c) * c
y = int(random(height - tam) / c) * c
stroke(rnd_choice(COLORS))
noFill() # fill(rnd_choice(COLORS), 100)
strokeWeight(int(random(1, 3)))
random_a = rnd_choice(range(1, a + 1))
grid(x, y, random_a, b, c, rnd_choice(SHAPES))
# uncomment next lines to export GIF
if not frameCount % 30:
gif_export(GifMaker,
frames=2000,
delay=500,
filename=SKETCH_NAME)
# Draws sliders and checks for mouse dragging or keystrokes
Slider.update_all()
def grid(x, y, num, size_, space, func):
for i in range(x, x + num * space, space):
for j in range(y, y + num * space, space):
func(i, j, size_, size_)
def rnd_choice(collection):
i = int(random(len(collection)))
return collection[i]
# def keyPressed():
# saveFrame(SKETCH_NAME + '_###.gif')

11
s087/shapes.py 100644
Wyświetl plik

@ -0,0 +1,11 @@
def exes(x, y, c, _):
with pushMatrix():
translate(x, y)
line(-c / 2, -c / 2, c / 2, c / 2)
line(c / 2, -c / 2, -c / 2, c / 2)
def losang(x, y, c, _):
with pushMatrix():
translate(x, y)
rotate(radians(45))
rect(0, 0, c, c)

73
s087/slider.py 100644
Wyświetl plik

@ -0,0 +1,73 @@
"""
Slider code based on Peter Farell's htts://twitter.com/hackingmath
https://github.com/hackingmath/python-sliders http://farrellpolymath.com/
"""
class Slider:
SLIDERS = []
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
self.more = more_key
self.less = less_key
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(self.val), self.rectx, self.recty + 35)
if mousePressed:
self.rectx = mouseX
# key usage
if keyPressed:
if key == self.more:
self.rectx += 1
if key == self.less:
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()
def value(self):
''' backwards compatible method... '''
self.update()
return self.val
@classmethod
def update_all(cls):
for slider in Slider.SLIDERS:
slider.update()

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=32, # 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
s088/s087.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

BIN
s088/s088.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

69
s088/s088.pyde 100644
Wyświetl plik

@ -0,0 +1,69 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME = "s088" # 180329
add_library('gifAnimation')
from gif_exporter import gif_export
from slider import Slider
from shapes import *
A = Slider(1, 40, 10, 'q', 'a')
B = Slider(1, 100, 50, 'w', 's')
C = Slider(1, 40, 10, 'e', 'd')
D = Slider(1, 40, 10, 'r', 'f')
SHAPES = [my_ellipse,
my_rect,
exes,
losang]
def setup():
size(600, 600, P2D)
colorMode(HSB)
rectMode(CENTER)
A.position(40, height - 70)
B.position(40, height - 30)
C.position(width - 140, height - 70)
D.position(width - 140, height - 30)
def draw():
background(200)
noFill()
a = int(A.val) # number of elements
b = C.val * B.val / 100 # size of el ements (B.val % of spacing!)
c = int(C.val) # spacing between elements
d = int(D.val) # number of grids
randomSeed(int(d * 100)) # a different random seed
for i in range(d):
tam = a * c
x = int(random(width - tam) / c) * c
y = int(random(height - tam) / c) * c
stroke(rnd_choice(COLORS))
fill(rnd_choice(COLORS), 100)
random_a = rnd_choice(range(1, a + 1))
grid(x, y, random_a, b, c, rnd_choice(SHAPES))
# uncomment next lines to export GIF
if not frameCount % 30:
gif_export(GifMaker,
frames=2000,
delay=500,
filename=SKETCH_NAME)
# Draws sliders and checks for mouse dragging or keystrokes
Slider.update_all()
def grid(x, y, num, size_, space, func):
for i in range(x, x + num * space, space):
for j in range(y, y + num * space, space):
func(i, j, size_, size_)
def rnd_choice(collection):
i = int(random(len(collection)))
return collection[i]
# def keyPressed():
# saveFrame(SKETCH_NAME + '_###.gif')

36
s088/shapes.py 100644
Wyświetl plik

@ -0,0 +1,36 @@
COLORS = [color(0), color(0), color(0),
color(255), color(255),
color(200, 0, 100),
]
def my_ellipse(x, y, d, _):
pushStyle()
noStroke()
ellipse(x, y, d, d)
popStyle()
def my_rect(x, y, d, _):
pushStyle()
rectMode(CENTER)
noStroke()
rect(x, y, d, d)
popStyle()
def exes(x, y, c, _):
pushStyle()
strokeWeight(3)
with pushMatrix():
translate(x, y)
line(-c / 2, -c / 2, c / 2, c / 2)
line(c / 2, -c / 2, -c / 2, c / 2)
popStyle()
def losang(x, y, c, _):
pushStyle()
noStroke()
with pushMatrix():
translate(x, y)
rotate(radians(45))
rect(0, 0, c, c)
popStyle()

73
s088/slider.py 100644
Wyświetl plik

@ -0,0 +1,73 @@
"""
Slider code based on Peter Farell's htts://twitter.com/hackingmath
https://github.com/hackingmath/python-sliders http://farrellpolymath.com/
"""
class Slider:
SLIDERS = []
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
self.more = more_key
self.less = less_key
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(self.val), self.rectx, self.recty + 35)
if mousePressed:
self.rectx = mouseX
# key usage
if keyPressed:
if key == self.more:
self.rectx += 1
if key == self.less:
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()
def value(self):
''' backwards compatible method... '''
self.update()
return self.val
@classmethod
def update_all(cls):
for slider in Slider.SLIDERS:
slider.update()