Example #1
0
 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_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()
Example #4
0
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()
Example #5
0
 def draw(self):    
     if not self.visible: return
     super(PolygonButton, self).draw()
     
     x, y = self.x+self.width/2, self.y+self.height/2
     poly = self.generate_polygon(x,y,x,self.y+self.height*0.9,self.sides)
     if self.fill:
         if graphics.fill_rainbow():
             graphics.set_color(1,1,1,1)
         else:
             graphics.set_color(color=graphics.fill_color)
         draw.polygon(poly)
     if self.outline:
         graphics.set_line_width(2)
         if graphics.line_rainbow():
             graphics.set_color(1,1,1,1)
         else:
             graphics.set_color(color=graphics.line_color)
         draw.line_loop(poly)
         draw.points(poly)
Example #6
0
 def draw_polygon(self, canvas, N, L):
     canvas.translate(self.cw / (2.0 * self.xu), self.ch / (2.0 * self.xu))
     draw.polygon(canvas, N, L)
     canvas.stroke_style = "#000"
     canvas.line_width = self.line_width
     canvas.stroke()
 def draw_polygon(self,canvas, N, L):
     canvas.translate(self.cw/(2.0*self.xu), self.ch/(2.0*self.xu))
     draw.polygon(canvas, N, L)
     canvas.stroke_style = "#000"
     canvas.line_width = self.line_width
     canvas.stroke()