明确概念
向量:PVector(x, y),定义一个2维
向量对象的方法:https://processing.org/reference/PVector.html
Velocity: s/t, 单位时间内距离的变化
Acceleration: v/t, 单位时间内速度的变化
F: a*m, 力产生加速度
明确功能
1.一个圆从画布随机出现,随机加速度,在画布上移动
功能设计
类:Mover
属性:初始坐标,初始速度,初始加速度,初始形状/大小
方法:setup(),move(),display()
伪代码
setup(){
mover.setup()
}
draw(){
mover.move()
mover.display()
}
class Mover{
定义属性
Mover(){}
定义方法
}
正式代码
见:
https://github.com/JoeyQiang/Processing/tree/master/Vectors
代码优化
1.考虑边界反弹
2.考虑最大速度限制
3.考虑多个对象的位移
4.考虑朝鼠标位置位置
网友评论