Ejemplo n.º 1
0
def map(key):
    global mappedTo
    if mappedTo:
        gf.map(mappedTo)
    if key:
        gf.map(key, "randomRot.randomRot()")
    mappedTo = key
Ejemplo n.º 2
0
def map(key):
    global mappedTo
    if mappedTo:
        gf.map(mappedTo)
    if key:
        gf.map(key, "randomRot.randomRot()")
    mappedTo = key
Ejemplo n.º 3
0
def open(newGfFigure, byName):
	global gfFigure
	global figsByName
	global instructions
	gfFigure=newGfFigure
	figsByName=byName
	gf.figureOpen(gfFigure)
	gf.clear()
	sleep()
	instructions=deque()
	gf.map("<enter>", "debugPlayback.play()")
Ejemplo n.º 4
0
def randomRot(allowCameraMoving=False, printInfo=True):
    global mappedTo
    maxspeed = gf.get_speed()
    dim = gf.get_dimen()

    # Create two dimensional list of angular velocities (one for every pair of axes)
    velocities = [0]
    for i in range(1, dim + 1):
        velocities = velocities + [[0] * i]

    if allowCameraMoving:
        # Create list of camera distances (in different levels of persp. proj.) and list of their current speeds
        camPosL = [0] * (dim + 1)
        for i in range(3, dim + 1):
            camPosL[i] = gf.get_camposl(i)
        camPosLAcc = [0] * (dim + 1)

    lastTime = gf.time()
    minDelay = 1000 / gf.get_maxfps()
    while gf.sleep(
            minDelay
    ):  # Repeat till user abort; repaint and wait at least 1ms before every course
        t = gf.time()  # Time measuring to deal with different sleeping time
        if printInfo:
            gf.clear()
            # echo prints every line below the previous one, clearing is necessary
            gf.echo("--- Random rotation ---")

        # Rotate figure and write velocities to console
        for i in range(1, dim + 1):
            for j in range(1, i):
                velocities[i][j] = velocities[i][j] + (random.random() -
                                                       0.5) * maxspeed / 20
                if velocities[i][j] > maxspeed / 2:
                    velocities[i][j] = maxspeed / 2
                if velocities[i][j] < -maxspeed / 2:
                    velocities[i][j] = -maxspeed / 2
                if printInfo:
                    gf.echo("  {}{}: {:6.2f} deg/sec".format(
                        j, i, -velocities[i][j]))
                gf.rotate(i, j, velocities[i][j] * (t - lastTime) / 1000)

        if allowCameraMoving:
            # Change camera distances and write new values to console
            for i in range(3, dim + 1):
                camPosLAcc[i] = camPosLAcc[i] + (random.random() - 0.5) / 64
                if camPosLAcc[i] < 0:
                    if camPosLAcc[i] < -0.01:
                        camPosLAcc[i] = -0.01
                    camPosL[i] = camPosL[i] + (camPosL[i] -
                                               0.2) * camPosLAcc[i]
                if camPosLAcc[i] > 0:
                    if camPosLAcc[i] > 0.01:
                        camPosLAcc[i] = 0.01
                    camPosL[i] = camPosL[i] + (10 - camPosL[i]) * camPosLAcc[i]
                if printInfo:
                    gf.echo("  camposl{}={:6.2f}".format(i, camPosL[i]))
                gf.set_camposl(i, camPosL[i])

        lastTime = t
        if printInfo:
            if auto:
                gf.echo("Automatic rotation enabled")
            else:
                gf.echo("Automatic rotation disabled")
        if mappedTo:
            if printInfo:
                gf.clearAfterCmd(
                    "Press " + mappedTo +
                    " to toggle camera moving or any other key to stop moving"
                )  # Remove only this line when user types command
            if allowCameraMoving:
                gf.map(mappedTo, "randomRot.randomRot(False)"
                       )  # Tab always rotates without camera moving (default)
            else:
                gf.map(
                    mappedTo, "randomRot.randomRot(gf.time()<" +
                    str(gf.time() + 100) + ")"
                )  # Pressing tab in 100ms will rotate with camera moving
                # If tab was used to abort rotation, the same press will resume it
        else:
            if printInfo:
                gf.clearAfterCmd("Press any key to stop moving")
Ejemplo n.º 5
0
def randomRot(allowCameraMoving=False, printInfo=True):
    global mappedTo
    maxspeed = gf.get_speed()
    dim = gf.get_dimen()

    # Create two dimensional list of angular velocities (one for every pair of axes)
    velocities = [0]
    for i in range(1, dim + 1):
        velocities = velocities + [[0] * i]

    if allowCameraMoving:
        # Create list of camera distances (in different levels of persp. proj.) and list of their current speeds
        camPosL = [0] * (dim + 1)
        for i in range(3, dim + 1):
            camPosL[i] = gf.get_camposl(i)
        camPosLAcc = [0] * (dim + 1)

    lastTime = gf.time()
    minDelay = 1000 / gf.get_maxfps()
    while gf.sleep(minDelay):  # Repeat till user abort; repaint and wait at least 1ms before every course
        t = gf.time()  # Time measuring to deal with different sleeping time
        if printInfo:
            gf.clear()
            # echo prints every line below the previous one, clearing is necessary
            gf.echo("--- Random rotation ---")

            # Rotate figure and write velocities to console
        for i in range(1, dim + 1):
            for j in range(1, i):
                velocities[i][j] = velocities[i][j] + (random.random() - 0.5) * maxspeed / 20
                if velocities[i][j] > maxspeed / 2:
                    velocities[i][j] = maxspeed / 2
                if velocities[i][j] < -maxspeed / 2:
                    velocities[i][j] = -maxspeed / 2
                if printInfo:
                    gf.echo("  {}{}: {:6.2f} deg/sec".format(j, i, -velocities[i][j]))
                gf.rotate(i, j, velocities[i][j] * (t - lastTime) / 1000)

        if allowCameraMoving:
            # Change camera distances and write new values to console
            for i in range(3, dim + 1):
                camPosLAcc[i] = camPosLAcc[i] + (random.random() - 0.5) / 64
                if camPosLAcc[i] < 0:
                    if camPosLAcc[i] < -0.01:
                        camPosLAcc[i] = -0.01
                    camPosL[i] = camPosL[i] + (camPosL[i] - 0.2) * camPosLAcc[i]
                if camPosLAcc[i] > 0:
                    if camPosLAcc[i] > 0.01:
                        camPosLAcc[i] = 0.01
                    camPosL[i] = camPosL[i] + (10 - camPosL[i]) * camPosLAcc[i]
                if printInfo:
                    gf.echo("  camposl{}={:6.2f}".format(i, camPosL[i]))
                gf.set_camposl(i, camPosL[i])

        lastTime = t
        if printInfo:
            if auto:
                gf.echo("Automatic rotation enabled")
            else:
                gf.echo("Automatic rotation disabled")
        if mappedTo:
            if printInfo:
                gf.clearAfterCmd(
                    "Press " + mappedTo + " to toggle camera moving or any other key to stop moving"
                )  # Remove only this line when user types command
            if allowCameraMoving:
                gf.map(mappedTo, "randomRot.randomRot(False)")  # Tab always rotates without camera moving (default)
            else:
                gf.map(
                    mappedTo, "randomRot.randomRot(gf.time()<" + str(gf.time() + 100) + ")"
                )  # Pressing tab in 100ms will rotate with camera moving
                # If tab was used to abort rotation, the same press will resume it
        else:
            if printInfo:
                gf.clearAfterCmd("Press any key to stop moving")
Ejemplo n.º 6
0
	main_help_pages.add(name)

def addPage(name, content):
	global help_pages, main_help_pages
	gf.addCommand("help " + name, "helpMod.printPage('" + name + "')")
	help_pages[name]=content.strip("\n")

def printPage(name):
	help_page=help_pages[name]
	if not help_page:
		raise RuntimeException("help " + name + " not found")
	gf.clear()
	gf.printCentered(help_pages[name])


gf.map("?", "helpMod.configPrint()")
gf.map("<F1>", "helpMod.configPrint()")
gf.addCommand("help config", "helpMod.configPrint()")
gf.echo("To see the configuration press F1")
config_readme=""

def configPrint():
	text=""
	if config_readme:
		text += config_readme
		text += "\n\nFor further help see the configuration file,"
	else:
		text += "There is no help on configuration (maybe there is no config.py file at all),"
	if main_help_pages:
		text += """
for help on imported modules type :help module <name>,