示例#1
0
def open_website(link):
    wpm = 250
    keyboard.send("f6")
    time.sleep(0.1)
    typist = Typist(wpm)
    typist.insert_characters(link)
    sleep_time = (len(link) / (wpm * 5)) * 60 + 1.5
    time.sleep(sleep_time)
    keyboard.send("enter")
示例#2
0
def race_bot():
    # wait for the user to open the typeracer website
    time.sleep(3)

    successful_types = 0
    unsuccessful_types = 0

    while True:
        open_website("https://typeracer.com/")
        time.sleep(5)  # wait for it to load

        enter_race()

        if not search_for_yellow_light():
            continue
        # premature quote grab
        premature_text, _ = get_typing_content()
        typist = Typist(config.wpm, config.accuracy, config.error_deviation)
        time.sleep(3.4)
        typist.insert_characters(premature_text[0:25])
        time.sleep(0.5)
        # take a screenshot and save it
        text, bounding_box = get_typing_content()
        text_continuation = find_text_continuation(premature_text, text, 25)
        typist.insert_characters(text_continuation)
        text = premature_text[0:25] + text_continuation
        textbox_location = (config.mouse_width_typebox, bounding_box[3] +
                            config.mouse_offset_of_change_display_typebox)
        while not typist.is_finished():
            typo_flag = wait_for_text_to_be_written(3, textbox_location)
            if typist.is_finished():
                typo_flag = False
                break
            if typo_flag:
                break
        typist.stop_typing()

        if typo_flag:
            append = "typo"
            unsuccessful_types += 1
        else:
            append = "correct"
            successful_types += 1

        with open("quotes_log_" + append + ".txt", 'a') as f:
            f.write(text + "\n")

        time.sleep(0.3)
        print("Sucessful: {} | Unsuccessful: {}".format(
            successful_types, unsuccessful_types))
示例#3
0
    def activateTypewriter(self):
        """
        Once the intro is complete, enable interactivity
        """

        self.placeItems()

        # re-enable mouse
        mat = Mat4(self.base.camera.getMat())
        mat.invertInPlace()
        self.base.mouseInterfaceNode.setMat(mat)
        self.base.enableMouse()

        self.typist = Typist(self.base, self.typewriterNP, self.underDeskClip,
                             self.sounds)
        self.typist.start()
示例#4
0
def main():
    """ The main execution block """
    chars = helpers.make_vocabulary(
        [string.ascii_lowercase, string.digits, string.punctuation])
    keep_typing = True
    while keep_typing:
        name = helpers.login()
        user = Typist(name, chars)
        keep_typing = menu(user)
示例#5
0
    def activateTypewriter(self):
        """
        Once the intro is complete, enable interactivity
        """

        self.placeItems()

        # re-enable mouse
        mat=Mat4(self.base.camera.getMat())
        mat.invertInPlace()
        self.base.mouseInterfaceNode.setMat(mat)
        self.base.enableMouse()

        self.typist = Typist(self.base, self.typewriterNP, self.underDeskClip, self.sounds)
        self.typist.start()
示例#6
0
class World(object):

    def __init__(self, base, USE_RP):
        self.base = base
        """ direct.showbase.ShowBase """

        if not USE_RP:
            alight = AmbientLight('alight')
            alnp = self.base.render.attachNewNode(alight)
            alight.setColor((0.2, 0.2, 0.2, 1))
            self.base.render.setLight(alnp)

            # Put lighting on the main scene

            dlight = DirectionalLight('dlight')
            dlnp = self.base.render.attachNewNode(dlight)
            dlnp.setPos(0, 5, 5)
            dlight.setColor((0.8, 0.8, 0.5, 1))
            dlnp.setHpr(0, 60, 0)
            self.base.render.setLight(dlnp)

            plight = PointLight('plight')
            plnp = self.base.render.attachNewNode(plight)
            plnp.setPos(0, -50, 50)
            plnp.setHpr(0, 60, 0)
            self.base.render.setLight(plnp)

        self.sounds = {}

    def start(self, skipIntro):
        self.skipIntro = skipIntro

        self.base.skybox = None
        self.typewriterNP = None
        self.deskNP = None
        self.base.taskMgr.doMethodLater(0.2, self.loadup, 'loadup')

    def loadup(self, task):
        # get in front
        self.base.camera.setPos(0, 0, 0)

        # trusty typewriter
        self.typewriterNP = self.base.loader.loadModel('typewriter')

        # the desk
        self.deskNP = self.base.loader.loadModel('desk')

        # skybox
        skyb = skybox.NetmapSkybox(self.base, 'iceRiver', '', '.jpg')
        self.sky = skyb.create(self.base.cam)

        # sounds
        self.sounds['bell'] = self.base.loader.loadSfx('bell.wav')
        self.sounds['advance'] = self.base.loader.loadSfx('advance.wav')
        self.sounds['pullback'] = self.base.loader.loadSfx('pullback.wav')
        self.sounds['scroll'] = self.base.loader.loadSfx('scroll.wav')
        self.sounds['type1'] = self.base.loader.loadSfx('type1.wav')
        self.sounds['type2'] = self.base.loader.loadSfx('type2.wav')
        self.sounds['type3'] = self.base.loader.loadSfx('type3.wav')

        self.base.sfxManagerList[0].setVolume(0.5)

        if not self.skipIntro:
            self.sky.setAttrib(TransparencyAttrib.make(TransparencyAttrib.M_alpha))
            self.sky.setAlphaScale(0, 1)

            alphaInterval = LerpFunc(lambda a: self.sky.setAlphaScale(a, 1),
                                     duration=1,
                                     fromData=0,
                                     toData=1,
                                     blendType='easeIn')

            seq = Sequence(alphaInterval)
            seq.setDoneEvent('createWorld')

            seq.start()

        else:
            self.base.messenger.send('createWorld')

    def createWorld(self, task=None):
        self.sky.clearAttrib(TransparencyAttrib)

        self.deskNP.reparentTo(self.base.render)
        self.deskNP.setScale(7.5)
        self.deskNP.setPos(0, -5, -6.5)

        # make a box that clips content under the desk (e.g. the paper)
        bb = self.deskNP.getTightBounds()
        sz = (bb[1]-bb[0]) * 0.8

        self.underDeskClip = self.base.loader.loadModel('box')
        self.underDeskClip.setScale(sz)
        self.underDeskClip.reparentTo(self.base.render)
        self.underDeskClip.setPos(-sz.x/2, -sz.y*1.1, -sz.z*0.73)

        if False:
            # --> nope, this actually hides everything the camera might see

            self.newBin = CullBinManager.getGlobalPtr().addBin('foo', CullBinManager.BT_state_sorted, -50)
            # make the box obscure geometry "inside" it
            self.underDeskClip.setAttrib(ColorWriteAttrib.make(False))
            self.underDeskClip.setDepthWrite(True)
            self.underDeskClip.setBin('foo', -50)

        else:
            bb = self.underDeskClip.getTightBounds()
            self.underDeskClip.removeNode()


        self.typewriterNP.reparentTo(self.base.render)

        self.typewriterNP.setHpr(0, 0, 0)
        self.typewriterNP.setScale(5)

        self.base.camera.setPos(0, -25, 5)
        self.cameraTarget = Point3(0, -9.5, 7.5)
        #self.cameraTarget = Point3(0, -25, 2.5)
        self.cameraHprTarget = Point3(0, -19.5, 0)
        self.typewriterTarget = Point3(0, -2.5, 2.666)
        self.typewriterStart = Point3(0, -5, 10)

        if not self.skipIntro:
            self.animateArrival()
        else:
            self.activateTypewriter()

    def animateArrival(self):
        """
        Cheesy animation introducing viewer to the DESK and TYPEWRITER
        :return:
        """
        camMoveInterval = LerpPosInterval(self.base.camera,  2, self.cameraTarget)
        camHprInterval = LerpHprInterval(self.base.camera,  2, self.cameraHprTarget)

        dropKeyboardInterval = LerpPosInterval(self.typewriterNP, 2,
                                               self.typewriterTarget,
                                               startPos=self.typewriterStart,
                                               blendType='easeOut')

        sequence = Parallel(camMoveInterval, camHprInterval, dropKeyboardInterval)

        sequence.setDoneEvent('arrivalFinished')

        def arrivalFinished():
            self.activateTypewriter()
            self.base.ignore('enter')
            self.base.ignore('esc')

        self.base.accept('arrivalFinished', arrivalFinished)

        sequence.start()

        # for the impatient...
        def cancelStartupSequence():
            sequence.finish()

        self.base.acceptOnce('enter', cancelStartupSequence)
        self.base.acceptOnce('esc', cancelStartupSequence)


    def activateTypewriter(self):
        """
        Once the intro is complete, enable interactivity
        """

        self.placeItems()

        # re-enable mouse
        mat=Mat4(self.base.camera.getMat())
        mat.invertInPlace()
        self.base.mouseInterfaceNode.setMat(mat)
        self.base.enableMouse()

        self.typist = Typist(self.base, self.typewriterNP, self.underDeskClip, self.sounds)
        self.typist.start()

    def placeItems(self):
        """
        Place items in world after intro animation (should be a no-op, but to be sure...)
        """
        self.base.camera.setHpr(self.cameraHprTarget)
        self.base.camera.setPos(self.cameraTarget)
        self.typewriterNP.setPos(self.typewriterTarget)
示例#7
0
class World(object):
    def __init__(self, base, USE_RP):
        self.base = base
        """ direct.showbase.ShowBase """

        if not USE_RP:
            alight = AmbientLight('alight')
            alnp = self.base.render.attachNewNode(alight)
            alight.setColor((0.2, 0.2, 0.2, 1))
            self.base.render.setLight(alnp)

            # Put lighting on the main scene

            dlight = DirectionalLight('dlight')
            dlnp = self.base.render.attachNewNode(dlight)
            dlnp.setPos(0, 5, 5)
            dlight.setColor((0.8, 0.8, 0.5, 1))
            dlnp.setHpr(0, 60, 0)
            self.base.render.setLight(dlnp)

            plight = PointLight('plight')
            plnp = self.base.render.attachNewNode(plight)
            plnp.setPos(0, -50, 50)
            plnp.setHpr(0, 60, 0)
            self.base.render.setLight(plnp)

        self.sounds = {}

    def start(self, skipIntro):
        self.skipIntro = skipIntro

        self.base.skybox = None
        self.typewriterNP = None
        self.deskNP = None
        self.base.taskMgr.doMethodLater(0.2, self.loadup, 'loadup')

    def loadup(self, task):
        # get in front
        self.base.camera.setPos(0, 0, 0)

        # trusty typewriter
        self.typewriterNP = self.base.loader.loadModel('typewriter')

        # the desk
        self.deskNP = self.base.loader.loadModel('desk')

        # skybox
        skyb = skybox.NetmapSkybox(self.base, 'iceRiver', '', '.jpg')
        self.sky = skyb.create(self.base.cam)

        # sounds
        self.sounds['bell'] = self.base.loader.loadSfx('bell.wav')
        self.sounds['advance'] = self.base.loader.loadSfx('advance.wav')
        self.sounds['pullback'] = self.base.loader.loadSfx('pullback.wav')
        self.sounds['scroll'] = self.base.loader.loadSfx('scroll.wav')
        self.sounds['type1'] = self.base.loader.loadSfx('type1.wav')
        self.sounds['type2'] = self.base.loader.loadSfx('type2.wav')
        self.sounds['type3'] = self.base.loader.loadSfx('type3.wav')

        self.base.sfxManagerList[0].setVolume(0.5)

        if not self.skipIntro:
            self.sky.setAttrib(
                TransparencyAttrib.make(TransparencyAttrib.M_alpha))
            self.sky.setAlphaScale(0, 1)

            alphaInterval = LerpFunc(lambda a: self.sky.setAlphaScale(a, 1),
                                     duration=1,
                                     fromData=0,
                                     toData=1,
                                     blendType='easeIn')

            seq = Sequence(alphaInterval)
            seq.setDoneEvent('createWorld')

            seq.start()

        else:
            self.base.messenger.send('createWorld')

    def createWorld(self, task=None):
        self.sky.clearAttrib(TransparencyAttrib)

        self.deskNP.reparentTo(self.base.render)
        self.deskNP.setScale(7.5)
        self.deskNP.setPos(0, -5, -6.5)

        # make a box that clips content under the desk (e.g. the paper)
        bb = self.deskNP.getTightBounds()
        sz = (bb[1] - bb[0]) * 0.8

        self.underDeskClip = self.base.loader.loadModel('box')
        self.underDeskClip.setScale(sz)
        self.underDeskClip.reparentTo(self.base.render)
        self.underDeskClip.setPos(-sz.x / 2, -sz.y * 1.1, -sz.z * 0.73)

        if False:
            # --> nope, this actually hides everything the camera might see

            self.newBin = CullBinManager.getGlobalPtr().addBin(
                'foo', CullBinManager.BT_state_sorted, -50)
            # make the box obscure geometry "inside" it
            self.underDeskClip.setAttrib(ColorWriteAttrib.make(False))
            self.underDeskClip.setDepthWrite(True)
            self.underDeskClip.setBin('foo', -50)

        else:
            bb = self.underDeskClip.getTightBounds()
            self.underDeskClip.removeNode()

        self.typewriterNP.reparentTo(self.base.render)

        self.typewriterNP.setHpr(0, 0, 0)
        self.typewriterNP.setScale(5)

        self.base.camera.setPos(0, -25, 5)
        self.cameraTarget = Point3(0, -9.5, 7.5)
        #self.cameraTarget = Point3(0, -25, 2.5)
        self.cameraHprTarget = Point3(0, -19.5, 0)
        self.typewriterTarget = Point3(0, -2.5, 2.666)
        self.typewriterStart = Point3(0, -5, 10)

        if not self.skipIntro:
            self.animateArrival()
        else:
            self.activateTypewriter()

    def animateArrival(self):
        """
        Cheesy animation introducing viewer to the DESK and TYPEWRITER
        :return:
        """
        camMoveInterval = LerpPosInterval(self.base.camera, 2,
                                          self.cameraTarget)
        camHprInterval = LerpHprInterval(self.base.camera, 2,
                                         self.cameraHprTarget)

        dropKeyboardInterval = LerpPosInterval(self.typewriterNP,
                                               2,
                                               self.typewriterTarget,
                                               startPos=self.typewriterStart,
                                               blendType='easeOut')

        sequence = Parallel(camMoveInterval, camHprInterval,
                            dropKeyboardInterval)

        sequence.setDoneEvent('arrivalFinished')

        def arrivalFinished():
            self.activateTypewriter()
            self.base.ignore('enter')
            self.base.ignore('esc')

        self.base.accept('arrivalFinished', arrivalFinished)

        sequence.start()

        # for the impatient...
        def cancelStartupSequence():
            sequence.finish()

        self.base.acceptOnce('enter', cancelStartupSequence)
        self.base.acceptOnce('esc', cancelStartupSequence)

    def activateTypewriter(self):
        """
        Once the intro is complete, enable interactivity
        """

        self.placeItems()

        # re-enable mouse
        mat = Mat4(self.base.camera.getMat())
        mat.invertInPlace()
        self.base.mouseInterfaceNode.setMat(mat)
        self.base.enableMouse()

        self.typist = Typist(self.base, self.typewriterNP, self.underDeskClip,
                             self.sounds)
        self.typist.start()

    def placeItems(self):
        """
        Place items in world after intro animation (should be a no-op, but to be sure...)
        """
        self.base.camera.setHpr(self.cameraHprTarget)
        self.base.camera.setPos(self.cameraTarget)
        self.typewriterNP.setPos(self.typewriterTarget)