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
        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_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
        self.cw  = canvas.get_width()
        self.ch = canvas.get_height()
        cw= self.cw
        ch = self.ch
        xu = self.xu

        draw.reset2(canvas, xu)
        self.draw(self.tides, "#ffd600", True)
        self.draw(self.earth, "#008cff")
        self.draw(self.moon, "#00ff94")
        canvas.begin_path()
        canvas.translate(cw/(2*xu), ch/(2*xu))
        canvas.move_to(0,0)
        canvas.rotate(self.earth.angle)
        canvas.line_to(self.earth.radius, 0)
        canvas.line_width =0.05
        canvas.stroke_style =  "#d6786b"
        canvas.stroke()
        draw.reset2(canvas, xu)

        if self.check_arrows.checked:
            #arrows
            canvas.translate(cw/(2*xu), ch/(2*xu))

            canvas.rotate(self.moon.angle)
            canvas.translate(self.moon.orbit, 0)
            canvas.rotate(math.pi/2 -(self.moon.angle-self.tides.angle))
            draw.arrow(canvas,-0.01*(self.earth.ang_vel - self.moon.ang_vel), 0.2)
            canvas.fill_style = "#d14f42"
            canvas.fill()


            draw.reset2(canvas, xu)
            canvas.translate(cw/(2*xu), ch/(2*xu))
            canvas.rotate(self.tides.angle)
            canvas.translate(1.3*self.earth.radius, 0)
            canvas.rotate(math.pi/2)
            draw.arrow(canvas,0.01*(self.earth.ang_vel - self.moon.ang_vel), 0.2)
            canvas.fill_style = "#d14f42"
            canvas.fill()
            draw.reset2(canvas, xu)
Exemple #5
0
    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
        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")
Exemple #7
0
    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)