Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # skate-sim.py
- #
- # Copyright 2012 Ricardo Band <xen@makesyouhappy.org>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Library General Public
- # License as published by the Free Software Foundation; either
- # version 3 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Library General Public License for more details.
- #
- # You should have received a copy of the GNU Library General Public
- # License along with this library; if not, write to the Free
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- import sys, os
- import pygame
- from pygame.locals import *
- from array import *
- pygame.init()
- fpsClock = pygame.time.Clock()
- windowSurfaceObj = pygame.display.set_mode((800, 480), FULLSCREEN)
- pygame.display.set_caption("Skate Sim")
- redColor = pygame.Color(255, 0, 0)
- greenColor = pygame.Color(0, 255, 0)
- blueColor = pygame.Color(0, 0, 255)
- whiteColor = pygame.Color(255, 255, 255)
- fontObj = pygame.font.Font("freesansbold.ttf", 32)
- # find SIXAXIX
- six_present = False
- numJoy = pygame.joystick.get_count()
- sixaxis = pygame.joystick.Joystick
- msg = "SIXAXIS not connected."
- if numJoy > 0:
- joyId = -1
- for i in range(0, numJoy):
- joy = pygame.joystick.Joystick(i)
- if "PLAYSTATION(R)3 Controller" in joy.get_name():
- joyId = i
- continue
- if joyId > -1:
- sixaxis = pygame.joystick.Joystick(0)
- if not sixaxis.get_init():
- sixaxis.init()
- six_present = True
- else:
- msg = "This is no SIXAXIS"
- # prepare arrays for graphs
- graphx = array('I')
- graphy = array('I')
- graphz = array('I')
- for i in range(0, 800):
- graphx.append(240)
- graphy.append(240)
- graphz.append(240)
- while True:
- windowSurfaceObj.fill(whiteColor)
- if six_present:
- msgx = "x: " + str(sixaxis.get_axis(4))
- msgy = "y: " + str(sixaxis.get_axis(5))
- msgz = "z: " + str(sixaxis.get_axis(6))
- else:
- msgx = ""
- msgy = ""
- msgz = ""
- msgxSurfaceObj = fontObj.render(msgx, False, redColor)
- msgySurfaceObj = fontObj.render(msgy, False, greenColor)
- msgzSurfaceObj = fontObj.render(msgz, False, blueColor)
- msgxRectObj = msgxSurfaceObj.get_rect()
- msgyRectObj = msgySurfaceObj.get_rect()
- msgzRectObj = msgzSurfaceObj.get_rect()
- msgxRectObj.topleft = (10, 10)
- msgyRectObj.topleft = (10, 47) # 32px font + 5px space
- msgzRectObj.topleft = (10, 84)
- windowSurfaceObj.blit(msgxSurfaceObj, msgxRectObj)
- windowSurfaceObj.blit(msgySurfaceObj, msgyRectObj)
- windowSurfaceObj.blit(msgzSurfaceObj, msgzRectObj)
- for i in range(0, 799):
- graphx[i] = graphx[i+1]
- graphy[i] = graphy[i+1]
- graphz[i] = graphz[i+1]
- if six_present:
- graphx[799] = int(sixaxis.get_axis(4)*-240+240)
- graphy[799] = int(sixaxis.get_axis(5)*-240+240)
- graphz[799] = int(sixaxis.get_axis(6)*-240+240)
- else:
- graphx[799] = 240
- graphy[799] = 240
- graphz[799] = 240
- pixArr = pygame.PixelArray(windowSurfaceObj)
- for x in range(0, 800):
- pixArr[x][graphx[x]] = redColor
- pixArr[x][graphy[x]] = greenColor
- pixArr[x][graphz[x]] = blueColor
- del pixArr
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == MOUSEBUTTONUP:
- pygame.event.post(pygame.event.Event(QUIT))
- pygame.display.update()
- fpsClock.tick(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement