Exemplo n.º 1
0
def graphFunction():
    x = xmin
    while x <= xmax:
        p.stroke(255, 0, 0)
        p.fill(0)
        p.line((x * xscl, f(x) * yscl), ((x + 0.1) * xscl, f(x + 0.1) * yscl))
        x += 0.1
Exemplo n.º 2
0
def draw():
    p5.background(0)

    if player.walking:
        settings.Maps[settings.currentMap].move(player)
        player.walkingAnimation(settings.Maps[settings.currentMap])
        if player.walkTimer % player.walkingAnimationTime == 0 and player.stopRequest:
            player.walking = False
            player.walkTimer = 0

    settings.Maps[settings.currentMap].show()
    player.show()
    settings.Maps[settings.currentMap].drawExtras()

    p5.stroke(255)
    p5.stroke_weight(1)
    if showGrid:
        for x in range(settings.Maps[settings.currentMap].gridWidth + 2):
            p5.line((settings.Maps[settings.currentMap].GridtoPosX(x),
                     settings.Maps[settings.currentMap].GridtoPosY(0)),
                    (settings.Maps[settings.currentMap].GridtoPosX(x),
                     settings.Maps[settings.currentMap].GridtoPosY(
                         settings.Maps[settings.currentMap].gridHeight + 1)))
        for y in range(settings.Maps[settings.currentMap].gridHeight + 2):
            p5.line((settings.Maps[settings.currentMap].GridtoPosX(0),
                     settings.Maps[settings.currentMap].GridtoPosY(y)),
                    (settings.Maps[settings.currentMap].GridtoPosX(
                        settings.Maps[settings.currentMap].gridWidth + 1),
                     settings.Maps[settings.currentMap].GridtoPosY(y)))
Exemplo n.º 3
0
    def addArrow(self, p1, p2, color=BLACK):
        p5.stroke(color)

        self.addLine(p1, p2)

        to_int = (int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]))
        if to_int in ARROW_CACHE:
            arrow = ARROW_CACHE[to_int]

        else:
            p1 = QPoint(*p1)
            p2 = QPoint(*p2)

            path = QPainterPath()
            path.moveTo(p1)
            path.lineTo(p2)

            line = QLineF(p1, p2)

            end = p2
            pathlen = path.length()
            leng = min(10, pathlen / 4.0)
            arrowbase = path.pointAtPercent(path.percentAtLength(pathlen - leng))
            l1 = QLineF(arrowbase, end)
            l2 = QLineF(arrowbase, end)
            l1.setAngle(line.angle() - 150)
            l2.setAngle(line.angle() + 150)
            l1.setLength(l1.length() / 2.0)
            l2.setLength(l2.length() / 2.0)

            arrow = (arrowbase.toTuple(), l1.p2().toTuple(), end.toTuple(), l2.p2().toTuple())
            ARROW_CACHE[to_int] = arrow

        p5.fill(color)
        p5.quad(*arrow)
Exemplo n.º 4
0
def draw():
    global Maps, showGrid
    p5.background(0)
    Maps[0].show()

    if showGrid:
        p5.stroke(255)
        p5.no_fill()
        for x in range(Maps[0].gridWidth+1):
            x += (width/2)/scl-Maps[0].gridpos.x-0.5
            for y in range(Maps[0].gridHeight+1):
                y += (height/2)/scl-Maps[0].gridpos.y-9/32
                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()

    if player.walking:
        Maps[0].move(player)
        player.walkingAnimation(Maps[0])
        if player.walkTimer % player.walkingAnimationTime == 0 and player.stopRequest:
            player.walking = False
            player.walkTimer = 0

    p5.fill(255, 0, 0, 70)

    # p5.rect((4*scl+scl*((width/2)/scl-Maps[0].gridpos.x-0.5),4*scl+scl*((height/2)/scl-Maps[0].gridpos.y-9/32)),scl,scl)
    player.show()
    print(Maps[0].gridpos.x, Maps[0].gridpos.y)
Exemplo n.º 5
0
    def display(self):
        colour_scale = remap(self.lifespan, (0, self.initial_lifespan),
                             (0, 255))
        fill(0, colour_scale, 0, colour_scale)
        stroke(colour_scale, 0, 0, colour_scale)

        theta = self.velocity.angle
        with push_matrix():
            translate(self.location.x, self.location.y)
            rotate(theta + PI / 2)
            triangle(
                (0, -self.size / 2),
                (-self.size / 4, self.size / 2),
                (self.size / 4, self.size / 2),
            )
        circle((self.location.x, self.location.y), 5)
        """
        display debug vector lines.
        Green = acceleration
        Red = velocity
        """

        # line((self.location.x, self.location.y),
        #      (self.location.x + self.velocity.x * 10,
        #       self.location.y + self.velocity.y * 10))
        # stroke(0, 244, 0)
        # line((self.location.x, self.location.y),
        #      (self.location.x + self.acceleration.x * 100,
        #       self.location.y + self.acceleration.y * 100))
        """ Debug end """
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def show(self):
        if (self.blinkCounter > 5):
            stroke(255, 0, 0)
        else:
            stroke(0, 0, 255)

        fill(0, 0, 255)
        circle((self.position.x, self.position.y), 10)
def new_doodle(d):
    p5.background(240, 238, 225)

    n = doodles[d]

    query = "SELECT MIN(vertex_x) as 'left', " \
          "MAX(vertex_x) as 'right', " \
                   "MIN(vertex_y) as 'top', " \
                   "MAX(vertex_y) as 'bottom' " \
            "FROM path_verticies " \
            "WHERE doodle_id = '%s'" % d

    table_rows = db.query(query)
    outers = {
        k: v
        for k, v in zip(['left', 'right', 'top', 'bottom'], table_rows[0])
    }
    l, r, t, b = outers['left'], outers['right'], outers['top'], outers[
        'bottom']

    x_interp = interp1d([l, r], [0, res])
    y_interp = interp1d([t, b], [0, res])

    for i in range(n):

        path_chars_columns = [
            'doodle_id', 'path_number', 'color_r', 'color_g', 'color_b',
            'stroke_weight'
        ]

        path_verts_columns = [
            'doodle_id', 'path_number', 'vertex_number', 'vertex_x', 'vertex_y'
        ]

        query = "SELECT * FROM path_characteristics " \
                "WHERE doodle_id = '%s' AND path_number = %d" % (d, i)
        table_rows = db.query(query)
        path_chars = {k: v for k, v in zip(path_chars_columns, table_rows[0])}

        query = "SELECT * FROM path_verticies " \
                "WHERE doodle_id = '%s' AND path_number = %d" % (d, i)
        table_rows = db.query(query)
        path_verts = pd.DataFrame(table_rows, columns=path_verts_columns)

        p5.stroke(path_chars['color_r'], path_chars['color_g'],
                  path_chars['color_b'])

        for i in range(path_verts.shape[0] - 1):

            row = path_verts.iloc[i]
            row_next = path_verts.iloc[i + 1]

            x = round(float(x_interp(row.vertex_x)), 2)
            y = round(float(y_interp(row.vertex_y)), 2)
            x_next = round(float(x_interp(row_next.vertex_x)), 2)
            y_next = round(float(y_interp(row_next.vertex_y)), 2)

            p5.line((x, y), (x_next, y_next))
Exemplo n.º 9
0
def draw():
    global counter
    counter+=0.01
    p5.background(0)
    p5.fill(0,255,0)
    p5.stroke(0)
    #p5.rotate_x(counter)
    p5.rotate_y(counter)
    #p5.sphere(300)
    p5.box(300,300,300)
Exemplo n.º 10
0
def draw():
    global smallBall, bigBall
    p5.background(0)
    smallBall.updatePos(bigBall)
    smallBall.collision(bigBall)

    smallBall.show()
    bigBall.show()
    p5.stroke(255, 0, 0)
    p5.line((smallBall.pos), (bigBall.pos))
Exemplo n.º 11
0
def grid(xscl, yscl):
    p.stroke_weight(1)
    p.stroke(0, 255, 255)
    for i in range(xmin, xmax + 1):
        p.line((i * xscl, ymin * yscl), (i * xscl, ymax * yscl))
    for i in range(ymin, ymax + 1):
        p.line((xmin * xscl, i * yscl), (xmax * xscl, i * yscl))
    p.stroke(0)
    p.line((0, ymin * yscl), (0, ymax * yscl))
    p.line((xmin * xscl, 0), (xmax * xscl, 0))
Exemplo n.º 12
0
def draw():
    p.background(255)
    p.translate(width / 2, height / 2)
    grid(xscl, yscl)
    ang = p.remap(mouse_y, (0, width), (0, p.TWO_PI))
    rot_matrix = [[p.cos(ang), -p.sin(ang)], [p.sin(ang), p.cos(ang)]]
    newmatrix = transpose(multmatrix(rot_matrix, transpose(fmatrix)))
    graphPoints(fmatrix)
    p.stroke(255, 0, 0)
    graphPoints(newmatrix)
Exemplo n.º 13
0
 def display_pointer(self, mass=40):
     stroke(255)
     fill(100)
     theta = self.velocity.angle
     with push_matrix():
         translate(self.location.x, self.location.y)
         rotate_z(theta + PI / 2)
         triangle((0, -mass / 2), (-mass / 4, mass / 2), (mass / 4, mass / 2))
     fill(0, 255, 0)
     circle((self.location.x, self.location.y), 5)
Exemplo n.º 14
0
def draw():

    p5.translate(width / 2, height / 2)

    #v=p5.Vector(randint(-100,100),randint(-100,100))
    v = p5.Vector.random_2D()  #random unit vector in 2d
    v *= 100
    p5.stroke_weight(4)
    p5.stroke(255, 50)
    p5.line((0, 0), (v.x, v.y))
Exemplo n.º 15
0
def draw():
    p5.background(0)
    pos = p5.Vector(200, 200)
    mouse = p5.Vector(mouse_x, mouse_y)
    v = mouse - pos
    #m=abs(v)
    v = v.normalize() * 100
    p5.translate(width / 2, height / 2)
    p5.stroke_weight(4)
    p5.stroke(255)
    p5.line((0, 0), (v.x, v.y))
Exemplo n.º 16
0
def draw():
    global smallBall, bigBall
    p5.background(0)
    MousePos = p5.Vector(mouse_x, mouse_y)
    smallBall.pos = MousePos
    smallBall.collision(bigBall)
    print(abs(smallBall.relativePos(bigBall)))
    smallBall.show()
    bigBall.show()
    p5.stroke(255, 0, 0)
    p5.line((smallBall.pos), (bigBall.pos))
Exemplo n.º 17
0
 def show(self):
     if self.trail:
         self.xlist.append(self.pos.x)
         self.ylist.append(self.pos.y)
         p5.stroke(255, 255, 30)
         numberfromlast = 1000
         numberfromlast += 1
         for i in range(len(self.xlist[-numberfromlast:])):
             p5.point(self.xlist[-numberfromlast:][i],
                      self.ylist[-numberfromlast:][i])
     p5.stroke(0)
     p5.circle((self.pos.x, self.pos.y), self.d, mode="CENTER")
Exemplo n.º 18
0
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)
                p5.stroke(0)
            else:
                r, g, b = [int(c) for c in eval(fill)]
                p5.fill(r, g, b)
                p5.stroke(r, g, b)
            p5.rect(((i * w_scale) + res, j * h_scale), w_scale, h_scale)
Exemplo n.º 19
0
 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")
Exemplo n.º 20
0
def draw():
    global xscl, yscl
    p.background(255)
    p.translate(width / 2, height / 2)
    grid(xscl, yscl)
    p.stroke_weight(2)
    p.stroke(0)
    newmatrix = transpose(multmatrix(transformation_matrix,
                                     transpose(fmatrix)))
    graphPoints(fmatrix)
    p.stroke(255, 0, 0)
    graphPoints(newmatrix)
Exemplo n.º 21
0
 def display(self):
     stroke(150, 150)
     for row in range(self.number_of_rows):
         for column in range(self.number_of_columns):
             origin = [column * self.resolution, row * self.resolution]
             vector_x = copy.copy(self.field[row][column].x)
             vector_y = copy.copy(self.field[row][column].y)
             vector_x *= 10
             vector_y *= 10
             with push_matrix():
                 translate(self.resolution / 2, self.resolution / 2)
                 line((origin), (origin[0] + vector_x, origin[1] + vector_y))
                 reset_matrix()
Exemplo n.º 22
0
def draw():
    background(250)
    global point_a
    global point_b
    stroke(0)
    mouse = Vector(mouse_x, mouse_y)

    line(point_a, mouse)
    line(point_a, point_b)

    norm = scalar_projection(mouse, point_a, point_b)
    fill(255, 0, 0)
    ellipse((norm.x, norm.y), 10, 10)
Exemplo n.º 23
0
def draw():
    p.background(255)
    p.translate(width/2, height/2)
    points = []
    t = 0
    while t < 1000:
        points.append(harmonograph(t))
        t += 0.01
    for i, s in enumerate(points):
        p.stroke_weight(0.01)
        p.stroke(255, 0, 0)
        if i < len(points)-1:
            p.line((s[0], s[1]), (points[i+1][0], points[i+1][1]))
Exemplo n.º 24
0
def setup():
    # isimler adlı değikeni düzenleyebilmek için global
    global isimler

    # Pencere boyutu ayarla
    p5.size(1920, 1080)
    # isimler listesini al
    isimler = isimleri_al()

    # çizgi rengi belirle
    p5.stroke(p5.Color(41, 255, 41, 41))
    # çizgi kalınlığı belirle
    p5.stroke_weight(3)
Exemplo n.º 25
0
def draw():
    p5.background(0)
    p5.stroke(255)
    p5.no_fill()
    p5.translate(width / 2, height / 2)
    p5.rotate_x(3.41459 / 3)
    p5.translate(-w / 2, -h / 2)
    for y in range(rows):
        p5.begin_shape("TRIANGLE_STRIP")
        for x in range(cols):
            p5.vertex(x * scl, y * scl, randint(-100, 100))
            p5.vertex(x * scl, (y + 1) * scl, randint(-100, 100))
        p5.end_shape()
Exemplo n.º 26
0
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)
Exemplo n.º 27
0
 def display(self):
     stroke(255)
     fill(255)
     theta = self.velocity.angle
     with push_matrix():
         translate(self.location.x, self.location.y)
         rotate_z(theta + PI / 2)
         triangle(
             (0, -self.mass / 2),
             (-self.mass / 4, self.mass / 2),
             (self.mass / 4, self.mass / 2),
         )
     fill(0, 255, 0)
     circle((self.location.x, self.location.y), 5)
Exemplo n.º 28
0
def draw():
    p5.background(0)
    p5.stroke(255)
    p5.stroke_weight(strokeWeight)
    if showGrid:
        for x in range(int(gridW / gridScl) + 1):
            x += gridOffsetX / gridScl
            p5.line((x * gridScl, gridOffsetY),
                    (x * gridScl, gridOffsetY + gridH))

        for y in range(int(gridH / gridScl) + 1):
            y += gridOffsetY / gridScl
            p5.line((gridOffsetX, y * gridScl),
                    (gridOffsetX + gridW, y * gridScl))
Exemplo n.º 29
0
def draw():
    p.background(0)
    p.translate(width / 2, height / 2)
    # grid(xscl, yscl)

    rot = p.remap(mouse_x, (0, width), (0, p.TWO_PI))
    tilt = p.remap(mouse_y, (0, height), (0, p.TWO_PI))
    rot_matrix = rottilt(rot, tilt)

    newmatrix = multmatrix(fmatrix, rot_matrix)

    p.no_fill()
    p.stroke_weight(2)
    p.stroke(255, 0, 0)
    graphPoints2(newmatrix, edges)
Exemplo n.º 30
0
 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))