def draw_frame(self, canvas, balls): #draws border, arrows and balls on to canvas cw = self.cw ch = self.ch xu = self.xu #reset canvas draw.reset2(canvas, xu) #clear canvas draw.clear_canvas(canvas, "#fff") #balls for i in range(0, 2): if i % 2 == 0: canvas.fill_style = "#4c7fbe" else: canvas.fill_style = "#bb2828" draw.circle(canvas, balls[i].radius, balls[i].pos.x, balls[i].pos.y) canvas.fill() #borders canvas.stroke_style = "#000" canvas.line_width = self.border / xu canvas.stroke_rect(0, 0, cw / (1.0 * xu), ch / (1.0 * xu)) #arrows if not self.running and self.check_vel.checked: for ball in balls: draw.vel_arrows(canvas, ball, self.linewidth, self.arrow_scale) draw.reset2(canvas, xu)
def render(self, img, origin): for line in self.lines: draw.line(line, img, origin) for circle in self.circles: draw.circle(circle, img, origin) for poly in self.polygons: draw.polygon(poly, img, origin)
def draw_all(self): canvas = self.canvas cw = self.cw ch = self.ch xu = self.xu ball = self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#7ec0ee") #floor canvas.fill_style = "#1f8107" canvas.fill_rect(0, 0, cw / self.xu, self.floor_height) #pole canvas.fill_style = "rgb(111, 62, 55)" canvas.fill_rect(self.L + self.ball.radius, self.floor_height, self.D, 3) canvas.translate(self.L + self.ball.radius - 0.05, 3 + self.floor_height) canvas.rotate(-math.pi / 2) draw.polygon(canvas, 3, self.D * 6) canvas.fill_style = "rgb(227, 81, 61)" canvas.fill() draw.reset2(canvas, xu) #ball draw.circle(canvas, ball.radius, ball.pos.x, ball.pos.y) canvas.fill_style = "#fff" canvas.fill() #arrow if not self.running: ball = self.ball #velocity vector canvas.translate(ball.pos.x, ball.pos.y) if ball.vel.y > 0: canvas.rotate(ball.vel.phi()) else: canvas.rotate(-ball.vel.phi()) draw.arrow(canvas, ball.vel.mag() * self.arrow_scale, 4 * self.line_width) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu) #dashes canvas.begin_path() if not self.running: for path in self.paths: if len(path) > 2: for i in range(len(path) - 1): canvas.move_to(path[i].x, path[i].y) diff = path[i + 1] - path[i] new = path[i] + diff * 0.8 canvas.line_to(new.x, new.y) canvas.line_width = self.line_width canvas.stroke()
def draw_frame(self, canvas, balls): #draws border, arrows and balls on to canvas cw = self.cw ch = self.ch xu= self.xu #reset canvas draw.reset2(canvas,xu) #clear canvas draw.clear_canvas(canvas, "#fff") #balls for i in range(0,2): if i%2 == 0: canvas.fill_style = "#4c7fbe" else: canvas.fill_style ="#bb2828" draw.circle(canvas, balls[i].radius,balls[i].pos.x, balls[i].pos.y) canvas.fill() #borders canvas.stroke_style = "#000" canvas.line_width = self.border/xu canvas.stroke_rect(0,0, cw/(1.0*xu),ch/(1.0*xu)) #arrows if not self.running and self.check_vel.checked: for ball in balls: draw.vel_arrows(canvas, ball, self.linewidth, self.arrow_scale) draw.reset2(canvas, xu)
def draw_all(self): canvas = self.canvas self.cw = canvas.get_width() self.ch = canvas.get_height() cw = self.cw ch = self.ch xu = self.xu ball = self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#fff") canvas.fill_style = "#000" canvas.fill_rect(0, 0, cw, self.floor_height) draw.circle(canvas, ball.radius, ball.pos.x, ball.pos.y) canvas.fill_style = "#3683f3" canvas.fill() #arrow if not self.running: ball = self.ball #velocity vector canvas.translate(ball.pos.x, ball.pos.y) canvas.rotate(ball.vel.phi()) draw.arrow(canvas, ball.vel.mag() * self.arrow_scale, 4 * self.linewidth) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu) #dashes if not self.running: draw.paths(canvas, self.paths, self.linewidth, "#000")
def draw_source(self, point, canvas, colour=default_colour, wave_colour=default_colour_wave, thickness=0.003): xu = self.xu cw = self.cw ch = self.ch #point draw.circle(canvas, point.radius, x=point.pos.x, y=point.pos.y) canvas.fill_style = colour canvas.fill() big = math.sqrt((self.cw / xu * 1.0)**2 + (self.ch / xu * 1.0)**2) if point.wavefront + point.wavelength > big: point.wavefront -= point.wavelength rad = point.wavefront while rad > 0: draw.circle(canvas, rad, x=point.pos.x, y=point.pos.y) canvas.stroke_style = wave_colour canvas.line_width = thickness canvas.stroke() rad -= point.wavelength
def draw_bugs(self, canvas, pos, colour): canvas.translate(self.cw/(2.0*self.xu), self.ch/(2.0*self.xu)) for i in range(self.N): canvas.rotate(self.a) canvas.translate(pos.x, pos.y) draw.circle(canvas, self.bug.radius) canvas.fill_style = colour canvas.fill() canvas.translate(-pos.x, -pos.y)
def draw_frame(self, canvas, balls): #draws border, arrows and balls on to canvas cw = self.cw ch = self.ch xu = self.xu #reset canvas draw.reset2(canvas, xu) #clear canvas draw.clear_canvas(canvas, "#fff") #balls for i in range(0, 2): if i % 2 == 0: canvas.fill_style = "#4c7fbe" else: canvas.fill_style = "#bb2828" draw.circle(canvas, balls[i].radius, balls[i].pos.x, balls[i].pos.y) canvas.fill() #borders canvas.stroke_style = "#000" canvas.line_width = self.border / xu canvas.stroke_rect(0, 0, cw / (1.0 * xu), ch / (1.0 * xu)) #arrows if not self.running and self.check_vel.checked: for ball in balls: #x component draw.arrow(canvas, ball.vel.x * self.arrow_scale, 2 * self.linewidth, ball.pos.x, ball.pos.y) canvas.fill_style = "#333333" canvas.fill() #y component canvas.translate(ball.pos.x, ball.pos.y) canvas.rotate(math.pi / 2) draw.arrow(canvas, ball.vel.y * self.arrow_scale, 2 * self.linewidth) canvas.fill() draw.reset2(canvas, xu) #velocity vector canvas.translate(ball.pos.x, ball.pos.y) if ball.vel.y > 0: canvas.rotate(ball.vel.phi()) else: canvas.rotate(-ball.vel.phi()) draw.arrow(canvas, ball.vel.mag() * self.arrow_scale, 4 * self.linewidth) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu)
def draw_all(self): canvas = self.canvas cw= self.cw ch = self.ch xu = self.xu ball= self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#7ec0ee") #floor canvas.fill_style = "#1f8107" canvas.fill_rect(0, 0,cw/self.xu , self.floor_height) #pole canvas.fill_style = "rgb(111, 62, 55)" canvas.fill_rect(self.L+self.ball.radius, self.floor_height, self.D, 3) canvas.translate(self.L+self.ball.radius-0.05, 3+self.floor_height) canvas.rotate(-math.pi/2) draw.polygon(canvas,3, self.D*6) canvas.fill_style = "rgb(227, 81, 61)" canvas.fill() draw.reset2(canvas, xu) #ball draw.circle(canvas, ball.radius, ball.pos.x, ball.pos.y) canvas.fill_style= "#fff" canvas.fill() #arrow if not self.running: ball = self.ball #velocity vector canvas.translate(ball.pos.x, ball.pos.y) if ball.vel.y>0: canvas.rotate(ball.vel.phi()) else: canvas.rotate(-ball.vel.phi()) draw.arrow(canvas, ball.vel.mag()*self.arrow_scale, 4*self.line_width) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu) #dashes canvas.begin_path() if not self.running: for path in self.paths: if len(path)>2: for i in range(len(path)-1): canvas.move_to(path[i].x, path[i].y) diff = path[i+1] - path[i] new = path[i] + diff*0.8 canvas.line_to(new.x, new.y) canvas.line_width = self.line_width canvas.stroke()
def draw_bugs(self, canvas, pos, colour): canvas.translate(self.cw / (2.0 * self.xu), self.ch / (2.0 * self.xu)) for i in range(self.N): canvas.rotate(self.a) canvas.translate(pos.x, pos.y) draw.circle(canvas, self.bug.radius) canvas.fill_style = colour canvas.fill() canvas.translate(-pos.x, -pos.y)
def draw_bugs(self, canvas, pos, colour): canvas.translate(self.cw/(2.0*self.xu), self.ch/(2.0*self.xu)) for i in range(self.N): canvas.rotate(self.a) canvas.translate(pos.x, pos.y) draw.circle(canvas, self.bug.radius) if i%2 ==0: canvas.fill_style = "rgb(148, 76, 190)" else: canvas.fill_style = "rgb(80, 158, 46)" canvas.fill() canvas.translate(-pos.x, -pos.y)
def draw_frame(self, canvas, balls): # draws border, arrows and balls on to canvas cw = self.cw ch = self.ch xu = self.xu # reset canvas draw.reset2(canvas, xu) # clear canvas draw.clear_canvas(canvas, "#fff") # balls for i in range(0, 2): if i % 2 == 0: canvas.fill_style = "#4c7fbe" else: canvas.fill_style = "#bb2828" draw.circle(canvas, balls[i].radius, balls[i].pos.x, balls[i].pos.y) canvas.fill() # borders canvas.stroke_style = "#000" canvas.line_width = self.border / xu canvas.stroke_rect(0, 0, cw / (1.0 * xu), ch / (1.0 * xu)) # arrows if not self.running and self.check_vel.checked: for ball in balls: # x component draw.arrow(canvas, ball.vel.x * self.arrow_scale, 2 * self.linewidth, ball.pos.x, ball.pos.y) canvas.fill_style = "#333333" canvas.fill() # y component canvas.translate(ball.pos.x, ball.pos.y) canvas.rotate(math.pi / 2) draw.arrow(canvas, ball.vel.y * self.arrow_scale, 2 * self.linewidth) canvas.fill() draw.reset2(canvas, xu) # velocity vector canvas.translate(ball.pos.x, ball.pos.y) if ball.vel.y > 0: canvas.rotate(ball.vel.phi()) else: canvas.rotate(-ball.vel.phi()) draw.arrow(canvas, ball.vel.mag() * self.arrow_scale, 4 * self.linewidth) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu)
def draw_all(self): canvas = self.canvas xu = self.xu canvas.xu = xu ball = self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#fff") #ball drawrad = ball.radius*(1/(1+ball.pos.z/3)) if 0.01>drawrad or drawrad>10: self.running = False self.btn_run.text = "Run" else: draw.circle(canvas, drawrad, ball.pos.x, ball.pos.y) canvas.fill_style = "rgb(30, 96, 139)" canvas.fill() if self.running and self.check_trail.checked: b = len(self.trail) canvas.begin_path() canvas.move_to(self.trail[0].x, self.trail[0].y) canvas.quadratic_curve_to(self.trail[int(b/2)].x, self.trail[int(b/2)].y, self.trail[-1].x, self.trail[-1].y) canvas.line_width = 0.03 canvas.stroke() #paths if not self.running and self.check_paths.checked: draw.paths(canvas,self.paths, self.line_width, "#000") #arrows if not self.running: draw.vel_arrows(canvas, self.ball, self.line_width, self.arrow_scale) draw.reset2(canvas, xu) #field arrows canvas.scale(1.0/self.xu, 1.0/self.xu) draw.cart_arrows(canvas, self.E, 3, 100/((self.E.mag()+1)), x = 30, y = 50) B2 = self.B*10e3 draw.cart_arrows(canvas, B2, 3, 100/((B2.mag()+1)), x = (self.cw - 80), y = 50) canvas.scale(1,-1) canvas.font= "20px sans-serif" canvas.fill_text("E",50, -30 ) canvas.fill_text("B",(self.cw - 60), -30 ) canvas.scale(self.xu, -self.xu) #frame draw.border(canvas,5, "#000", xu)
def draw_level_objects(): colors = { True: prim_color, False: (1,0,0,1) } for obj in primitives: if obj.yaml_tag == u"!Line": if obj.visible: draw.set_color(*prim_color) else: if obj.collides: draw.set_color(0,1,0,1) else: draw.set_color(1,0,0,1) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!Circle": if obj.visible: draw.set_color(*prim_color) else: if obj.collides: draw.set_color(0,1,0,1) else: draw.set_color(1,0,0,1) draw.circle(obj.x, obj.y, obj.radius) elif obj.yaml_tag == u"!FilledRect": draw.set_color(*colors[obj.visible]) draw.rect(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!FilledTriangle": draw.set_color(*colors[obj.visible]) draw.polygon((obj.x1, obj.y1, obj.x2, obj.y2, obj.x3, obj.y3)) elif obj.yaml_tag == u"!Door": draw.set_color(*resources.key_colors[obj.key]) graphics.set_line_width(5.0) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) draw.set_color(*colors[True]) graphics.set_line_width(1.0) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!Key": draw.set_color(1,1,1,1) resources.key_images[obj.number].blit(obj.x, obj.y) simple_objects_batch.draw() draw.set_color(1,1,1,1) for label in labels: draw.rect( label.x-label.content_width/2-3, label.y-label.content_height/2, label.x+label.content_width/2+3, label.y+label.content_height/2 ) label_batch.draw()
def draw_source(self,point, canvas, colour = default_colour, wave_colour = default_colour_wave, thickness = 0.003): xu = self.xu cw = self.cw ch = self.ch #point draw.circle(canvas, point.radius, x= point.pos.x, y = point.pos.y) canvas.fill_style = colour canvas.fill() big = math.sqrt((self.cw/xu*1.0)**2 + (self.ch/xu*1.0)**2) if point.wavefront + point.wavelength <big: rad = point.wavefront draw.circle(canvas, rad, x= point.pos.x, y = point.pos.y) canvas.stroke_style = wave_colour canvas.line_width = thickness canvas.stroke()
def draw(self, obj, colour, tides = False): cw= self.cw ch = self.ch xu = self.xu canvas = self.canvas canvas.translate(cw/(2*xu), ch/(2*xu)) canvas.rotate(obj.angle) canvas.translate(obj.orbit, 0) if tides: canvas.scale(1.3, 1) draw.circle(canvas, obj.radius) canvas.fill_style = colour canvas.fill() draw.reset2(canvas, xu)
def main(): img = Image.new('RGB', IMG_DIM, color='white') my_circle = Circle(Vector([200, 50]), 100) circle_2 = Circle(Vector([0, 0]), 300) arc = hyper.arc_from_angles(my_circle, math.pi / 3, 3 * math.pi / 4) draw.axes(img, ORIGIN) draw.circle(my_circle, img, ORIGIN) draw.circle_segment(circle_2, math.pi / 2, 5 * math.pi / 4, img, ORIGIN) draw.line((0, 0), (200, 300), img, ORIGIN) draw.circle_segment(arc, img, ORIGIN) img = ImageOps.flip(img) img.save('new.png')
def draw_level(self): draw.set_color(1,1,1,1) if level.background_image != None: try: level.background_image.blit_tiled( 0, 0, 0, level.width, level.height ) except: level.background_image.blit(0,0) draw.set_color(1, 0, 1, 0.5) draw.grid(level.camera_x, level.camera_y, graphics.width, graphics.height) draw.set_color(0,0,0,1) draw.line(0,0,0,level.height) draw.line(0,level.height,level.width,level.height) draw.line(level.width,level.height,level.width,0) draw.line(level.width,0,0,0) level.draw_level_objects() draw.set_color(0,1,0,1) draw.circle(level.player_x, level.player_y, 80) if graphics.drawing: self.current_tool.keep_drawing_static()
def draw_all(self): canvas = self.canvas self.cw = canvas.get_width() self.ch = canvas.get_height() cw= self.cw ch = self.ch xu = self.xu ball= self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#fff") canvas.fill_style = "#000" canvas.fill_rect(0, 0, cw, self.floor_height) draw.circle(canvas, ball.radius, ball.pos.x, ball.pos.y) canvas.fill_style= "#3683f3" canvas.fill() #arrow if not self.running: ball = self.ball #velocity vector canvas.translate(ball.pos.x, ball.pos.y) if ball.vel.y>0: canvas.rotate(ball.vel.phi()) else: canvas.rotate(-ball.vel.phi()) draw.arrow(canvas, ball.vel.mag()*self.arrow_scale, 4*self.linewidth) canvas.fill_style = "#49902a" canvas.fill() draw.reset2(canvas, xu) #dashes if not self.running: draw.paths(canvas,self.paths, self.linewidth, "#000")
import draw #Setup draw.ht() draw.screensize(800, 800) draw.penup() draw.speed(1000) draw.seth(90) draw.sety(-100) draw.setx(100) # Drawing a hill draw.pendown() draw.circle(100, 180) draw.penup() # Drawing a stick draw.goto(0, 0) draw.pendown() draw.fd(-250) draw.penup() # Crossbar draw.pendown() draw.seth(180) draw.fd(100) draw.penup() # Rope draw.pendown() draw.seth(270)
def draw(self): draw.circle((self.x, self.y), self.size) for sensor in self.sensors: sensor.draw()
def main(): out = sys.stdout parser = argparse.ArgumentParser(description='Generate gears.') parser.add_argument("command", help="command to run") args = parser.parse_args() color = "#000000" draw.header(out, WIDTH, HEIGHT) # Parts of clock for cutting. Spool. if args.command == "spool": # Inside. draw.circle(out, 5 * DPI, 5 * DPI, LOOSE_SLIP_HOLE_RADIUS, color) draw.circle(out, 5 * DPI, 5 * DPI, 0.80 * DPI, color) # Outside. draw.circle(out, 10 * DPI, 5 * DPI, LOOSE_SLIP_HOLE_RADIUS, color) draw.circle(out, 10 * DPI, 5 * DPI, 1.25 * DPI, color) # Hole for wire. draw.circle(out, 10 * DPI + 0.85 * DPI, 5 * DPI, 0.05 * DPI, color) # Outside. draw.circle(out, 15 * DPI, 5 * DPI, LOOSE_SLIP_HOLE_RADIUS, color) draw.circle(out, 15 * DPI, 5 * DPI, 1.25 * DPI, color) # Low tooth-count test. if args.command == "low_tooth_count": gear_train = train.GearTrain(out, WIDTH / 4, HEIGHT * 3 / 5, 40) hole_radius = 0.1 * DPI gear_train.add_gear(6, None, hole_radius) # gear_train.add_gear(6, train.EAST, hole_radius) # Laser test. if args.command == "laser_test": gear_train = train.GearTrain(out, WIDTH / 4, HEIGHT * 3 / 5, 5) hole_radius = 0.1 * DPI gear_train.add_gear(64, None, hole_radius) gear_train.cy -= 10 gear_train.add_gear(16, train.NORTH, hole_radius) # Output for cover of Graphics Engine book. if args.command == "ge_book": gear_train = train.GearTrain(out, 0, 0, 5) gear_train.set_angle_offset(-2) hole_radius = 0.05 * DPI gear_train.add_gear(18, None, hole_radius) gear_train.add_gear(30, train.NORTH, hole_radius) gear_train.add_gear(20, None, hole_radius) gear_train.add_gear(60, train.WEST, hole_radius) gear_train.add_gear(16, None, hole_radius) gear_train.add_gear(64, train.NORTH, hole_radius) gear_train.add_gear(24, None, hole_radius) gear_train.add_gear(40, train.WEST, hole_radius) gear_train.add_gear(20, None, hole_radius) gear_train.add_gear(26, train.NORTH, hole_radius) gear_train.add_gear(16, None, hole_radius) gear_train.add_gear(24, train.WEST, hole_radius) # Hole test. if args.command == "hole_test": cx = DPI cy = DPI if False: r = 0.25 * DPI for i in range(5): draw.circle(out, cx, cy, r, "#000000") cx += DPI * 0.75 r += 0.001 * DPI if False: r = 0.255 * DPI r2 = 0.40 * DPI for i in range(3): draw.circle(out, cx, cy, r, "#000000") draw.circle(out, cx, cy, r2, "#000000") cx += DPI * 0.95 r += 0.001 * DPI if True: r = 0.394 * DPI for i in range(5): draw.circle(out, cx, cy, r, "#000000") cx += DPI * 0.95 r += 0.001 * DPI # Gear for inlay. if args.command == "inlay": gear_train = train.GearTrain(out, 50, 50, 20) gear_train.set_angle_offset(0) hole_radius = 0.3 * DPI gear_train.add_gear(18, None, hole_radius) draw.footer(out)
def parseFile(fileName, screens, color, edgeMatrix, transformMatrix): scriptFile = open('{}'.format(fileName), 'r') for line in scriptFile: currentLine = line.split() if (currentLine[0][0] == '#'): pass elif (currentLine[0] == 'line'): argumentLine = scriptFile.readline().split() a = [ float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]) ] b = [ float(argumentLine[3]), float(argumentLine[4]), float(argumentLine[5]) ] matrix.addEdge(edgeMatrix, a, b) elif (currentLine[0] == 'ident'): matrix.setIdentityMatrix(transformMatrix) elif (currentLine[0] == 'move'): argumentLine = scriptFile.readline().split() moveMatrix = matrix.createTranslateMatrix(float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2])) matrix.matrixMultiplication(moveMatrix, transformMatrix) elif (currentLine[0] == 'scale'): argumentLine = scriptFile.readline().split() scaleMatrix = matrix.createScaleMatrix(float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2])) matrix.matrixMultiplication(scaleMatrix, transformMatrix) elif (currentLine[0] == 'rotate'): argumentLine = scriptFile.readline().split() rotateMatrix = matrix.createRotateMatrix(argumentLine[0], float(argumentLine[1])) matrix.matrixMultiplication(rotateMatrix, transformMatrix) elif (currentLine[0] == 'circle'): argumentLine = scriptFile.readline().split() draw.circle(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), 0) elif (currentLine[0] == 'hermite'): argumentLine = scriptFile.readline().split() draw.curve(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), float(argumentLine[4]), float(argumentLine[5]), float(argumentLine[6]), float(argumentLine[7]), 0, 'hermite') elif (currentLine[0] == 'bezier'): argumentLine = scriptFile.readline().split() draw.curve(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), float(argumentLine[4]), float(argumentLine[5]), float(argumentLine[6]), float(argumentLine[7]), 0, 'bezier') elif (currentLine[0] == 'box'): argumentLine = scriptFile.readline().split() draw.box(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), float(argumentLine[4]), float(argumentLine[5])) elif (currentLine[0] == 'sphere'): argumentLine = scriptFile.readline().split() draw.sphere(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), 0) elif (currentLine[0] == 'torus'): argumentLine = scriptFile.readline().split() draw.torus(edgeMatrix, float(argumentLine[0]), float(argumentLine[1]), float(argumentLine[2]), float(argumentLine[3]), float(argumentLine[4]), 0) elif (currentLine[0] == 'clear'): edgeMatrix = [[], [], [], []] elif (currentLine[0] == 'apply'): matrix.matrixMultiplication(transformMatrix, edgeMatrix) elif (currentLine[0] == 'display'): matrix.drawEdges(screens, edgeMatrix, color) screen.display(screens) screen.clearScreen(screens) time.sleep(.01) elif (currentLine[0] == 'save'): argumentLine = scriptFile.readline().split() matrix.drawEdges(screens, edgeMatrix, color) screen.saveExtension(screens, argumentLine[0]) else: print('Bad command, ' + currentLine[0])
def stick_circles(env): for h in shortcuts.my_field_hockeyists(env) + shortcuts.opponent_field_hockeyists(env): draw.circle(h, env.game.stick_length)
def draw_all(self): canvas = self.canvas xu = self.xu canvas.xu = xu ball = self.ball draw.reset2(canvas, xu) draw.clear_canvas(canvas, "#fff") #ball drawrad = ball.radius * (1 / (1 + ball.pos.z / 3)) if 0.01 > drawrad or drawrad > 10: self.running = False self.btn_run.text = "Run" else: draw.circle(canvas, drawrad, ball.pos.x, ball.pos.y) canvas.fill_style = "rgb(30, 96, 139)" canvas.fill() if self.running and self.check_trail.checked: b = len(self.trail) canvas.begin_path() canvas.move_to(self.trail[0].x, self.trail[0].y) canvas.quadratic_curve_to(self.trail[int(b / 2)].x, self.trail[int(b / 2)].y, self.trail[-1].x, self.trail[-1].y) canvas.line_width = 0.03 canvas.stroke() #paths if not self.running and self.check_paths.checked: draw.paths(canvas, self.paths, self.line_width, "#000") #arrows if not self.running: draw.vel_arrows(canvas, self.ball, self.line_width, self.arrow_scale) draw.reset2(canvas, xu) #field arrows canvas.scale(1.0 / self.xu, 1.0 / self.xu) draw.cart_arrows(canvas, self.E, 3, 100 / ((self.E.mag() + 1)), x=30, y=50) B2 = self.B * 10e3 draw.cart_arrows(canvas, B2, 3, 100 / ((B2.mag() + 1)), x=(self.cw - 80), y=50) canvas.scale(1, -1) canvas.font = "20px sans-serif" canvas.fill_text("E", 50, -30) canvas.fill_text("B", (self.cw - 60), -30) canvas.scale(self.xu, -self.xu) #frame draw.border(canvas, 5, "#000", xu)
def sample_with_skeleton(annot, idx, preds, res=None): # Load image and basic info ds = annot.attrs['name'] img = ref.loadimg(annot, idx) c = annot['center'][idx] s = annot['scale'][idx] if res is None: res = [256, 256] # Skeleton colors colors = [ (255, 0, 0), # Upper arm (left) (255, 100, 100), # Lower arm (left) (0, 0, 255), # Upper arm (right) (100, 100, 255), # Lower arm (right) (100, 255, 100), # Head/neck/face (255, 75, 0), # Upper leg (left) (255, 175, 100), # Lower leg (left) (0, 75, 255), # Upper leg (right) (100, 175, 255) # Lower leg (right) ] # Draw arms draw.limb(img, preds[ref.parts[ds].index('lsho')], preds[ref.parts[ds].index('lelb')], colors[0], 5 * s) draw.limb(img, preds[ref.parts[ds].index('lwri')], preds[ref.parts[ds].index('lelb')], colors[1], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rsho')], preds[ref.parts[ds].index('relb')], colors[2], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rwri')], preds[ref.parts[ds].index('relb')], colors[3], 5 * s) if ds == 'mpii': # MPII # Draw head draw.circle(img, preds[ref.parts[ds].index('head')], colors[4], 5 * s) draw.circle(img, preds[ref.parts[ds].index('neck')], colors[4], 5 * s) # Draw legs draw.limb(img, preds[ref.parts[ds].index('lhip')], preds[ref.parts[ds].index('lkne')], colors[5], 5 * s) draw.limb(img, preds[ref.parts[ds].index('lank')], preds[ref.parts[ds].index('lkne')], colors[6], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rhip')], preds[ref.parts[ds].index('rkne')], colors[7], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rank')], preds[ref.parts[ds].index('rkne')], colors[8], 5 * s) elif ds == 'flic': # FLIC # Draw face draw.circle(img, preds[ref.parts[ds].index('leye')], colors[4], 3 * s) draw.circle(img, preds[ref.parts[ds].index('reye')], colors[4], 3 * s) draw.circle(img, preds[ref.parts[ds].index('nose')], colors[4], 3 * s) # Draw hips draw.circle(img, preds[ref.parts[ds].index('lhip')], colors[5], 5 * s) draw.circle(img, preds[ref.parts[ds].index('rhip')], colors[7], 5 * s) return crop(img, c, s, res)
def sample_with_skeleton(annot, idx, preds, res=None): # Load image and basic info ds = annot.attrs['name'] img = ref.loadimg(annot, idx) c = annot['center'][idx] s = annot['scale'][idx] if res is None: res = [256, 256] # Skeleton colors colors = [(255, 0, 0), # Upper arm (left) (255, 100, 100), # Lower arm (left) (0, 0, 255), # Upper arm (right) (100, 100, 255), # Lower arm (right) (100, 255, 100), # Head/neck/face (255, 75, 0), # Upper leg (left) (255, 175, 100), # Lower leg (left) (0, 75, 255), # Upper leg (right) (100, 175, 255) # Lower leg (right) ] # Draw arms draw.limb(img, preds[ref.parts[ds].index('lsho')], preds[ref.parts[ds].index('lelb')], colors[0], 5 * s) draw.limb(img, preds[ref.parts[ds].index('lwri')], preds[ref.parts[ds].index('lelb')], colors[1], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rsho')], preds[ref.parts[ds].index('relb')], colors[2], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rwri')], preds[ref.parts[ds].index('relb')], colors[3], 5 * s) if ds == 'mpii': # MPII # Draw head draw.circle(img, preds[ref.parts[ds].index('head')], colors[4], 5 * s) draw.circle(img, preds[ref.parts[ds].index('neck')], colors[4], 5 * s) # Draw legs draw.limb(img, preds[ref.parts[ds].index('lhip')], preds[ref.parts[ds].index('lkne')], colors[5], 5 * s) draw.limb(img, preds[ref.parts[ds].index('lank')], preds[ref.parts[ds].index('lkne')], colors[6], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rhip')], preds[ref.parts[ds].index('rkne')], colors[7], 5 * s) draw.limb(img, preds[ref.parts[ds].index('rank')], preds[ref.parts[ds].index('rkne')], colors[8], 5 * s) elif ds == 'flic': # FLIC # Draw face draw.circle(img, preds[ref.parts[ds].index('leye')], colors[4], 3 * s) draw.circle(img, preds[ref.parts[ds].index('reye')], colors[4], 3 * s) draw.circle(img, preds[ref.parts[ds].index('nose')], colors[4], 3 * s) # Draw hips draw.circle(img, preds[ref.parts[ds].index('lhip')], colors[5], 5 * s) draw.circle(img, preds[ref.parts[ds].index('rhip')], colors[7], 5 * s) return crop(img, c, s, res)