Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Button:
- def __init__(self, x, y, w, h, f, s, c , txt):
- self.x = x
- self.y = y
- self.w = w
- self.h = h
- self.run = f
- self.screen = s
- self.color = c
- self.text = txt
- def checkInBorders(self, x, y):
- if self.x < x < self.x + self.w and self.y < y < self.y + self.h:
- self.run()
- def show(self, currentScreen):
- if self.screen == currentScreen:
- fill(self.color)
- rect(self.x, self.y, self.w, self.h)
- text(self.text, self.x, self.y)
- def move(self, x, y):
- self.x += x
- self.y += y
- def nextScreen():
- global currentScreen
- currentScreen = 1
- print("ff")
- def createNewButton():
- buttons.append(Button(random.randint(0, width), random.randint(0, height), 50, 75, createNewButton, 1, color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), "Ik ben gemaakt"))
- buttons = []
- currentScreen = 0
- def setup():
- global buttons
- size(800, 400)
- buttons.append(Button(100, 10, 50, 75, nextScreen, 0, color(255, 0, 0), "Ik ben button op scherm 1"))
- buttons.append(Button(10, 100, 50, 75, createNewButton, 1, color(0, 255, 0), "Ik ben de OG button op scherm 2"))
- def draw():
- global buttons
- background(51)
- for button in buttons:
- button.show(currentScreen)
- button.move(1, 0)
- def mousePressed():
- for button in buttons:
- button.checkInBorders(mouseX, mouseY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement