Skip to content

Language Settings

Milliseconds

A millisecond is 1/1000 of a second. Processing keeps track of the number of milliseconds a program has run. By modifying this number with the modulo(%) operator, different patterns in time are created.

This example is ported from the Milliseconds example on the Processing website

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let scale;
function setup() {
  createCanvas(720, 400);
  noStroke();
  scale = width/20;
}
function draw() { 
  let i;
  for ( i = 0; i < scale; i++) {
    colorMode(RGB, (i+1) * scale * 10);
    fill(millis()%((i+1) * scale * 10));
    rect(i*scale, 0, scale, height);
  }
}
X

creative commons license