コード例 #1
0
def za_8():
    krogi = []
    for i in range(30):
        krog = risar.krog(
            randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
            risar.barva(randint(0, 150), randint(0, 150), randint(0, 150)), 3)
        krogi.append([krog, 2 * random() + 3, 2 * random() + 3])
    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)
    for i in range(1000):
        if not risar.klik:
            checkx, checky = risar.miska
            miska.setPos(checkx, checky)
        for n in range(len(krogi)):
            item, new_x, new_y = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if checkx-33 < item.x() < checkx+33 \
                    and checky-33 < item.y() < checky+33 and risar.klik:
                exit()
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
            if not (15 < item.y() < risar.maxY - 15):
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
                krogi[n][2] = -new_y

        risar.cakaj(0.02)
コード例 #2
0
def narisi_povezave(kraji, enosmerne=False):
    koord = koordict(kraji)
    pov = povezave(5, kraji)
    if not enosmerne:
        pov = dvosmerno(pov)
    for kraj, sosedi in pov.items():
        for sosed in sosedi:
            x1, y1 = koord[kraj]
            x2, y2 = koord[sosed]
            if enosmerne:
                x2 = .6 * x1 + .4 * x2
                y2 = .6 * y1 + .4 * y2
            risar.crta(tx(x1), ty(y1), tx(x2), ty(y2), barva=risar.barva(48, 48, 48), sirina=4)
            risar.crta(tx(x1), ty(y1), tx(x2), ty(y2), barva=risar.barva(96, 96, 96), sirina=1)
コード例 #3
0
def za_8():
    '''
    Draws 30 circles at random positions, moves the around. Draws an extra circle, around mouse coordinates.
    Mouse circle follows mouse until first left click. After the click circle stops, program terminates when first
    circle touches mouse circle.
    Speed of movement is 5, circles bounce upon hitting edge.
    Calls create_circles, to create actual objects.
    :return:
    '''
    krogi = create_circles(30)
    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    while True:
        if not risar.klik:
            checkx, checky = risar.miska
            miska.setPos(checkx, checky)
        for n in range(len(krogi)):
            item, new_x, new_y, *s = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if checkx-33 < item.x() < checkx+33 \
                    and checky-33 < item.y() < checky+33 and risar.klik:
                     exit()
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)
コード例 #4
0
def create_circles(stevilo):
    krogi = []
    for i in range(stevilo):
        krog = risar.krog(
            randint(30, risar.maxX - 30), randint(30, risar.maxY - 30), 10,
            risar.barva(randint(0, 150), randint(0, 150), randint(0, 150)), 3)
        krogi.append([krog, 2 * random() + 3, 2 * random() + 3, 0, 0, False])
    return krogi
コード例 #5
0
def naloga9_razsiri():
    oznake = naloga6_povezave(False, True)
    zacetek = {"Ljubljana", "Lenart", "Žužemberk"}
    razsirjen = razsiri(zacetek, Test09.povezave5)
    for kraj, oznaka in oznake.items():
        if kraj in zacetek:
            barva = risar.rumena
        elif kraj in razsirjen:
            barva = risar.bela
        else:
            barva = risar.barva(48, 48, 48)
        oznaka.setDefaultTextColor(barva)
    risar.stoj()
コード例 #6
0
def za_6():
    krog = risar.krog(
        randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
        risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)), 3)
    x, y = 2 * random() + 3, 2 * random() + 3
    t = time.time()
    for i in range(1000):
        if time.time() - t > 20:
            exit()
        krog.setPos(krog.x() + x, krog.y() + y)
        if not (15 < krog.x() < risar.maxX - 15):
            x = -x
        if not (15 < krog.y() < risar.maxY - 15):
            y = -y
        risar.cakaj(0.02)
コード例 #7
0
def create_circles(stevilo):
    '''
    Creates a list for each object risar.krog with random coordinates, random radius, random color and thickness of 5.
    Values stored in list are: risar.krog object, horizontal speed, vertical speed, counter, explosion start time
    and explotion status bool.

    New speed is calculated using pythagorean theorem.
    Function returns a list of lists if there is more than 1 circle created otherwise it returns a single list with
    above values.
    :param stevilo:
    :return:
    '''
    krogi = []
    for i in range(stevilo):
        krog = risar.krog(randint(30, risar.maxX - 30), randint(30, risar.maxY - 30), 10,
                          risar.barva(randint(30, 240), randint(30, 240), randint(30, 240)), 5)
        x = choice([-4, -3, -2, -1, 1, 2, 3, 4])
        y = math.sqrt((5**2)-(x**2))
        krogi.append([krog, x, y, 0, 0, False])
        print(math.sqrt(x**2 + y**2))
    return krogi if len(krogi)>1 else krogi[0]
コード例 #8
0
def za_7():
    krogi = []
    for i in range(30):
        krog = risar.krog(
            randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
            risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)), 3)
        krogi.append([krog, 2 * random() + 3, 2 * random() + 3])
    t = time.time()
    for i in range(1000):

        for i in range(1000):
            if time.time() - t > 20:
                exit()
        for n in range(len(krogi)):
            item, new_x, new_y = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
            if not (15 < item.y() < risar.maxY - 15):
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
                krogi[n][2] = -new_y

        risar.cakaj(0.02)
コード例 #9
0
def za_10():
    '''
    Repeats the call of function za_10_game() for each element in pravila, if enough circles have exploded it continues,
    otherwise it repeats the loop. Program terminates when all levels have been completed. It also changes the color
    of the background for each iteration.

    :return:
    '''
    pravila = [(1, 5), (2, 8), (5, 10), (8, 16), (12, 20), (16, 24), (20, 28), (25, 30), (28, 30), (30, 30)]
    i = 0
    while i < len(pravila):
        potrebnih, vseh = pravila[i]
        risar.klik = False
        QMessageBox.information(None, "Nivo {}".format(pravila.index((potrebnih, vseh)) + 1),
                                "Zadeni {} od {} zog.".format(potrebnih, vseh))
        rezultat = za_10_game(vseh)
        if potrebnih <= rezultat:

            i += 1
        else:
            QMessageBox.information(None, "Nivo {}".format(pravila.index((potrebnih, vseh)) + 1),
                                    "Zadeli ste {} od {} zog. Poskusite ponovno!".format(rezultat, vseh))
        risar.pobrisi()
        risar.barvaOzadja(risar.barva(randint(0, 100), randint(0, 100), randint(0, 100)))
コード例 #10
0
import risar
from random import random, randint
from time import time
from math import sqrt
risar.obnavljaj = True

cas = time()
krogi = []
kx = []
ky = []
mx, my = risar.miska
speed = 5
miskaKrog = risar.krog(mx, my, 30, sirina=5)

for i in range(30):
    barva = risar.barva(randint(0, 255), randint(0, 255), randint(0, 255))
    pos = risar.nakljucne_koordinate()
    if pos[0] < risar.maxX or pos[1] < risar.maxY:
        pos = risar.nakljucne_koordinate()
    else:
        break
    krogi.append((risar.krog(pos[0], pos[1], 10, barva, sirina=2)))
    kx.append(randint(-5, 5))
    ky.append(sqrt(speed**2 - kx[i]**2))

while True:

    if risar.levo:
        mx, my = risar.miska
        cas = time()
コード例 #11
0
def za_10_game(krogov):
    st = time.clock()

    krogi = create_circles(krogov)

    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    miska_start = 0
    miska_klik = False
    stevec = 0
    stop_koordinate = {"miska": (risar.miska[0], risar.miska[1])}
    for s in range(1000):
        if not risar.klik:
            stop_koordinate["miska"] = (risar.miska[0], risar.miska[1])
            miska.setPos(risar.miska[0], risar.miska[1])

        for n in range(len(krogi)):
            item, new_x, new_y, count, startime, status = krogi[n]
            if time.time() - miska_start >= 4 and miska_klik:
                miska.hide()
                miska_klik = False
                del stop_koordinate["miska"]
                if len(stop_koordinate) == 0:
                    return stevec
            if startime != 0 and time.time() - krogi[n][4] >= 4:
                item.hide()
                krogi[n][4] = 0
                del stop_koordinate[item]
                if len(stop_koordinate) == 0:
                    return stevec
                continue

            elif status == True:
                continue
            item.setPos(item.x() + new_x, item.y() + new_y)
            if risar.klik and miska_start == 0:
                pobarvaj(miska, 150)
                '''color = miska.pen().color().lighter()
                color.setAlpha(150)
                miska.setBrush(color)'''
                miska_start = time.time()
                miska_klik = True
            for x, y in stop_koordinate.values():
                if x - 35.0 < item.x() < x + 35.0 and y - 35.0 < item.y(
                ) < y + 33.0 and risar.klik:
                    item.setRect(-30, -30, 60, 60)
                    '''color = item.pen().color().lighter()
                        color.setAlpha(randint(120, 180))
                        item.setBrush(color)'''
                    pobarvaj(item, randint(120, 180))
                    stop_koordinate[item] = (item.x(), item.y())
                    krogi[n][4] = time.time()

                    krogi[n][5] = True
                    stevec += 1
                    break

            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)
        if time.clock() - st > 20:
            break
    return stevec
コード例 #12
0
def za_10_game(krogov):
    '''
    Draws x circles - krogov - at random positions, moves them around. Draws an extra circle, around mouse coordinates.
    Mouse circle follows mouse until first left click. After the click mouse circle stops, each circle that touches
    that circle explodes, thus creating another explosion node. Each circle that touches an explosion node, explodes
    as well. Program ends when there is no more exploded circles on canvas or time runs out. It display how many circles
    have exploded and terminates.
    Speed of movement is 5, circles bounce upon hitting edge.
    Explotion time is 4 seconds. Runout time is 20 seconds.
    Calls create_circles, to create actual objects.
    :return:
    '''

    krogi = create_circles(krogov)

    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    miska_start = 0
    miska_klik = False
    stevec = 0
    stop_koordinate = {"miska": (risar.miska[0], risar.miska[1])}
    while True:
        if not risar.klik:
            stop_koordinate["miska"] = (risar.miska[0], risar.miska[1])
            miska.setPos(risar.miska[0], risar.miska[1])

        for n in range(len(krogi)):
            item, new_x, new_y, count, startime, status = krogi[n]
            if time.time() - miska_start >= 4 and miska_klik:
                miska.hide()
                miska_klik = False
                del stop_koordinate["miska"]
                if len(stop_koordinate) == 0:
                    return stevec
            if startime != 0 and time.time() - krogi[n][4] >= 4:
                item.hide()
                krogi[n][4] = 0
                del stop_koordinate[item]
                if len(stop_koordinate) == 0:
                    return stevec
                continue
            elif status == True:
                continue
            item.setPos(item.x() + new_x, item.y() + new_y)
            if risar.klik and miska_start == 0:
                pobarvaj(miska, 200)
                miska_start = time.time()
                miska_klik = True
            for x, y in stop_koordinate.values():
                if x - 35.0 < item.x() < x + 35.0 and y - 35.0 < item.y() < y + 33.0 and risar.klik:
                    item.setRect(-30, -30, 60, 60)
                    pobarvaj(item, randint(120, 180))
                    stop_koordinate[item] = (item.x(), item.y())
                    krogi[n][4] = time.time()
                    krogi[n][5] = True
                    stevec += 1
                    break
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)