def main(): global window mbhandler.init() glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(640, 480) glutInitWindowPosition(200, 200) window = glutCreateWindow('OpenGL Python Cube') glutDisplayFunc(DrawGLScene) glutIdleFunc(DrawGLScene) glutKeyboardFunc(keyPressed) InitGL(640, 480) glutMainLoop()
def setup(): global m, gem, gems if MB: mbhandler.init() else: global qRte, qEnd qRte, qEnd = qpath(qRot) m = G.Mesh() gem = G.Mesh() gems = [] m.addSphere(radius=radius, ambient=1) gem.colour = yellow gem.addSphere(radius=.01, ambient=.5, size=5) m.texture = "starmap_4k.jpeg" for k in range(50): v = RandomVec3(radius) gems.append(v) G.strokeWidth(.01) G.stroke(white)
import turtle import mbhandler width, height = turtle.screensize() mbhandler.init() colours = ["Red", "Green", "Blue", "Yellow", "Purple", "Cyan"] colour = 0 turtle.pencolor(colours[colour]) speed = 0 while True: mb = mbhandler.queue.get() x = mb['accelerometer']['x'] y = mb['accelerometer']['y'] a = mb['button_a']['down'] b = mb['button_b']['down'] if abs(x) < 10: x = 0 if abs(y) < 10: y = 0 if abs(y) > abs(x): speed -= y / 100 else: turtle.right(x) turtle.forward(speed) tx, ty = turtle.position()
#! /usr/bin/python3 import mbhandler import ev3dev.ev3 as ev3 mbhandler.init() # Steering mA = ev3.MediumMotor('outA') # Drive mB = ev3.LargeMotor('outB') # Head mD = ev3.LargeMotor('outD') def closedown(): print("Closing down ...") mbhandler.quit() ev3.Leds.all_off() mA.stop() mB.stop() mD.stop() exit() def strike(): mD.stop_action = 'hold' strike_pos = -10 mD.run_to_abs_pos(position_sp=strike_pos,speed_sp=50) mD.wait_while('running') mD.run_to_abs_pos(position_sp=-strike_pos,speed_sp=300) mD.wait_while('running')
msgfont = pygame.freetype.SysFont("TeX Gyre Pagella",size=height//20) titlefont = pygame.freetype.SysFont("TeX Gyre Pagella",size=height//15) splashfont = pygame.freetype.SysFont("TeX Gyre Pagella",size=height//5) mlh = msgfont.get_sized_height() + 2 tlh = titlefont.get_sized_height() + 2 slh = splashfont.get_sized_height() + 2 msgfont.origin = True titlefont.origin = True splashfont.origin = True screen = pygame.display.set_mode(size,pygame.FULLSCREEN) times = [] mbhandler.init(method="pygame", output="raw") scores = {} # Game states: # 0: Wait for a click to start # 1: Started, but trigger not given # 2: Trigger given gameState = 0 # Game levels: # 0: Easy, don't subtract if early # 1: Hard, early means minus points gameLevel = 0 disqualified = []
gem = pygame.image.load("gem.png") gemrect = gem.get_rect() gem = pygame.transform.scale(gem,(20,int(gemrect.height/gemrect.width*20))) gemrect = gem.get_rect() gems = [] cgems = 0 hgems = 0 font = pygame.freetype.Font(None,size=20) clock = pygame.time.Clock() inplay = True mbhandler.init(method="pygame") TREEEVENT = pygame.USEREVENT pygame.time.set_timer(TREEEVENT,30) while 1: clock.tick(100) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == 276: speed = -1 skier = skierL elif event.key == 275: speed = 1
import tkinter import tkinter.font import mbhandler spin = ["|", "/", "-", "\\"] spinIndex = 0 mbhandler.init(output="raw") root = tkinter.Tk() root.title("Quiz") frame = tkinter.Frame(root, width="200px", height="200px") frame.grid_propagate(0) frame.pack() font = tkinter.font.Font(family='TeX Gyre Pagella', size=20) b = tkinter.Button(frame, text="Click to start", font=font) q = tkinter.Button(frame, text="Quit", font=font) w = tkinter.Label(frame, justify=tkinter.RIGHT, text="Waiting ", font=font) spinVar = tkinter.StringVar() sp = tkinter.Label(frame, justify=tkinter.LEFT, textvariable=spinVar, font=font) w.grid(sticky=tkinter.E, row=0) sp.grid(sticky=tkinter.W, row=0, column=1) m = tkinter.Label(frame, justify=tkinter.RIGHT, text="Team ", font=font) mbVar = tkinter.StringVar()
import tkinter import tkinter.font import mbhandler spin = ["|","/","-","\\"] spinIndex = 0 mbhandler.init(output="raw") root = tkinter.Tk() root.title("Quiz") frame = tkinter.Frame(root,width="200px",height="200px") frame.grid_propagate(0) frame.pack() font = tkinter.font.Font(family='TeX Gyre Pagella', size=20) b = tkinter.Button(frame, text="Click to start", font=font) q = tkinter.Button(frame, text="Quit", font=font) w = tkinter.Label(frame, justify=tkinter.RIGHT, text="Waiting ",font = font) spinVar = tkinter.StringVar() sp = tkinter.Label(frame, justify=tkinter.LEFT, textvariable=spinVar, font=font) w.grid(sticky=tkinter.E,row=0) sp.grid(sticky=tkinter.W,row=0,column=1) m = tkinter.Label(frame, justify=tkinter.RIGHT, text="Team ",font = font) mbVar = tkinter.StringVar() mb = tkinter.Label(frame, justify=tkinter.LEFT, textvariable=mbVar,font = font) m.grid(sticky=tkinter.E,row=0) mb.grid(sticky=tkinter.W,row=0,column=1)
gem = pygame.image.load("gem.png") gemrect = gem.get_rect() gem = pygame.transform.scale(gem, (20, int(gemrect.height / gemrect.width * 20))) gemrect = gem.get_rect() gems = [] cgems = 0 hgems = 0 font = pygame.freetype.Font(None, size=20) clock = pygame.time.Clock() inplay = True mbhandler.init(method="pygame") TREEEVENT = pygame.USEREVENT pygame.time.set_timer(TREEEVENT, 30) while 1: clock.tick(100) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == 276: speed = -1 skier = skierL elif event.key == 275: speed = 1