3386

帖子

0

TA的资源

五彩晶圆(中级)

41
 

 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

42
 

15、滚雪球(大于)

 

  • #MicroPython动手做(35)——小游戏
  • #滚雪球
  • from mpython import *
  • import time
  • import random
  • import math
  • def on_button_a_down(_):
  • global i, x, y, r, yn, xn, my_listy, my_listx, j
  • time.sleep_ms(10)
  • if button_a.value() == 1: return
  • x = 4
  • y = 32
  • xn = 0
  • yn = 0
  • r = 4
  • i = 0
  • j = 10
  • my_listx = []
  • my_listy = []
  • for count in range(10):
  • my_listx.append((random.randint(20, 120)))
  • my_listy.append((random.randint(1, 60)))
  • oled.fill(0)
  • for count in range(10):
  • oled.pixel(my_listx[xn], my_listy[yn], 1)
  • xn = xn + 1
  • yn = yn + 1
  • oled.show()
  • while True:
  • oled.fill_circle(x, y, r, 1)
  • oled.DispChar((str(int(r))), 0, 0, 1)
  • oled.show()
  • if get_tilt_angle('Y') < -15:
  • x = x + 1
  • if get_tilt_angle('X') < -10:
  • y = y + -1
  • if get_tilt_angle('X') > 10:
  • y = y + 1
  • if x > 130:
  • break
  • i = 0
  • my_func()
  • def my_func():
  • global i, x, y, r, yn, xn, my_listy, my_listx, j
  • for count in range(int(j)):
  • if math.sqrt((x - my_listx[i]) ** 2 + (y - my_listy[i]) ** 2) <= r:
  • r = r + 2
  • my_listx[i] = (-1)
  • my_listy[i] = (-1)
  • i = i + 1
  • random.seed(time.ticks_cpu())
  • def get_tilt_angle(_axis):
  • _Ax = accelerometer.get_x()
  • _Ay = accelerometer.get_y()
  • _Az = accelerometer.get_z()
  • if 'X' == _axis:
  • _T = math.sqrt(_Ay ** 2 + _Az ** 2)
  • if _Az < 0: return math.degrees(math.atan2(_Ax , _T))
  • else: return 180 - math.degrees(math.atan2(_Ax , _T))
  • elif 'Y' == _axis:
  • _T = math.sqrt(_Ax ** 2 + _Az ** 2)
  • if _Az < 0: return math.degrees(math.atan2(_Ay , _T))
  • else: return 180 - math.degrees(math.atan2(_Ay , _T))
  • elif 'Z' == _axis:
  • _T = math.sqrt(_Ax ** 2 + _Ay ** 2)
  • if (_Ax + _Ay) < 0: return 180 - math.degrees(math.atan2(_T , _Az))
  • else: return math.degrees(math.atan2(_T , _Az)) - 180
  • return 0
  • button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

43
 

滚雪球

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

44
 

mPython X 实验图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

45
 

mPython X 实验图形编程2

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

46
 

目录清单
MicroPython动手做(01)——春节后入手了一块K210芯片AI开发板 
https://bbs.eeworld.com.cn/thread-1115786-1-1.html

MicroPython动手做(02)——尝试搭建K210开发板的IDE环境
https://bbs.eeworld.com.cn/thread-1115831-1-1.html

MicroPython动手做(03)——零基础学MaixPy之开机运行
https://bbs.eeworld.com.cn/thread-1116184-1-1.html

MicroPython动手做(04)——零基础学MaixPy之基本示例
https://bbs.eeworld.com.cn/thread-1116438-1-1.html

MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
https://bbs.eeworld.com.cn/thread-1116577-1-1.html

MicroPython动手做(06)——零基础学MaixPy之单目摄像头
https://bbs.eeworld.com.cn/thread-1116591-1-1.html

MicroPython动手做(07)——零基础学MaixPy之机器视觉
https://bbs.eeworld.com.cn/thread-1116617-1-1.html

MicroPython动手做(08)——零基础学MaixPy之识别颜色 
https://bbs.eeworld.com.cn/thread-1116662-1-1.html

MicroPython动手做(09)——零基础学MaixPy之人脸识别
https://bbs.eeworld.com.cn/thread-1116720-1-1.html

MicroPython动手做(10)——零基础学MaixPy之神经网络KPU
https://bbs.eeworld.com.cn/thread-1116925-1-1.html

MicroPython动手做(11)——搭建掌控板IDE环境
https://bbs.eeworld.com.cn/thread-1117964-1-1.html

MicroPython动手做(12)——掌控板之Hello World
https://bbs.eeworld.com.cn/thread-1118180-1-1.html

MicroPython动手做(13)——掌控板之RGB三色灯 
https://bbs.eeworld.com.cn/thread-1118275-1-1.html

MicroPython动手做(14)——掌控板之OLED屏幕
https://bbs.eeworld.com.cn/thread-1118389-1-1.html

MicroPython动手做(15)——掌控板之AB按键
https://bbs.eeworld.com.cn/thread-1118496-1-1.html

MicroPython动手做(16)——掌控板之图片图像显示
https://bbs.eeworld.com.cn/thread-1118945-1-1.html

MicroPython动手做(17)——掌控板之触摸引脚
https://bbs.eeworld.com.cn/thread-1119462-1-1.html

MicroPython动手做(18)——掌控板之声光传感器
https://bbs.eeworld.com.cn/thread-1119583-1-1.html

MicroPython动手做(19)——掌控板之蜂鸣器与音乐
https://bbs.eeworld.com.cn/thread-1119668-1-1.html

MicroPython动手做(20)——掌控板之三轴加速度
https://bbs.eeworld.com.cn/thread-1119998-1-1.html

MicroPython动手做(21)——掌控板之磁场传感器
https://bbs.eeworld.com.cn/thread-1120188-1-1.html

MicroPython动手做(22)——掌控板之无线广播
https://bbs.eeworld.com.cn/thread-1120835-1-1.html

MicroPython动手做(23)——掌控板之WiFi与蓝牙
https://bbs.eeworld.com.cn/thread-1120934-1-1.html

MicroPython动手做(24)——掌控板之拓展掌控宝 
https://bbs.eeworld.com.cn/thread-1121208-1-1.html

MicroPython动手做(25)——语音合成与语音识别
https://bbs.eeworld.com.cn/thread-1123752-1-1.html

MicroPython动手做(26)——物联网之OneNET
https://bbs.eeworld.com.cn/thread-1125172-1-1.html

MicroPython动手做(27)——物联网之微信小程序
https://bbs.eeworld.com.cn/thread-1125520-1-1.html

MicroPython动手做(28)——物联网之Yeelight
https://bbs.eeworld.com.cn/thread-1125939-1-1.html

MicroPython动手做(29)——物联网之SIoT
https://bbs.eeworld.com.cn/thread-1126090-1-1.html

 MicroPython动手做(30)——物联网之Blynk

https://bbs.eeworld.com.cn/thread-1126427-1-1.html

MicroPython动手做(31)——物联网之Easy IoT 

https://bbs.eeworld.com.cn/thread-1126903-1-1.html

MicroPython动手做(32)——物联网之MQTT
https://bbs.eeworld.com.cn/thread-1128464-1-1.html

MicroPython动手做(33)——物联网之天气预报
https://bbs.eeworld.com.cn/thread-1128721-2-1.html

MicroPython动手做(34)——通用传感器
https://bbs.eeworld.com.cn/thread-1129058-1-1.html

MicroPython动手做(35)——体验小游戏
https://bbs.eeworld.com.cn/thread-1129451-1-1.html

MicroPython动手做(36)——MixPY之Hello world
https://bbs.eeworld.com.cn/thread-1129816-1-1.html

MicroPython动手做(37)——驱动LCD与图文显示
https://bbs.eeworld.com.cn/thread-1130106-1-1.html

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

47
 

17、石头剪刀布(阿勇)

 

  • #MicroPython动手做(35)——小游戏
  • #石头剪刀布
  • from mpython import *
  • import time
  • import random
  • from machine import Timer
  • def on_button_a_down(_):
  • global y, x, k, j
  • time.sleep_ms(10)
  • if button_a.value() == 1: return
  • x = random.randint(1, 3)
  • xianshi(x, 10)
  • def on_button_b_down(_):
  • global y, x, k, j
  • time.sleep_ms(10)
  • if button_b.value() == 1: return
  • y = random.randint(1, 3)
  • xianshi(y, 90)
  • _status_p = _status_y = _status_t = _status_h = _status_o = _status_n = 0
  • def on_touchpad_P_pressed():pass
  • def on_touchpad_P_unpressed():pass
  • def on_touchpad_Y_pressed():pass
  • def on_touchpad_Y_unpressed():pass
  • def on_touchpad_T_pressed():pass
  • def on_touchpad_T_unpressed():pass
  • def on_touchpad_H_pressed():pass
  • def on_touchpad_H_unpressed():pass
  • def on_touchpad_O_pressed():pass
  • def on_touchpad_O_unpressed():pass
  • def on_touchpad_N_pressed():pass
  • def on_touchpad_N_unpressed():pass
  • tim12 = Timer(12)
  • def timer12_tick(_):
  • global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n
  • try:
  • touchPad_P.read();pass
  • except:
  • return
  • if touchPad_P.read() < 400:
  • if 1 != _status_p:_status_p = 1;on_touchpad_P_pressed()
  • elif 0 != _status_p:_status_p = 0;on_touchpad_P_unpressed()
  • if touchPad_Y.read() < 400:
  • if 1 != _status_y:_status_y = 1;on_touchpad_Y_pressed()
  • elif 0 != _status_y:_status_y = 0;on_touchpad_Y_unpressed()
  • if touchPad_T.read() < 400:
  • if 1 != _status_t:_status_t = 1;on_touchpad_T_pressed()
  • elif 0 != _status_t:_status_t = 0;on_touchpad_T_unpressed()
  • if touchPad_H.read() < 400:
  • if 1 != _status_h:_status_h = 1;on_touchpad_H_pressed()
  • elif 0 != _status_h:_status_h = 0;on_touchpad_H_unpressed()
  • if touchPad_O.read() < 400:
  • if 1 != _status_o:_status_o = 1;on_touchpad_O_pressed()
  • elif 0 != _status_o:_status_o = 0;on_touchpad_O_unpressed()
  • if touchPad_N.read() < 400:
  • if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
  • elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()
  • tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)
  • def on_touchpad_P_pressed():
  • global y, x, k, j
  • x = 0
  • y = 0
  • oled.fill(0)
  • oled.DispChar("玩家1按A键玩家2按B键", 0, 0, 1)
  • oled.show()
  • def xianshi(j, k):
  • global y, x
  • if j == 1:
  • oled.blit(image_picture.load('face/rock_s.pbm', 0), k, 17)
  • if j == 2:
  • oled.blit(image_picture.load('face/scissors_s.pbm', 0), k, 17)
  • if j == 3:
  • oled.blit(image_picture.load('face/paper_s.pbm', 0), k, 17)
  • oled.show()
  • def panduan():
  • global y, x, k, j
  • if x == y:
  • oled.DispChar(" 打平", 50, 50, 1)
  • else:
  • if x - y == -1 or x - y == 2:
  • oled.DispChar("玩家1赢", 50, 50, 1)
  • else:
  • oled.DispChar("玩家2赢", 50, 50, 1)
  • oled.show()
  • random.seed(time.ticks_cpu())
  • button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
  • button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)
  • image_picture = Image()
  • oled.fill(0)
  • oled.DispChar(" 石头剪刀布小游戏", 0, 0, 1)
  • oled.DispChar("玩家1按A键玩家2按B键", 0, 16, 1)
  • oled.DispChar(" 系统自动判断谁输谁赢", 0, 32, 1)
  • oled.DispChar(" 按P键开始玩", 0, 48, 1)
  • oled.show()
  • x = 0
  • y = 0
  • while True:
  • if x != 0 and y != 0:
  • panduan()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

48
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

49
 

mPython X 实验图形编程1

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

50
 

mPython X 实验图形编程2

 

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
艾睿电子& Silicon Labs 有奖直播 | 全新蓝牙信道探测:从技术创新到实际应用
直播时间:3月12日(周三)上午10:00
直播奖励:多功能榨汁机、蓝牙音箱、手机支架

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表