-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
76 lines (61 loc) · 1.36 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;
let engine;
let world;
var ball;
var ground;
var con;
var ball2;
var con2
function setup() {
createCanvas(400,400);
engine = Engine.create();
world = engine.world;
var ball_options = {
restitution: 0.8
}
ball = Bodies.circle(200,50,10,ball_options);
World.add(world,ball);
ball2 = Bodies.circle(350,10,12,ball_options);
World.add(world,ball2);
con = Matter.Constraint.create({
pointA:{x:200,y:20},
bodyB:ball,
pointB:{x:0,y:0},
length:100,
stiffness:0.1
});
World.add(world,con);
con2 = Matter.Constraint.create({
bodyA:ball,
pointA:{x:0,y:0},
bodyB:ball2,
pointB:{x:0,y:0},
length:100,
stiffness:0.1
})
World.add(world,con2);
rectMode(CENTER);
ellipseMode(RADIUS);
}
function draw()
{
background(51);
Engine.update(engine);
ellipse(ball.position.x,ball.position.y,10);
ellipse(ball2.position.x,ball2.position.y,12);
push();
strokeWeight(2);
stroke(255);
line(con.pointA.x,con.pointA.y,ball.position.x,ball.position.y);
line(ball.position.x,ball.position.y,ball2.position.x,ball2.position.y);
pop();
}
function keyPressed()
{
if(keyCode==RIGHT_ARROW)
{
Matter.Body.applyForce(ball,{x:0,y:0},{x:0.05,y:0});
}
}