コード例 #1
0
ファイル: vehicle.py プロジェクト: Mgallimore88/NatureOfCode
    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 """
コード例 #2
0
def draw():

    global planet, moon

    p5.fill(255)
    if not moon.finished:
        p5.background(0)
        p5.scale(1, -1)
        p5.translate(0, -height)

        moon.collide(planet)

        moon.update(planet, G)

        #planet.update(moon,G)

        p5.no_fill()
        p5.stroke(255, 60)
        #p5.circle((planet.pos.x,planet.pos.y),2*abs(moon.relpos(planet)))

    p5.fill(10, 173, 73)
    p5.stroke(0)
    planet.show()

    p5.fill(0, 0, 255)
    p5.stroke(0, 0, 255)
    moon.show()
コード例 #3
0
ファイル: polygon.py プロジェクト: rubaimushtaq/python
def draw():
    p.translate(width / 2, height / 2)
    p.begin_shape()
    for i in range(6):
        p.vertex(100 * p.cos(p.radians(60 * i)),
                 100 * p.sin(p.radians(60 * i)))
        p.rotate(p.radians(60))
    p.end_shape('CLOSE')
コード例 #4
0
ファイル: colourGrid.py プロジェクト: rubaimushtaq/python
def draw():
    p.background(0)
    p.translate(20, 20)
    for x in range(30):
        for y in range(30):
            d = p.dist((30*x, 30*y), (mouse_x, mouse_y))
            p.fill(0.5*d, 255, 255)
            p.rect((30*x, 30*y), 25, 25)
コード例 #5
0
ファイル: main.py プロジェクト: astrokod/Astro-Kod-Ders-13
def draw():
    # Arka planı siyah yap
    p5.background(0)
    # Orijini pencerenin merkezine taşı
    p5.translate(width / 2, height / 2)

    # clock fonsiyonundan gelen değerleri
    # sırasıyla h, m ve s değişkenlerine ata
    h, m, s = clock()

    # Çevre çizgisi çizme
    p5.no_stroke()

    # [0, 360) aralığında 6'şar derece aralıklarla değer oluştur
    # 0, 6, 12, ...,  342, 348, 354
    for i in range(0, 360, 6):

        # Kutupsal koordinat sisteminde
        # (r_d, i) değerini kartezyen koordinat sistemine dönüştür
        d_x, d_y = pol2car(r_d, i)

        # i değeri 30'un tam katıysa,
        if i % 30 == 0:
            # saat değerleri için nokta koyacağız
            p5.fill(255, 0, 0)
            r = 15
        else:
            # dakika/saniye değerleri için nokta koyacağız
            p5.fill(255)
            r = 10

        # Belirlenen özelliklerle hesaplanan noktada
        # bir daire çiz
        p5.circle((d_x, d_y), r)

    # Akrep kolunun ucunun konumunu hesala
    h_x, h_y = pol2car(r_h, h)
    # Akrep kolunun şekil ayarlarını yap
    p5.stroke(255)
    p5.stroke_weight(5)
    # Akrep konu çiz
    p5.line((0, 0), (h_x, h_y))

    # Yelkovan kolunun ucunun konumunu hesala
    m_x, m_y = pol2car(r_m, m)
    # Yelkovan kolunun şekil ayarlarını yap
    p5.stroke(255)
    p5.stroke_weight(3)
    # Yelkovan konu çiz
    p5.line((0, 0), (m_x, m_y))

    # Saniye kolunun ucunun konumunu hesala
    s_x, s_y = pol2car(r_s, s)
    # Saniye kolunun şekil ayarlarını yap
    p5.stroke(255, 0, 0)
    p5.stroke_weight(1)
    # Saniye konu çiz
    p5.line((0, 0), (s_x, s_y))
コード例 #6
0
def draw():
    global t
    p.background(255)
    p.translate(width/2, height/2)
    p.rotate(p.radians(t))
    for _ in range(12):
        p.rect((200, 0),50, 50)
        p.rotate(p.radians(360/12))
    t += 2
コード例 #7
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)
コード例 #8
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))
コード例 #9
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)
コード例 #10
0
def setup():
    global LeftPlanet,RightPlanet
    p5.scale(1,-1)
    p5.size(1500,700)
    p5.translate(0,-height)

    LeftPlanet=Planet(0,height/2,1,[10,0],25,trail=1)
    LeftPlanet.pos.x+=LeftPlanet.r
    RightPlanet=Planet(width,height/2,1,[-10,0],25,trail=1)
    RightPlanet.pos.x-=RightPlanet.r
コード例 #11
0
def draw():
    global t
    p.background(255)
    p.translate(width/2, height/2)
    for i in range(90):
        p.rotate(p.radians(360/90))
        with p.push_matrix():
            p.translate(200, 0)
            p.rotate(p.radians(t+2*i*360/90))
            tri(100)
        t+=0.01
コード例 #12
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))
コード例 #13
0
 def display(self):
     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()
コード例 #14
0
ファイル: mandelbrot.py プロジェクト: rubaimushtaq/python
def draw():
    p.translate(width / 2, height / 2)
    for x in arange(xmin, xmax, .01):
        for y in arange(ymin, ymax, .01):
            z = [x, y]
            c = [0.285, 0.01]
            col = julia(z, c, 100)
            if col == 100:
                p.fill(0)
            else:
                p.fill((3 * col), 255, 255)
            p.rect((x * xscl, y * yscl), 1, 1)
コード例 #15
0
ファイル: boid.py プロジェクト: IronCore864/p5boids
 def show(self):
     translate(self.x, self.y)
     angle = atan2(self.dy, self.dx)
     rotate(angle)
     # fixed sized "boid"
     triangle(
         [0, 0],
         [-10, 4],
         [-10, -4],
     )
     rotate(-angle)
     translate(-self.x, -self.y)
コード例 #16
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)
コード例 #17
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()
コード例 #18
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]))
コード例 #19
0
ファイル: vehicle.py プロジェクト: Mgallimore88/NatureOfCode
 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)
コード例 #20
0
def draw():
    global sprite
    p5.background(255)
    theta = mouse_y

    # reference shape
    sprite.draw_pointer()

    p5.fill(255, 0, 0, 128)
    #  rotate a house shape aboutits centre
    with p5.push_matrix():
        p5.translate(40, 40)
        p5.rotate(p5.radians(theta))
        sprite.draw_house()
コード例 #21
0
ファイル: matrices3D.py プロジェクト: rubaimushtaq/python
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)
コード例 #22
0
ファイル: julia.py プロジェクト: rubaimushtaq/python
def draw():
    p.translate(width / 2, height / 2)
    x = xmin
    while x < xmax:
        y = ymin
        while y < ymax:
            z = [x, y]
            c = [-0.4, 0.6]
            col = julia(z, c, 100)
            if col == 100:
                p.fill(0)
            else:
                p.fill((3 * col), 255, 255)
            p.rect((x * xscl, y * yscl), 1, 1)
            y += 0.01
        x += 0.01
コード例 #23
0
def draw():
    global t, circleList
    p.background(200)
    p.translate(width / 4, height / 2)
    p.no_fill()
    p.stroke(0)
    p.ellipse((0, 0), 2 * r1, 2 * r1)
    p.fill(255, 0, 0)
    y = r1 * p.sin(t)
    x = r1 * p.cos(t)
    circleList = [y] + circleList[:249]
    p.ellipse((x, y), r2, r2)
    p.stroke(0, 255, 0)
    p.line((x, y), (200, y))
    p.fill(0, 255, 0)
    p.ellipse((200, y), 10, 10)
    for i, c in enumerate(circleList):
        p.ellipse((200 + i, c), 15, 15)
    t += 0.1
コード例 #24
0
def setup():
    global planet, moon
    p5.scale(1, -1)
    p5.size(1500, 700)
    p5.translate(0, -height)
    planet = Planet(width / 2, height / 2, 20, [0, 0], 500, trail=0)
    moon = Planet(width / 2,
                  planet.pos.y + planet.r + 50,
                  1, [0, 0],
                  10,
                  trail=1)

    #0,1,2,5,7,7.5,7.7,7.8,7.82

    min_orbit_vx = np.sqrt(
        ((G * planet.m) / (abs(moon.initpos.y - planet.initpos.y))))
    #moon.vel.x=min_orbit_vx

    print(min_orbit_vx)
コード例 #25
0
def draw():
    global r1, r2, x1, y1, t, prop, points
    p.translate(width / 2, height / 2)
    p.background(255)
    p.no_fill()
    p.stroke(0)
    p.ellipse((x1, y1), 2 * r1, 2 * r1)
    x2 = (r1 - r2) * p.cos(t)
    y2 = (r1 - r2) * p.sin(t)
    p.ellipse((x2, y2), 2 * r2, 2 * r2)
    x3 = x2 + prop * (r2 - r3) * p.cos(-((r1 - r2) / r2) * t)
    y3 = y2 + prop * (r2 - r3) * p.sin(-((r1 - r2) / r2) * t)
    p.fill(255, 0, 0)
    p.ellipse((x3, y3), 2 * r3, 2 * r3)
    points = [[x3, y3]] + points[:2000]
    for i, d in enumerate(points):
        if i < len(points) - 1:
            p.stroke(255, 0, 0)
            p.line((d[0], d[1]), (points[i + 1][0], points[i + 1][1]))
    t += 0.1
コード例 #26
0
def draw():
    global sprite_1
    global sprite_2
    p5.background(255)
    theta = mouse_y
    # sprite_1.x = mouse_x

    # reference shape
    sprite_1.draw_pointer()

    p5.fill(255, 0, 0, 128)
    #  rotate a house shape about its centre
    with p5.push_matrix():
        p5.translate(40, 40)
        p5.rotate(p5.radians(theta))
        sprite_1.draw_house()

    p5.fill(250, 250, 0, 127)
    with p5.push_matrix():
        p5.translate(mouse_x, mouse_y)
        p5.rotate(2 * p5.PI * mouse_y / height)
        sprite_2.draw_pointer()
コード例 #27
0
def draw():
    # Arka alanı siyah yap
    p5.background(0)
    # Orijini (Yani (0, 0) noktasını) pencerenin ortasına taşı
    p5.translate(w / 2, h / 2)

    # Analog saatte, saat değerlerinin olduğu konumlara
    # kırmızı noktalar koymak için döngü
    # [0, 360) aralığında 30'ar derece açılarla değer oluştur:
    # Böylece 0, 30, 60, ..., 270, 300, 330 değerleri elde edilecek
    for i in range(0, 360, 30):
        # Her bir açı için x ve y konumlarını hesapla
        x = r * math.cos(math.radians(i))
        y = r * math.sin(math.radians(i))

        # Çizilecek nesnenin içini kırmızı renk ile doldur
        p5.fill(255, 0, 0)
        # Çizilecek nesne için çevre çizgisi çizme
        p5.no_stroke()
        # x ve y konumuna 15 piksel çapında bir daire çiz.
        p5.circle((x, y), 15)

    # Analog saatte, dakika değerlerinin olduğu konumlara
    # beyaz noktalar koymak için döngü
    # [0, 360) aralığında 6'şar derece açılarla değer oluştur:
    # Böylece 0, 6, 12, ..., 342, 348, 354 değerleri elde edilecek
    for u in range(0, 360, 6):
        # Eğer u açısı 30'a tm bölünebiliyorsa işlemi YAPMA
        if u % 30:
            # Her bir açı için x ve y konumlarını hesapla
            x = r * math.cos(math.radians(u))
            y = r * math.sin(math.radians(u))

            # Çizilecek nesnenin içini beyaz renk ile doldur
            p5.fill(255)
            # Çizilecek nesne için çevre çizgisi çizme
            p5.no_stroke()
            # x ve y konumuna 10 piksel çapında bir daire çiz.
            p5.circle((x, y), 10)
コード例 #28
0
ファイル: main.py プロジェクト: astrokod/minnettarlik
def draw():
    # sayac değikenini düzenlemek için global
    global sayac
    # Eğer ilk framede isek, arka planı siyah yap
    if sayac == 0:
        p5.background(p5.Color(0, 0, 0))

    # isimlerin sayacinci elemanını al
    isim = isimler[sayac]

    # 0, 0 noktasını ekranın sol üst köşesine taşı (resetleme)
    p5.reset_matrix()
    # 0, 0 noktasını ekranın x ekseninnde orta, y ekseninde alt tarafa taşı
    p5.translate(1920 / 2, 1080 - 50)

    # isim deki her harf için döngü başlat
    for harf in isim:
        # harfın ascii değerine bak.
        if ord(harf) % 2:
            # Çift ise pozitif yönde aci kadar dön
            p5.rotate(aci)
        else:
            # Tek ise negatif yönde aci kadar dön
            p5.rotate(-aci)

        # 0, 0'dan y yönünde uzunluk kadar br çizgi çiz
        p5.line(p5.Vector(0, 0), p5.Vector(0, -uzuluk))
        # 0, 0 noktasını çizilen çizginin son noktasına taşı
        p5.translate(0, -uzuluk)

    # Eğer sayac isimlerin uzunluğundan bir eksik ise
    if sayac == len(isimler) - 1:
        # Bitti yaz ve p5, döngüsünü durdur
        print("Bitti")
        p5.no_loop()
    else:
        # değilse, sayac'ı bir arttır
        sayac += 1
コード例 #29
0
def draw():
    global LeftPlanet,RightPlanet
    p5.scale(1,-1)
    p5.translate(0,-height)

    if not LeftPlanet.finished and not RightPlanet.finished:
        LeftPlanet.collide(RightPlanet)
        p5.stroke(255,0,0)
        LeftPlanet.update(RightPlanet,G)
        p5.stroke(0,0,255)

        RightPlanet.update(LeftPlanet,G)
        


        p5.background(0)
        
    p5.stroke(255,0,0)
    p5.fill(255,0,0)
    LeftPlanet.show()
    p5.stroke(0,0,255)
    p5.fill(0,0,255)
    RightPlanet.show()
コード例 #30
0
def draw():
    global xscl, yscl
    p.background(255)
    p.translate(width / 2, height / 2)
    grid(xscl, yscl)
    graphFunction()