Skip to content

Commit 561e84d

Browse files
authored
Merge pull request #822 from nature-of-code/notion-update-docs
[Notion] Update docs
2 parents e1ad083 + c4a7e5c commit 561e84d

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

content/06_libraries.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ <h2 id="polygons-and-groups-of-shapes">Polygons and Groups of Shapes</h2>
533533
<p>Two strategies can be used to make such complex forms. The generic <code>Bodies.polygon()</code> method can create any regular polygon (pentagon, hexagon, and so on). Additionally, <code>Bodies.trapezoid()</code> makes a quadrilateral with at least one pair of parallel sides:</p>
534534
<pre class="codesplit" data-code-language="javascript">// A regular hexagon (six-sided polygon)
535535
let hexagon = Bodies.polygon(x, y, 6, radius);
536-
537536
// A trapezoid
538537
let trapezoid = Bodies.trapezoid(x, y, width, height, slope);</pre>
539538
<p>A more general-purpose option is <code>Bodies.fromVertices()</code>. It builds a shape from an array of vectors, treating them as a series of connected vertices. I’ll encapsulate this logic in a <code>CustomShape</code> class.</p>
@@ -643,7 +642,6 @@ <h3 id="example-65-multiple-shapes-on-one-body">Example 6.5: Multiple Shapes on
643642
let position2 = this.part2.position;
644643
fill(200);
645644
stroke(0);
646-
strokeWeight(1);
647645
// Translate and rotate the rectangle (<code>part1</code>).
648646
push();
649647
translate(position1.x, position1.y);
@@ -704,14 +702,16 @@ <h3 id="distance-constraints">Distance Constraints</h3>
704702
<li><code>stiffness</code>: A value from 0 to 1 that represents the rigidity of the constraint, with 1 being fully rigid and 0 being completely soft.</li>
705703
</ul>
706704
<p>These settings get packaged up in an object literal:</p>
707-
<pre class="codesplit" data-code-language="javascript">let options = {
705+
<div class="avoid-break">
706+
<pre class="codesplit" data-code-language="javascript">let options = {
708707
bodyA: particleA.body,
709708
bodyB: particleB.body,
710709
pointA: Vector.create(0, 0),
711710
pointB: Vector.create(0, 0),
712711
length: 100,
713712
stiffness: 0.5
714713
};</pre>
714+
</div>
715715
<p>Technically, the only required options are <code>bodyA</code> and <code>bodyB</code>, the two bodies connected by the constraint. If you don’t specify any additional options, Matter.js will choose defaults for the other properties. For example, it will use <code>(0, 0)</code> for each relative anchor point (the body’s center), set the <code>length</code> to the current distance between the bodies, and assign a default <code>stiffness</code> of <code>0.7</code>. Two other notable options I didn’t include are <code>damping</code> and <code>angularStiffness</code>. The <code>damping</code> option affects the constraint’s resistance to motion, with higher values causing the constraint to lose energy more quickly. The <code>angularStiffness</code> option controls the rigidity of the constraint’s angular motion, with higher values resulting in less angular flexibility between the bodies.</p>
716716
<p>Once the options are configured, the constraint can be created. As usual, this assumes another alias—<code>Constraint</code> is equal to <code>Matter.Constraint</code>:</p>
717717
<pre class="codesplit" data-code-language="javascript">let constraint = Constraint.create(options);
@@ -729,20 +729,17 @@ <h3 id="example-66-matterjs-pendulum">Example 6.6: Matter.js Pendulum</h3>
729729
constructor(x, y, len) {
730730
this.r = 12;
731731
this.len = len;
732-
733732
//{!2} Create two bodies, one for the anchor and one for the bob.
734733
// The anchor is static.
735734
this.anchor = Bodies.circle(x, y, this.r, { isStatic: true });
736735
this.bob = Bodies.circle(x + len, y, this.r, { restitution: 0.6 });
737-
738736
//{!6} Create a constraint connecting the anchor and the bob.
739737
let options = {
740738
bodyA: this.anchor,
741739
bodyB: this.bob,
742740
length: this.len,
743741
};
744742
this.arm = Matter.Constraint.create(options);
745-
746743
//{!3} Add all bodies and constraints to the world.
747744
Composite.add(engine.world, this.anchor);
748745
Composite.add(engine.world, this.bob);
@@ -752,20 +749,16 @@ <h3 id="example-66-matterjs-pendulum">Example 6.6: Matter.js Pendulum</h3>
752749
show() {
753750
fill(127);
754751
stroke(0);
755-
strokeWeight(2);
756-
757752
//{!2} Draw a line representing the pendulum arm.
758753
line(this.anchor.position.x, this.anchor.position.y,
759754
this.bob.position.x, this.bob.position.y);
760-
761755
//{!6} Draw the anchor.
762756
push();
763757
translate(this.anchor.position.x, this.anchor.position.y);
764758
rotate(this.anchor.angle);
765759
circle(0, 0, this.r * 2);
766760
line(0, 0, this.r, 0);
767761
pop();
768-
769762
//{!6} Draw the bob.
770763
push();
771764
translate(this.bob.position.x, this.bob.position.y);
@@ -823,7 +816,6 @@ <h3 id="example-67-spinning-windmill">Example 6.7: Spinning Windmill</h3>
823816
//{!2} The rotating body
824817
this.body = Bodies.rectangle(x, y, w, h);
825818
Composite.add(engine.world, this.body);
826-
827819
//{!8} The revolute constraint
828820
let options = {
829821
bodyA: this.body,

0 commit comments

Comments
 (0)