11723| 1
|
[高级教程] 【数学之美】圆和正弦,动起来 |
本帖最后由 rzyzzxw 于 2019-2-15 15:17 编辑 ![]() 【本项目程序来自文杰工程师】 ![]() ![]() 最新版本 ![]() 程序代码 [mw_shl_code=applescript,true]from mpython import * from machine import Timer import math def upRange(start, stop, step): while start <= stop: yield start start += abs(step) def downRange(start, stop, step): while start >= stop: yield start start -= abs(step) def timer1_tick(_): global Dy, Dx, i, j, my_list, _item oled.fill_rect(48, 0, 80, 64, 0) oled.hline(48, 32, 80, 1) oled.vline(48, 8, 50, 1) j_end = int(len(my_list)) for j in (1 <= j_end) and upRange(1, j_end, 1) or downRange(1, j_end, 1): oled.pixel(((len(my_list) + 50) - j), my_list[(j - 1)], 1) tim1 = Timer(1) def add_to_list(_item): global Dy, Dx, i, j, my_list my_list.append(_item) if len(my_list) > 72: my_list.pop(0) my_list = [] oled.fill(0) tim1.init(period=100, mode=Timer.PERIODIC, callback=timer1_tick) while True: for i in range(0, 361, 5): oled.fill_rect(0, 0, 47, 64, 0) oled.circle(20, 32, 20, 1) Dx = int((20 + math.cos(math.radians(i)) * 20)) Dy = int((32 - math.sin(math.radians(i)) * 20)) oled.line(20, 32, Dx, Dy, 1) oled.line(Dx, Dy, 46, Dy, 1) oled.show() add_to_list(Dy) [/mw_shl_code] 图形化程序 自定义函数中的列表为移动的正弦准备 ![]() 定时器部分是随圆上的点移动的正弦波 ![]() 重复执行部分是圆上运动的的点及连杆 ![]() 改了下程序 做成这样 ![]() 一颗爱心 献给你 ![]() |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed