A small program utilizing the
turtle modules. You can drive the little turtle by turning your Thinkpad (which must have APS).
You need a newer Thinkpad (T41, T42, T43, T6x, R5x, R6x or any newer) and need to have the Active Protection System drivers (now called Lenovo Airbag Protection) installed.
Python, 32 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import ctypes import time import turtle class SensorData(ctypes.Structure): _fields_ = [ ('status', ctypes.c_int), ('raw_x', ctypes.c_short), ('raw_y', ctypes.c_short), ('x', ctypes.c_short), ('y', ctypes.c_short), ('temp', ctypes.c_byte), ('center_x', ctypes.c_short), ('center_y', ctypes.c_short), ] def getXY(): data = SensorData() ctypes.windll.Sensor.ShockproofGetAccelerometerData(ctypes.byref(data)) return data.raw_x / 10.0, data.raw_y / 10.0 def main(): centerx, centery = getXY() turtle.pensize(3) while 1: x, y = getXY() turtle.left(centery-y) turtle.forward(centerx-x) time.sleep(0.01) if __name__ == '__main__': main()
please provide more information. i tried to run this program on my laptop and got an exception:
You probably don't have a newer Thinkpad (T41, T42, T43, T6x, R5x, R6x or any newer) or don't have the Active Protection System drivers (now called Lenovo Airbag Protection) installed.
ahh i don't even have thinkpad :)
Linux version is here.
My Python 2.4 under windows denied to use turtle attributes, so I fix source for running in text mode: