猫史档案馆


【Python作品分享】永动机

用户:yj皓月当空yj皓月当空查看:0 回复:0 评论:0 创建时间:2020-07-12T13:12:20


【作品展示】

center_image

 

【作品介绍】

永动机

 

【作品源代码】

from vpython import helix, vector, color, sphere, box, rate, graph, gcurve

spring = helix(pos = vector(0, 2, 0),
               axis = vector(0, -1, 0),
               size = vector(2, 0.3, 0.3),
               coils = 20
                )

floor = box(pos = vector(0, 2, 0),
            size = vector(1, 0.1, 1),
            color = color.green
            )

ball = sphere(pos = spring.pos + spring.axis,
              radius = 0.2,
              color = color.red,
              v = vector(0, -1, 0)
              )

graph(title="小球的速度", xtitle="时间", ytitle="速度") # 创建图表区域
v_curve = gcurve(color=color.red, label="小球速度") # 设定曲线的属性

i = 0
t = 0.01
f = 0.001

while i < 3000:
    rate(100)
    # 设置小球的速度
    ball.v += (-ball.pos) * t - f*ball.v
    # 移动小球
    ball.pos += ball.v * t
    spring.axis = ball.pos - spring.pos
    # 绘图
    v_curve.plot(i*t, ball.v.y)

    i = i + 1



# print("位置:", spring.pos)
# print("方向:", spring.axis)
# print("大小:", spring.size)
# print("圈数:", spring.coils)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页