Advertisement
Guest User

OOP processing

a guest
Dec 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import random
  2.  
  3. class Button:
  4.  
  5. def __init__(self, x, y, w, h, f, s, c , txt):
  6. self.x = x
  7. self.y = y
  8. self.w = w
  9. self.h = h
  10. self.run = f
  11. self.screen = s
  12. self.color = c
  13. self.text = txt
  14.  
  15. def checkInBorders(self, x, y):
  16. if self.x < x < self.x + self.w and self.y < y < self.y + self.h:
  17. self.run()
  18.  
  19. def show(self, currentScreen):
  20. if self.screen == currentScreen:
  21. fill(self.color)
  22. rect(self.x, self.y, self.w, self.h)
  23.  
  24. text(self.text, self.x, self.y)
  25.  
  26. def move(self, x, y):
  27. self.x += x
  28. self.y += y
  29.  
  30. def nextScreen():
  31. global currentScreen
  32. currentScreen = 1
  33. print("ff")
  34.  
  35. def createNewButton():
  36. 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"))
  37.  
  38.  
  39. buttons = []
  40. currentScreen = 0
  41.  
  42. def setup():
  43. global buttons
  44. size(800, 400)
  45.  
  46. buttons.append(Button(100, 10, 50, 75, nextScreen, 0, color(255, 0, 0), "Ik ben button op scherm 1"))
  47. buttons.append(Button(10, 100, 50, 75, createNewButton, 1, color(0, 255, 0), "Ik ben de OG button op scherm 2"))
  48.  
  49.  
  50. def draw():
  51. global buttons
  52. background(51)
  53.  
  54. for button in buttons:
  55. button.show(currentScreen)
  56. button.move(1, 0)
  57.  
  58.  
  59. def mousePressed():
  60.  
  61. for button in buttons:
  62. button.checkInBorders(mouseX, mouseY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement