1 Star 0 Fork 15

wait/python_turtle

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SpringDrag.pde 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
布树辉 提交于 2022-02-25 13:09 +08:00 . Rearrange dirs
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Mover object
Bob bob;
// Spring object
Spring spring;
void setup() {
size(640,360);
// Create objects at starting position
// Note third argument in Spring constructor is "rest length"
spring = new Spring(width/2,10,100);
bob = new Bob(width/2,100);
}
void draw() {
background(255);
// Apply a gravity force to the bob
PVector gravity = new PVector(0,2);
bob.applyForce(gravity);
// Connect the bob to the spring (this calculates the force)
spring.connect(bob);
// Constrain spring distance between min and max
spring.constrainLength(bob,30,200);
// Update bob
bob.update();
// If it's being dragged
bob.drag(mouseX,mouseY);
// Draw everything
spring.displayLine(bob); // Draw a line between spring and bob
bob.display();
spring.display();
fill(0);
text("click on bob to drag",10,height-5);
}
// For mouse interaction with bob
void mousePressed() {
bob.clicked(mouseX,mouseY);
}
void mouseReleased() {
bob.stopDragging();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wait1111/python_turtle.git
git@gitee.com:wait1111/python_turtle.git
wait1111
python_turtle
python_turtle
master

搜索帮助