コード例 #1
0
ファイル: zmf_form1.py プロジェクト: ss2165/ss2165.github.io
  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)
コード例 #2
0
ファイル: zmf_form1.py プロジェクト: ss2165/ss2165.github.io
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)