Merxlc

builts.py

May 3rd, 2021 (edited)
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. from tickedObject import TickedObject
  2.  
  3. def extract(obj, prop):
  4.     return (obj.__dict__[prop][0]).__dict__[obj.__dict__[prop][1]]
  5.  
  6. def setup(obj, prop, default):
  7.     obj.__dict__[f'std_{prop}'] = default
  8.     obj.__dict__[prop] = (obj, f'std_{prop}')
  9.  
  10. def launch(cdict):
  11.     varlist = {key: cdict[key] for key in cdict}
  12.     ticked = [varlist[key] for key in varlist if isinstance(varlist[key], TickedObject)]
  13.     return ticked
  14.  
  15. class Printer(TickedObject):
  16.  
  17.     def __init__(self):
  18.         self.std_message = 'No Print Set'
  19.         self.message = (self, 'std_message')
  20.  
  21.     def update(self):
  22.         print((self.message[0]).__dict__[self.message[1]])
  23.  
  24. class Counter(TickedObject):
  25.  
  26.     def __init__(self):
  27.         self.i = 0
  28.         self.std_increment = 1
  29.         self.increment = (self, 'std_increment')
  30.  
  31.     def update(self):
  32.         self.i += (self.increment[0]).__dict__[self.increment[1]]
  33.  
  34. import timeit
  35.  
  36. class FPSCounter(TickedObject):
  37.  
  38.     def __init__(self):
  39.         self.frames = 0
  40.         self.fps = 0
  41.         self.last_frame = 0
  42.         self.last_frames = []
  43.  
  44.     def update(self):
  45.         self.last_frame = timeit.default_timer()
  46.         self.last_frames.append(self.last_frame)
  47.         if len(self.last_frames) > 5:
  48.             self.last_frames = self.last_frames[1:]
  49.         framediffs = []
  50.         for i, frame_time in enumerate(self.last_frames):
  51.             if i != len(self.last_frames)-1:
  52.                 framediffs.append((self.last_frames[i+1])-frame_time)
  53.         if len(framediffs): self.fps = round(1/(sum(framediffs)/len(framediffs)),2)
  54.  
  55. import os
  56.  
  57. class Clearer(TickedObject):
  58.  
  59.     def __init__(self):
  60.         pass
  61.  
  62.     def update(self):
  63.         os.system('cls')
  64.  
  65. import math
  66.  
  67. class Operator(TickedObject):
  68.  
  69.     def __init__(self):
  70.         self.std_operation = lambda x : x**2
  71.         self.operation = (self, 'std_operation')
  72.         self.std_operand = 5
  73.         self.operand = (self, 'std_operand')
  74.         self.last_value = 0
  75.  
  76.     def update(self):
  77.         op = (self.operation[0]).__dict__[self.operation[1]]
  78.         self.last_value = op((self.operand[0]).__dict__[self.operand[1]])
  79.  
  80. class Difer(TickedObject):
  81.  
  82.     def __init__(self):
  83.         self.previous_value = 0
  84.         self.current_value = 0
  85.         self.difference = 0
  86.         self.value = setup(self, 'value', 0)
  87.  
  88.     def update(self):
  89.         self.current_value = extract(self, 'value')
  90.         self.difference = self.current_value-self.previous_value
  91.         self.previous_value = self.current_value
  92.  
  93. class Concator(TickedObject):
  94.  
  95.     def __init__(self):
  96.         setup(self, 'one', 'Hello')
  97.         setup(self, 'two', ' World!')
  98.         self.out = ''
  99.  
  100.     def update(self):
  101.         self.out = str(extract(self, 'one')) + str(extract(self, 'two'))
  102.  
  103. import UI
  104.  
  105. class Canvas(TickedObject):
  106.  
  107.     def __init__(self):
  108.         self.objects = []
  109.  
  110.     def update(self):
  111.         canvas = UI.Canvas()
  112.         for obj in self.objects:
  113.             canvas.objects.append(obj.load())
  114.         canvas.draw()
  115.  
  116. class CanvasRect(TickedObject):
  117.  
  118.     def __init__(self):
  119.         setup(self, 'x', 0)
  120.         setup(self, 'y', 0)
  121.         setup(self, 'width', 20)
  122.         setup(self, 'height', 10)
  123.         setup(self, 'text', '')
  124.  
  125.     def load(self):
  126.         return UI.Square(extract(self, 'x'), extract(self, 'y'), extract(self, 'width'), extract(self, 'height'), extract(self, 'text'))
  127.  
  128.     def update(self):
  129.         pass
  130.  
Add Comment
Please, Sign In to add comment