Esempio n. 1
0
 def __init__(self, logf, enable=True, silent=False, overwrite=False):
     self.logfile = logf
     self.numat = 0
     self.totalnum = 100
     self.stime = timer.getTime()
     self.lastnum = self.numat
     self.enabled = enable
     self.silent  = silent
     if enable and (not os.path.isfile(logf) or overwrite):
         fout = open(logf,'w')
         fout.close()
Esempio n. 2
0
 def getTime(self):
     return timer.getTime()
    if transac_status =="yes":
        print("How much money do you want to transfer?")
        amount = input("")
        if amount.isdigit():                
            if amount == 0:
                tran_op = 1;
                print("Transaction Impossible - Amount Null")
            elif True:                                        """insert proof of work here"""
                blockchain.new_transaction(amount)
                if (blockchain.chain == []):                  """ïf blockchain is empty, create genesis block"""
                    blockchain.create_genesis_block()
                else
                    blockchain.new_block(blockchain.last_block['hash'])
                print("Transaction Validated")   
                timer.setTime(0)
                while (timer.getTime() < 30):
                    if False:                                 """insert block incoming condition here"""
                        blockchain.chain[-1] = []             """"deletes created block if it recieves another block"""
                """append block"""
            else :
                print("Transaction Impossible - Invalid User")
        else:
            tran_op = 1;
            print("Transaction Impossible - Wrong Input")
    elif transac_status =="no":
        print("Ending Transaction")
        tran_op = 1
    else:
        print("Transaction Impossible - Wrong Input")
        tran_op = 1
tran_op = 0            
    def resolveCollisions(self):
        e = 0.75              # coefficient of restitution
        minTagInterval = 3.0  # minimum time allowed between re-tagging

        now = timer.getTime()
        loopCount = 0

        while True:
            isCollision = False

            for i in self.gs.characters:
                for j in self.gs.characters:

                    if i == j:
                        continue
  
                    if not i.isColliding(j):
                        continue

                    isCollision = True

                    # We have to keep computing these in case they changed in a previous collision
                    uc = i.getVelocity()
                    mc = i.mass

                    self.t = i.normalTo(j, self.t)
                    self.n = util2D.perpendicularTo(self.t, self.n, self.nTmp)[0]

                    uct = dot(uc, self.t)
                    ucn = dot(uc, self.n)

                    mo = j.mass

                    uo = j.getVelocity()

                    uot = dot(uo, self.t)
                    uon = dot(uo, self.n)

                    k = (uct - uot)/(mc + mo)
                    vct = uct - (1 + e) * mo * k
                    vot = uot + (1 + e) * mc * k

                    i.setVelocity(vec.scale(self.t, vct, self.vt) + vec.scale(self.n, ucn, self.vn))

                    j.setVelocity(vec.scale(self.t, vot, self.vt) + vec.scale(self.n, uon, self.vn))

                    # TODO: limit re-tagging restriction to previously tagged character only
                    if j.tagged and minTagInterval < now - self.gs.lastTagTime:
                        self.gs.setTagged(i, j, now)
                    elif i.tagged and minTagInterval < now - self.gs.lastTagTime:
                        self.gs.setTagged(j, i, now)

                for j in self.gs.nonCharacterObstacles:
                    if not i.isColliding(j):
                        continue

                    isCollision = True

                    uc = i.getVelocity()

                    self.t = i.normalTo(j, self.t)
                    self.n = util2D.perpendicularTo(self.t, self.n, self.nTmp)[0]

                    uct = dot(uc, self.t)
                    ucn = dot(uc, self.n)

                    vct = -e * uct
                    i.setVelocity(vec.scale(self.t, vct, self.vt) + vec.scale(self.n, ucn, self.vn))

            if not isCollision:
                break

            assert loopCount < 1000, "something probably went wrong"
            loopCount += 1
Esempio n. 5
0
 def render(self):
     if self.flash and math.fmod(timer.getTime(), 2.0) < 1.0:
         gui.setColor(self.flashColor)
     else:
         gui.setColor(self.foreground)
Esempio n. 6
0
 def handleTime(self):
     self.write(timer.getTime())
Esempio n. 7
0
        for y in range(gridH):
            tiles[x].append(Tile(x, y))


safeTiles = [(x, y) for x in range(gridW) for y in range(gridH)]
tiles = []
timer = timer.Timer()
genTiles()

numFlags = 0

resetButton = Button((0, 0, topMenuHeight, topMenuHeight),
                     reset,
                     sprite=sprites[12])
timerUI = SimpleText((topMenuHeight, 0, topMenuHeight, topMenuHeight),
                     "%.3f" % timer.getTime(), 60)
flagCountUI = SimpleText((topMenuHeight * 6, 0, topMenuHeight, topMenuHeight),
                         "%d" % (numMines - numFlags), 60, RED)

firstClick = True  # first discovery generates the field
mouseHold = False
run = True

while run:
    screen.fill(BEIGE)
    mouseX, mouseY = mouse.get_pos()
    hoveredTile = getHovered()

    resetButton.draw()
    timer.update()
    timerUI.update("%.3f" % timer.getTime())
Esempio n. 8
0
    def resolveCollisions(self):
        e = 0.75              # coefficient of restitution
        minTagInterval = 3.0  # minimum time allowed between re-tagging

        now = timer.getTime()
        loopCount = 0

        while True:
            isCollision = False

            for i in self.gs.characters:
                for j in self.gs.characters:

                    if i == j:
                        continue
  
                    if not i.isColliding(j):
                        continue

                    isCollision = True

                    # We have to keep computing these in case they changed in a previous collision
                    uc = i.getVelocity()
                    mc = i.mass

                    self.t = i.normalTo(j, self.t)
                    self.n = util2D.perpendicularTo(self.t, self.n, self.nTmp)[0]

                    uct = dot(uc, self.t)
                    ucn = dot(uc, self.n)

                    mo = j.mass

                    uo = j.getVelocity()

                    uot = dot(uo, self.t)
                    uon = dot(uo, self.n)

                    k = (uct - uot)/(mc + mo)
                    vct = uct - (1 + e) * mo * k
                    vot = uot + (1 + e) * mc * k

                    i.setVelocity(vec.scale(self.t, vct, self.vt) + vec.scale(self.n, ucn, self.vn))

                    j.setVelocity(vec.scale(self.t, vot, self.vt) + vec.scale(self.n, uon, self.vn))

                    # TODO: limit re-tagging restriction to previously tagged character only
                    if j.tagged and minTagInterval < now - self.gs.lastTagTime:
                        self.gs.setTagged(i, j, now)
                    elif i.tagged and minTagInterval < now - self.gs.lastTagTime:
                        self.gs.setTagged(j, i, now)

                for j in self.gs.nonCharacterObstacles:
                    if not i.isColliding(j):
                        continue

                    isCollision = True

                    uc = i.getVelocity()

                    self.t = i.normalTo(j, self.t)
                    self.n = util2D.perpendicularTo(self.t, self.n, self.nTmp)[0]

                    uct = dot(uc, self.t)
                    ucn = dot(uc, self.n)

                    vct = -e * uct
                    i.setVelocity(vec.scale(self.t, vct, self.vt) + vec.scale(self.n, ucn, self.vn))

            if not isCollision:
                break

            assert loopCount < 1000, "something probably went wrong"
            loopCount += 1
Esempio n. 9
0
def printTime(all_queues):
    for queue in all_queues:
        print('Fila ' + queue.getId(), end=' ')
        newQ = queue.getStates()
        print(newQ.items())
    print('TEMPO DA SIMULACAO = ' + str(getTime()) + ' segundos')
Esempio n. 10
0
    def addCharacter(self, c):
        if not self.tagged:
            self.setTagged(c, None, timer.getTime())

        self.characters.append(c)
 def render(self):
     if self.flash and math.fmod(timer.getTime(), 2.0) < 1.0:
         gui.setColor(self.flashColor)
     else:
         gui.setColor(self.foreground)
 def getTime(self):
     return timer.getTime()
    def addCharacter(self, c):
        if not self.tagged:
           self.setTagged(c, None, timer.getTime())

        self.characters.append(c)
Esempio n. 14
0
 def writeElapsedTime(self):
     t = timer.getTime()
     self.write('Elapsed: %s' % (self.__fs__(t-self.stime)))