---
title: Particle Sim
---
## Particle Simulation in Canvas
In this guide, we're going to build a basic particle simulation in Canvas using simple principles of animation.
We will want to set up an array of particles with accelerations and velocities. We will create 100 particles at random points on the canvas.
```js
canvas = document.getElementById("canvas");
ctx = canvas.getContext('2d');
var particles = [];
for(var i=0; i<100; i++) {
particles.push(
{
x:Math.random()*canvas.width,
y:Math.random()*canvas.height,
vx:0,
vy:0,
ax:0,
ay:0
}
);
}
```
In our draw loop, we render these particles.
```js
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for(var i=0; i