物理

站点: 聚观点-创意编程
课程: 必修1. 互联网创意编程基础
图书: 物理
打印: 访客用户
日期: 2024年12月27日 星期五 18:08

1.1. 绕转

精灵/族群围绕某一个旋转中心做绕转运动
▶️运行示例代码

1.2. 扭力

Torque is the force that causes rotation. Use applyTorque to non-imperatively affect the sprite's rotation.

In this example, the robot rolls slower going uphill than it does going downhill.


🖥️

let robot, floor1, floor2;

function setup() {

new Canvas(500, 250);

world.gravity.y = 10;


robot = new Sprite(250, 0, 50);

robot.debug = true;


floor1 = new Sprite(400, 100, 500, 5, 's');

floor1.rotation = -10;

floor2 = new Sprite(890, 100, 500, 5, 's');

floor2.rotation = 10;

}


function draw() {

background(16);

robot.applyTorque(3);


camera.pos = robot.pos;

}