最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

搖桿數(shù)據(jù)記錄

2022-10-27 18:40 作者:weezyr  | 我要投稿


import pygame#加載庫

# 定義顏色

BLACK ? ?= ( ? 0, ? 0, ? 0)

WHITE ? ?= ( 255, 255, 255)


#這是一個簡單的類,將幫助我們打印到屏幕上。它與操縱桿無關(guān),只是輸出信息。

class TextPrint:

? ? def __init__(self):

? ? ? ? self.reset()

? ? ? ? self.font = pygame.font.Font(None, 20)


? ? def print(self, screen, textString):

? ? ? ? textBitmap = self.font.render(textString, True, BLACK)

? ? ? ? screen.blit(textBitmap, [self.x, self.y])

? ? ? ? self.y += self.line_height

? ? ? ?

? ? def reset(self):

? ? ? ? self.x = 10

? ? ? ? self.y = 10

? ? ? ? self.line_height = 15

? ? ? ?

? ? def indent(self):

? ? ? ? self.x += 10

? ? ? ?

? ? def unindent(self):

? ? ? ? self.x -= 10

#設(shè)置屏幕得到寬度和長度 [width,height]

pygame.init()#初始化

size = [300, 300]

screen = pygame.display.set_mode(size)

pygame.display.set_caption("controller_test")

#被用來管理屏幕更新的速度

clock = pygame.time.Clock()

# 初始化joystick

pygame.joystick.init()

# 準備好打印

textPrint = TextPrint()

date = open('controll_joystick_date.txt',"w+")#新建數(shù)據(jù)文本

done = False#循環(huán)

#----程序主體部分--------

while done == False:#無線循環(huán)主體程序

? ?for event in pygame.event.get():#獲取玩家輸入

? ? ? ?if event.type == pygame.QUIT:

? ? ? ? ? done=True

? ? # 繪制的步驟

? ? #首先,用白色清除屏幕。不要放其它的繪圖指令

? ? #在這條上面的指令,將會被擦除

? ?screen.fill(WHITE)

? ?textPrint.reset()

? ?joystick_count = pygame.joystick.get_count()#獲取搖桿數(shù)目

? ?for i in range ( joystick_count ):#

? ? ? ? joystick = pygame.joystick.Joystick(i)

? ? ? ? joystick.init()

? ? ? ? axes = joystick.get_numaxes()#獲取軸數(shù)目

? ? ? ? for i in range ( axes ) :

? ? ? ? ? ? axis_0 = joystick.get_axis( 0 )#左搖桿x軸

? ? ? ? ? ? axis_1 = joystick.get_axis( 1 )#左搖桿y軸

? ? ? ? ? ? axis_2 = joystick.get_axis( 2 )#右搖桿x軸

? ? ? ? ? ? axis_3 = joystick.get_axis( 3 )#右搖桿y軸

? ? ? ? ? ? axis_4 = joystick.get_axis( 4 )#左板機

? ? ? ? ? ? axis_5 = joystick.get_axis( 5 )#右板機

? ? ? ? textPrint.print(screen,"Left_stick_x_axis value: {:>6.4f}".format(axis_0))

? ? ? ? textPrint.print(screen,"Left_stick_y_axis value: {:>6.4f}".format(axis_1))

? ? ? ? textPrint.print(screen,"Right_stick_x_axis value: {:>6.4f}".format(axis_2))

? ? ? ? textPrint.print(screen,"Right_stick_y_axis value: {:>6.4f}".format(axis_3))

? ? ? ? textPrint.print(screen,"Left_trigger value: {:>6.4f}".format(axis_4))

? ? ? ? textPrint.print(screen,"Right_trigger value: {:>6.4f}".format(axis_5))

? ? ? ? textPrint.unindent()

? ? ? ? date.write("{:>6.4f}\n".format(axis_3))#把搖桿數(shù)值寫入文本

? ?pygame.display.flip()

? ?clock.tick(20)

date.close()

pygame.quit ()


搖桿數(shù)據(jù)記錄的評論 (共 條)

分享到微博請遵守國家法律
林口县| 西盟| 贺州市| 潼南县| 南充市| 安陆市| 阳原县| 远安县| 凤山县| 虹口区| 永泰县| 瑞丽市| 中方县| 武胜县| 靖西县| 玉溪市| 金堂县| 赤水市| 陇南市| 六安市| 永年县| 渭源县| 抚松县| 南投县| 格尔木市| 铜陵市| 广州市| 襄城县| 平昌县| 青浦区| 轮台县| 兴山县| 阿拉善左旗| 龙泉市| 陇川县| 克什克腾旗| 大洼县| 葵青区| 嘉定区| 琼中| 镇平县|