kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
f584b245f9
commit
8c4339aca2
|
|
@ -0,0 +1,59 @@
|
|||
estado_inicial = True
|
||||
|
||||
def setup():
|
||||
global b1, b2
|
||||
size(400, 400)
|
||||
b1 = Botao(100, 150, 200, 50, "clique aqui")
|
||||
b2 = Botao(100, 200, 200, 50, "de novo!")
|
||||
|
||||
def draw():
|
||||
if estado_inicial:
|
||||
background(200)
|
||||
else:
|
||||
background(10)
|
||||
|
||||
global estado_inicial
|
||||
resultado1 = b1.display()
|
||||
resultado2 = b2.display()
|
||||
if resultado1 or resultado2:
|
||||
print('clique')
|
||||
estado_inicial = not estado_inicial
|
||||
|
||||
|
||||
|
||||
class Botao():
|
||||
|
||||
def __init__(self, x, y, w, h, t):
|
||||
self.x, self.y = x, y
|
||||
self.w, self.h = w, h
|
||||
self.t = t
|
||||
self.pressed = False
|
||||
|
||||
def mouse_over(self):
|
||||
return (self.x < mouseX < self.x + self.w and
|
||||
self.y < mouseY < self.y + self.h)
|
||||
|
||||
def display(self):
|
||||
mouse_over = self.mouse_over()
|
||||
if mouse_over:
|
||||
fill(140)
|
||||
else:
|
||||
fill(240)
|
||||
rectMode(CORNER)
|
||||
rect(self.x, self.y, self.w, self.h, 5)
|
||||
fill(0)
|
||||
textAlign(CENTER, CENTER)
|
||||
text(self.t,
|
||||
self.x + self.w / 2,
|
||||
self.y + self.h / 2)
|
||||
|
||||
if mouse_over and self.pressed and not mousePressed:
|
||||
self.pressed = False
|
||||
return True
|
||||
|
||||
if mouse_over and mousePressed:
|
||||
self.pressed = True
|
||||
else:
|
||||
self.pressed = False
|
||||
|
||||
return False
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
estado_inicial = True
|
||||
|
||||
def setup():
|
||||
size(400, 400)
|
||||
|
||||
def draw():
|
||||
global estado_inicial
|
||||
|
||||
if estado_inicial:
|
||||
background(200)
|
||||
else:
|
||||
background(10)
|
||||
|
||||
resultado1 = botao(100, 125, 200, 50, "clique aqui")
|
||||
resultado2 = botao(100, 225, 200, 50, "de novo!")
|
||||
if resultado1 or resultado2:
|
||||
print('clique')
|
||||
estado_inicial = not estado_inicial
|
||||
|
||||
def botao(x, y, w, h, _text):
|
||||
global estado_botoes
|
||||
try:
|
||||
estado_botoes
|
||||
except NameError:
|
||||
estado_botoes = dict()
|
||||
|
||||
mouse_over = (x < mouseX < x + w and
|
||||
y < mouseY < y + h)
|
||||
if mouse_over:
|
||||
fill(140)
|
||||
else:
|
||||
fill(240)
|
||||
rect(x, y, w, h, 5)
|
||||
fill(0)
|
||||
textAlign(CENTER, CENTER)
|
||||
text(_text, x + w / 2, y + h / 2)
|
||||
if mouse_over:
|
||||
if mousePressed:
|
||||
estado_botoes[(x, y)] = True
|
||||
return False
|
||||
elif estado_botoes.get((x, y)):
|
||||
estado_botoes[(x, y)] = False
|
||||
return True
|
||||
estado_botoes[(x, y)] = False
|
||||
return False
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
estado_inicial = True
|
||||
|
||||
def setup():
|
||||
size(400, 400)
|
||||
|
||||
def draw():
|
||||
global estado_inicial
|
||||
|
||||
if estado_inicial:
|
||||
background(200)
|
||||
else:
|
||||
background(10)
|
||||
|
||||
resultado1 = botao(100, 125, 200, 50, "clique aqui")
|
||||
resultado2 = botao(100, 225, 200, 50, "de novo!")
|
||||
if resultado1 or resultado2:
|
||||
print('clique')
|
||||
estado_inicial = not estado_inicial
|
||||
|
||||
def botao(x, y, w, h, _text):
|
||||
mouse_over = (x < mouseX < x + w and
|
||||
y < mouseY < y + h)
|
||||
if mouse_over:
|
||||
fill(140)
|
||||
else:
|
||||
fill(240)
|
||||
rect(x, y, w, h, 5)
|
||||
fill(0)
|
||||
textAlign(CENTER, CENTER)
|
||||
text(_text, x + w / 2, y + h / 2)
|
||||
if mouse_over:
|
||||
if mousePressed:
|
||||
botao.__dict__[(x, y)] = True
|
||||
return False
|
||||
elif botao.__dict__.get((x, y)):
|
||||
botao.__dict__[(x, y)] = False
|
||||
return True
|
||||
botao.__dict__[(x, y)] = False
|
||||
return False
|
||||
Ładowanie…
Reference in New Issue