def display(self): colour_scale = remap(self.lifespan, (0, self.initial_lifespan), (0, 255)) fill(0, colour_scale, 0, colour_scale) stroke(colour_scale, 0, 0, colour_scale) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate(theta + PI / 2) triangle( (0, -self.size / 2), (-self.size / 4, self.size / 2), (self.size / 4, self.size / 2), ) circle((self.location.x, self.location.y), 5) """ display debug vector lines. Green = acceleration Red = velocity """ # line((self.location.x, self.location.y), # (self.location.x + self.velocity.x * 10, # self.location.y + self.velocity.y * 10)) # stroke(0, 244, 0) # line((self.location.x, self.location.y), # (self.location.x + self.acceleration.x * 100, # self.location.y + self.acceleration.y * 100)) """ Debug end """
def draw(): global sprite p5.background(255) sprite.x = mouse_x # Draw a red house in start position p5.fill(255, 0, 0, 128) sprite.draw_house() p5.fill(0, 255, 0, 128) with p5.push_matrix(): p5.translate(50, 50) sprite.draw_house() p5.translate(50, 50) sprite.draw_house() p5.translate(50, 50) sprite.draw_house() # p5.print_matrix() p5.fill(0, 0, 255, 128) with p5.push_matrix(): p5.translate(0, 50) sprite.draw_house() p5.translate(0, 50) sprite.draw_house() p5.translate(0, 50) sprite.draw_house() p5.fill(0, 255, 255, 128) with p5.push_matrix(): sprite.y = mouse_y p5.translate(50, 0) sprite.draw_pointer() p5.translate(50, 0) sprite.draw_pointer() p5.translate(50, 0) sprite.draw_pointer() sprite.y = 20
def display_pointer(self, mass=40): stroke(255) fill(100) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate_z(theta + PI / 2) triangle((0, -mass / 2), (-mass / 4, mass / 2), (mass / 4, mass / 2)) fill(0, 255, 0) circle((self.location.x, self.location.y), 5)
def draw(): global v p5.background(255) # Draw a rectangle in start position p5.fill(192) p5.rect((v.x, v.y), v.size, v.size) # Draw a red rectangle in a new position by changing the rect coordianates p5.fill(255, 0, 0, 128) p5.rect((v.x + 70, v.y + 30), v.size, v.size) # Draw cascading blue rectangles by applying transformations of the canvas p5.fill(0, 0, 255, 128) p5.push_matrix() p5.translate(v.size, v.size) p5.rect((v.x, v.y), v.size, v.size) p5.translate(v.size, v.size) p5.rect((v.x, v.y), v.size, v.size) p5.translate(v.size, v.size) p5.rect((v.x, v.y), v.size, v.size) # reset transformations and reset matrix do the same. p5.reset_transforms() # an alternative to using push / reset, is the with push: p5.fill(0, 255, 0, 128) with p5.push_matrix(): p5.translate(25, 0) p5.rect((v.x, v.y), v.size, v.size) p5.translate(25, 0) p5.rect((v.x, v.y), v.size, v.size) p5.translate(25, 0) p5.rect((v.x, v.y), v.size, v.size) # p5.print_matrix() p5.print_matrix() print("matrix is back to normal 4x4 numpy ident")
def draw(): global t p.background(255) p.translate(width/2, height/2) for i in range(90): p.rotate(p.radians(360/90)) with p.push_matrix(): p.translate(200, 0) p.rotate(p.radians(t+2*i*360/90)) tri(100) t+=0.01
def display(self): for row in range(self.number_of_rows): for column in range(self.number_of_columns): origin = [column * self.resolution, row * self.resolution] vector_x = copy.copy(self.field[row][column].x) vector_y = copy.copy(self.field[row][column].y) vector_x *= 10 vector_y *= 10 with push_matrix(): translate(self.resolution / 2, self.resolution / 2) line((origin), (origin[0] + vector_x, origin[1] + vector_y)) reset_matrix()
def draw(): global sprite_1 global sprite_2 p5.background(255) theta = mouse_y # sprite_1.x = mouse_x # reference shape sprite_1.draw_pointer() p5.fill(255, 0, 0, 128) # rotate a house shape about its centre with p5.push_matrix(): p5.translate(40, 40) p5.rotate(p5.radians(theta)) sprite_1.draw_house() p5.fill(250, 250, 0, 127) with p5.push_matrix(): p5.translate(mouse_x, mouse_y) p5.rotate(2 * p5.PI * mouse_y / height) sprite_2.draw_pointer()
def display(self): stroke(255) fill(255) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate_z(theta + PI / 2) triangle( (0, -self.mass / 2), (-self.mass / 4, self.mass / 2), (self.mass / 4, self.mass / 2), ) fill(0, 255, 0) circle((self.location.x, self.location.y), 5)
def draw(): global t p.background(255) p.translate(width/2, height/2) p.rotate(p.radians(t)) for _ in range(12): p.rotate(p.radians(360/12)) with p.push_matrix(): p.translate(200, 0) p.rotate(p.radians(t)) p.rect((0, 0), 50, 50) t += 1
def draw(): global sprite p5.background(255) theta = mouse_y # reference shape sprite.draw_pointer() p5.fill(255, 0, 0, 128) # rotate a house shape aboutits centre with p5.push_matrix(): p5.translate(40, 40) p5.rotate(p5.radians(theta)) sprite.draw_house()
def draw(self, stroke, stroke_weight): colors = [ (180, 180, 180), (255, 255, 255), (50, 50, 125), (255, 255, 0), (0, 255, 255), (0, 100, 255), (100, 255, 100) ] with p5.push_matrix(): p5.apply_matrix(self.surface.get_transform_mat()) with p5.push_style(): try: for y, row in enumerate(self.grid): for x, cell in enumerate(row): p5.stroke(stroke) p5.stroke_weight(stroke_weight * (4 if cell.selected else 1)) p5.fill(p5.Color(*colors[cell.id]) if cell.id > -1 else p5.Color(0, 0, 0, 0)) p5.rect(x, y, 1, 1) except TypeError: pass
def draw(): global corner_handle p5.background(0) with p5.push_matrix(): p5.apply_matrix(canvas_surface.get_transform_mat()) # GIS shapes and objects if show_basemap: _gis.draw_basemap() if show_shapes: _gis.draw_polygon_layer(buildings, 0, 1, p5.Color(96, 205, 21), p5.Color(213, 50, 21), 'co2') _gis.draw_polygon_layer(typologiezonen, 0, 1, p5.Color(123, 201, 230, 50)) _gis.draw_linestring_layer(nahwaermenetz, p5.Color(217, 9, 9), 3) _gis.draw_polygon_layer(waermezentrale, 0, 1, p5.Color(252, 137, 0)) # find buildings intersecting with selected grid cells buildings['selected'] = False for y, row in enumerate(_grid.grid): for x, cell in enumerate(row): if cell.selected: # get viewport coordinates of the cell rectangle cell_vertices = _grid.surface.transform([[ _x, _y ] for _x, _y in [[x, y], [x + 1, y], [x + 1, y + 1], [x, y + 1]]]) ii = _gis.get_intersection_indexer( buildings, cell_vertices) buildings.loc[ii, 'selected'] = True # highlight selected buildings _gis.draw_polygon_layer(buildings[buildings.selected], p5.Color(255, 0, 127), 2, None) # grid if show_grid: _grid.draw(p5.Color(255, 255, 255), 1) # mask border = 1000 with p5.push_style(): p5.fill(p5.Color(0, 0, 0)) p5.rect(-border, -border, width + 2 * border, border) p5.rect(-border, height, width + 2 * border, height + border) p5.rect(-border, -border, border, height + 2 * border) p5.rect(width, -border, width + border, height + 2 * border) # get the drag handle (if the mouse hovers over it) corner_handle = canvas_surface.get_corner_handle(20) if corner_handle: with p5.push_style(): p5.no_stroke() p5.fill(p5.Color(255, 255, 255, 200)) p5.circle(list(corner_handle)[0], list(corner_handle)[1], 20)