def main(): P = [[40], [40]] V0 = [[30], [30]] V1 = [[40], [70]] V2 = [[50], [30]] points = [V0, V1, V2] aspect_correct = [[1, 0], [0, 4 / 7]] home = "\N{escape}[H" wakeup_time = time.time() print(home + "\N{escape}[J\N{escape}[?25l") t = 0 try: while True: kanvas = canvas.Canvas() rot = matrix.rotate_2D(t * 0.5) r_points = [] for point in points: C = matrix.sub(point, P) C = matrix.mult(rot, C) C = matrix.add(P, C) C = matrix.mult(aspect_correct, C) r_points.append(C) t += 1 kanvas.triangle(round(r_points[0][0][0]), round(r_points[0][1][0]), round(r_points[1][0][0]), round(r_points[1][1][0]), round(r_points[2][0][0]), round(r_points[2][1][0])) image = home + kanvas.get_image() print(image) wakeup_time += 0.05 time.sleep(max(0, wakeup_time - time.time())) finally: print(home + "\N{escape}[J \N{escape}[?25h")
def main(): P = [[40], [40], [0]] Axis = [[10], [5], [3]] # V0 = [[30], # [30], # [0]] # V1 = [[40], # [70], # [0]] # V2 = [[50], # [30], # [0]] # points = [V0, V1, V2] points = [] for i in range(15): points.append([[random.randint(20, 60)], [random.randint(30, 60)], [random.randint(-20, 20)]]) aspect_correct = [[1, 0, 0], [0, 4/7, 0], [0, 0, 1]] home = "\N{escape}[H" wakeup_time = time.time() print(home + "\N{escape}[J\N{escape}[?25l") t = 0 try: while True: kanvas = canvas.Canvas() rot = matrix.rotate_3D(t * 0.1, Axis) r_points = [] for point in points: C = matrix.sub(point, P) C = matrix.mult(rot, C) C = matrix.add(P, C) C = matrix.mult(aspect_correct, C) r_points.append(C) t += 1 for r_point in r_points: kanvas.dab(round(r_point[0][0]), round(r_point[1][0])) # kanvas.triangle(round(r_points[0][0][0]), # round(r_points[0][1][0]), # round(r_points[1][0][0]), # round(r_points[1][1][0]), # round(r_points[2][0][0]), # round(r_points[2][1][0])) image = home + kanvas.get_image() print(image) wakeup_time += 0.05 time.sleep(max(0, wakeup_time - time.time())) finally: print(home + "\N{escape}[J \N{escape}[?25h")
def __init__(self, filename): super(PygameInterpreter, self).__init__(filename) # Font if os.path.exists(DIR_FONT): font_name = DIR_FONT else: self.error("No {0}. Falling back to pygame default font.".format( DIR_FONT)) font_name = None # pygame default self.font = pygame.font.Font(font_name, FONT_SIZE) # pixel positioning self.text_height = self.font.get_linesize() border_width = int(self.text_height * BORDER_WIDTH_MULTIPLIER) self.text_topleft = [border_width] * 2 txt_area_size = matrix.sub(self.resolution, matrix.mul(self.text_topleft, [2, 2])) self.row_length = txt_area_size[0] # text placing self.linenumber = 0 self.remaining_row = self.row_length self.text = [] self.text_states = [] # setup self.clearwait = False #~ # black filter #~ self.darkening = 0 # buttons self.buttons = [] # menu self.rmenu = None # saving # normally this should be read in from the savenumber command self.savenumber = 20 self.saves = dict()
def __init__(self, filename): super(PygameInterpreter, self).__init__(filename) # Font if os.path.exists(DIR_FONT): font_name = DIR_FONT else: self.error( "No {0}. Falling back to pygame default font.".format(DIR_FONT) ) font_name = None # pygame default self.font = pygame.font.Font(font_name, FONT_SIZE) # pixel positioning self.text_height = self.font.get_linesize() border_width = int(self.text_height*BORDER_WIDTH_MULTIPLIER) self.text_topleft = [border_width]*2 txt_area_size = matrix.sub( self.resolution, matrix.mul(self.text_topleft, [2, 2]) ) self.row_length = txt_area_size[0] # text placing self.linenumber = 0 self.remaining_row = self.row_length self.text = [] self.text_states = [] # setup self.clearwait = False #~ # black filter #~ self.darkening = 0 # buttons self.buttons = [] # menu self.rmenu = None # saving # normally this should be read in from the savenumber command self.savenumber = 20 self.saves = dict()
else: path = param # Чтение JSON со входными данными with open(path) as f: data = json.load(f) # Словарь функций dictionary = { '1': matrix.add(data['first_matrix_dimensions'], data['second_matrix_dimensions'], data['first_matrix'], data['second_matrix']), '2': matrix.sub(data['first_matrix_dimensions'], data['second_matrix_dimensions'], data['first_matrix'], data['second_matrix']), '3': matrix.mult(data['first_matrix_dimensions'], data['second_matrix_dimensions'], data['first_matrix'], data['second_matrix']), '4': matrix.det(data['number'], data['first_matrix']) } # Вызов функции из словоря по списку входных данных for param in calls: if isinstance(dictionary[param], list) and not (isinstance(dictionary[param][0], int) or isinstance(dictionary[param][0], float)): for i in range(len(dictionary[param])):