def draw_house(self): p5.rect((self.x - self.size / 2, self.y), self.size, self.size) p5.triangle( (self.x - self.size, self.y), (self.x + self.size, self.y), (self.x, self.y - self.size), )
def draw(self): if self.frame_rate == 0: p5.background(0, 0, 0) # set initial background to black # action if self.paused: return self.frame_rate += 1 self.update() # MARK: actual drawing p5.background(0, 0, 0, 90) p5.fill(255) p5.stroke(255) p5.rect((self.user.x, self.user.y), self.block_width, self.block_height) p5.rect((self.machine.x, self.machine.y), self.block_width, self.block_height) p5.ellipse((self.ball.x, self.ball.y), 2 * self.ball_radius, 2 * self.ball_radius) if self.draw_prediction and self.last_prediction is not None: p5.no_fill() p5.stroke(220, 0, 0) p5.ellipse((self.width - self.block_width - self.ball_radius, self.last_prediction), 2 * self.ball_radius, 2 * self.ball_radius)
def draw_objects(self): # global simulation # triangle((0, 0), (0, 200), (350, 100)) background(30, 30, 47) # don't paint obstacles for free run if self.free_run: return fill(50) # shaded are upper quadrant quad((0, 0), (0, 160), (280, 256), (self.shaded_area_x, 0)) quad((0, self.height), (0, 640), (280, 544), (self.shaded_area_x, self.height)) fill(102) triangle((0, 160), (0, 640), (700, 400)) # fishes' start box rect((self.box_left, 335), self.box_width, self.box_width) # replica line for rc in self.replicas_coordinates: line((0, rc[2]), (rc[0], rc[1])) # line((0, 720), (self.replica_x_start, self.replica_y_start)) # shaded area line line((self.shaded_area_x, 0), (self.shaded_area_x, self.height)) # 544 # decision line line((self.decision_x, 0), (self.decision_x, self.height))
def draw(): p.background(0) p.translate(20, 20) for x in range(30): for y in range(30): d = p.dist((30*x, 30*y), (mouse_x, mouse_y)) p.fill(0.5*d, 255, 255) p.rect((30*x, 30*y), 25, 25)
def draw(): global t p.background(255) p.translate(width/2, height/2) p.rotate(p.radians(t)) for _ in range(12): p.rect((200, 0),50, 50) p.rotate(p.radians(360/12)) t += 2
def draw_midi(t): for i in notes: for j in beats: fill = pg.loc[(j, i), str(t)] if fill == '0': p5.fill(0) else: r, g, b = [int(c) for c in eval(fill)] p5.fill(r, g, b) p5.rect((i * w_scale, j * h_scale), w_scale, h_scale)
def text(self): if self.is_text: with pf.push_style(): pf.text(self.str, (self.x, self.y + 30)) print(pf.text_ascent(), pf.text_descent(), pf.text_width(self.str)) pf.no_fill() pf.stroke(*self.stroke_rgb) pf.rect((self.x, self.y + 30), pf.text_width(self.str), pf.text_ascent() + pf.text_descent(), mode="CORNER")
def draw(): p.translate(width / 2, height / 2) for x in arange(xmin, xmax, .01): for y in arange(ymin, ymax, .01): z = [x, y] c = [0.285, 0.01] col = julia(z, c, 100) if col == 100: p.fill(0) else: p.fill((3 * col), 255, 255) p.rect((x * xscl, y * yscl), 1, 1)
def draw_box(qt): no_fill() stroke(255, 0, 0) rect((qt.boundary[0], qt.boundary[1]), qt.boundary[2], qt.boundary[3]) fill(0, 255, 0) stroke(0, 255, 0) if len(qt.points) > 0: for pt in qt.points: ellipse([pt.x, pt.y], 1, 1) if qt.children[0] is not None: for child in qt.children: draw_box(child)
def draw(): p.translate(width / 2, height / 2) x = xmin while x < xmax: y = ymin while y < ymax: z = [x, y] c = [-0.4, 0.6] col = julia(z, c, 100) if col == 100: p.fill(0) else: p.fill((3 * col), 255, 255) p.rect((x * xscl, y * yscl), 1, 1) y += 0.01 x += 0.01
def rect(self): if self.is_rect: with pf.push_style(): if not self.is_stroke and not self.is_fill: return pf.color_mode("RGB") if self.is_fill: pf.fill(*self.fill_rgb) else: pf.no_fill() if self.is_stroke: pf.stroke_weight(self.stroke_weight) pf.stroke(*self.stroke_rgb) else: pf.no_stroke() pf.rect([self.get_rect_x(), self.get_rect_y()], self.w, self.h)
def draw(): # pf.image_mode("center") pf.background(255) pf.image(img0,(100,100)) pf.fill(255,0,0) # pf.text_align("LEFT","CENTER") pf.text_size(100) # pf.image_mode("corner") en_str = "hello 你好" pf.text(en_str,(200,200)) pf.rect((100,100), *[100,100])
def draw(): global perlx global perly perlx += 0.005 perly += 0.005 fill(remap(noise(perlx), (0, 1), (0, 255)), (255), (255), 100, color_mode="HSB") rect((width - 10, height), 10, -10, mode="CORNER") if mouse_is_pressed: fill(remap(noise(perlx), (0, 1), (0, 255)), (255), (255), 100, color_mode="HSB") else: fill(255, 15) circle_size = 25 * (noise(perlx, perly) + 1) circle((mouse_x, mouse_y), circle_size)
def draw(): p5.background(0) p5.image_mode("CORNER") p5.image(Map.sprite, (0, 0), size=(Map.sprite.size[0] * screenScale / 6, Map.sprite.size[1] * screenScale / 6)) if not True: p5.stroke(255) p5.no_fill() for x in range(int(width / 16)): for y in range(int(height / 16)): p5.begin_shape() p5.vertex(x * scl, y * scl) p5.vertex(x * scl, (y + 1) * scl) p5.vertex((x + 1) * scl, (y + 1) * scl) p5.vertex((x + 1) * scl, y * scl) p5.end_shape() p5.rect_mode("CENTER") p5.fill(255, 0, 0, 90) for x, y in Map.bannedList: p5.rect((x * scl + 0.5 * scl, y * scl + 0.5 * scl), scl, scl)
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 frm # pf.image_mode("center") pf.background(255) x, y = (10, 10) xgap, ygap = 2 * w + 20, h + 20 for i, item in enumerate(img_L): t0 = time.time() img, img_path, d_color, palette = item px = x + (i // 7) * xgap py = y + (i % 7) * ygap # pf.image(img,(px,py),(w,h)) pf.fill(*d_color) pf.rect((px + w, py), *(w / 3, h)) # pf.circle((px+w,py), w/3) pf.fill(*palette[0]) pf.rect((px + w + w * 1 / 3, py), *(w / 3, h)) # pf.circle((px+w+w*1/3,py), w/3) pf.fill(*palette[1]) pf.rect((px + w + w * 2 / 3, py), *(w / 3, h)) # pf.circle((px+w+w*2/3,py), w/3) # print("{}s".format(time.time()-t0)) frm += 1 print(frm) # pf.save_frame(img_path + "screen_.png") if frm == 30: pr.disable() s = io.StringIO() ps = pstats.Stats(pr, stream=s).sort_stats("tottime") # ps = pstats.Stats(pr, stream=s).sort_stats("cumtime") ps.print_stats() with open("res.txt", "w") as wf: print(s.getvalue(), file=wf) print("Writing profile to res.txt") print("Total elapsed time: {}s".format(round(time.time() - t1, 1)))
def draw_rectangle_at(self, r, c, color): p1 = Vector(c*self.rect_width, r*self.rect_height) p2 = Vector((c+1)*self.rect_width, (r+1)*self.rect_height) p5.fill(*color) p5.rect((p1.x, p1.y), self.rect_width, self.rect_height)
def draw(): if verbose: print(f"Drawing background.") background('#ffffff') no_stroke() # draw non-organic elements if verbose: print(f"Drawing shapes...") for i, row in df[(df.area_page != 0) & (~df.label.isin(['organic', 'ads']))].iterrows(): dimensions = row['dimensions'] location = row['location'] category = row['category'] color = cat2color[category.split('-')[0]] h = dimensions['height'] w = dimensions['width'] x = location['x'] y = location['y'] c = fill(color) rect((x, y), w, h) for i, row in df[(df.area_page != 0) & (df.label == 'ads')].iterrows(): dimensions = row['dimensions'] location = row['location'] category = row['category'] color = cat2color[category.split('-')[0]] h = dimensions['height'] w = dimensions['width'] x = location['x'] y = location['y'] c = fill(color) rect((x, y), w, h) # draw organic elements for i, row in df[(df.area_page != 0) & (df.label == 'organic')].iterrows(): dimensions = row['dimensions'] location = row['location'] category = row['category'] color = cat2color[category.split('-')[0]] h = dimensions['height'] w = dimensions['width'] x = location['x'] y = location['y'] c = fill(color) rect((x, y), w, h) # draw buttons elements for i, row in df[(df.area_page != 0) & (df.category == 'link-button')].iterrows(): dimensions = row['dimensions'] location = row['location'] category = row['category'] color = cat2color[category.split('-')[0]] h = dimensions['height'] w = dimensions['width'] x = location['x'] y = location['y'] c = fill(color) rect((x, y), w, h) if fn_img: tint(255, 60) image(img, (0, 0)) if verbose: print(f"Saving file") # save the file... save(fn_out) os.rename(fn_out.replace('.png', '0000.png'), fn_out) # draw reference image if verbose: print(f"Done.") exit()
def drawBar(self): rect_mode("CORNER") rect((self.xPos, self.yPos), self.barWidth, self.windowHeight)
def draw_square(self, x=0, y=0): p5.rect((self.x, self.y), self.size, self.size)
def draw(self): p5.stroke_weight(0.01) if self.stage > 0: p5.rect((self.bottomLeft.x, self.bottomLeft.y), self.linewidth, -self.height) if self.stage > 1: p5.rect((self.bottomLeft.x, self.bottomLeft.y - self.height), self.width / 2 + self.linewidth / 2, self.linewidth) if self.stage > 2: p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 2, self.bottomLeft.y - self.height), self.linewidth, self.height / 4) if self.stage > 3: p5.no_fill() p5.circle((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 2.5)), self.linewidth * 5, mode="CENTER") if self.stage > 4: p5.fill(255) p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5)), self.linewidth / 2, self.height / 4) if self.stage > 5: p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + 10), -self.width / 4, self.linewidth / 2) if self.stage > 6: p5.rect((self.bottomLeft.x + self.width / 2 + self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + 10), self.width / 4, self.linewidth / 2) if self.stage > 7: p5.stroke(255) p5.stroke_weight(4) p5.line((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + self.height / 4), (self.bottomLeft.x + self.width - self.width / 4, self.bottomLeft.y - self.height / 12)) if self.stage > 8: p5.line((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + self.height / 4), (self.bottomLeft.x + self.width - self.width * 3 / 4, self.bottomLeft.y - self.height / 12))
def draw_square(self, x=0, y=0): p5.rect((self.x, self.y), 40, 40)
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(): draw_box(qt) no_fill() stroke(0, 0, 255) rect([search[0], search[1]], search[2], search[3])
def render(self): p.fill(255) p.rect(self.pos.x, self.pos.y, self.w, self.h) self.render_fires()
def show(self): p5.rect((self.pos.x, self.pos.y), self.width, self.height)
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)