Art of CodeArt of Code

The Art of Code is a MA/MFA class that I am teaching at Multidisciplinary New Media department in Paris College of Art. The course provides an introduction to coding for artists and designers who are willing to learn and use it as a form of creative expression.

This website documents
the course materials. If you have any questions, you can contact me on Twitter.

Pixels

Manipulating canvas pixels


function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(0);

  circle(width/4, height/2, 200);

  // Load canvas pixels into pixels array
  loadPixels();

  // Modify pixels
  for (let i = 0; i < pixels.length; i += 4) {
    let value = map(i, 0, pixels.length, 0, 255);
    pixels[i] = value;
  }

  // Update canvas pixels
  updatePixels();

  circle(width/4*3, height/2, 200);
}

sketch is paused

Manipulating image pixels


let img;

function preload() {
  img = loadImage('city_night.jpg')
}

function setup() {
  createCanvas(400, 400);
  noLoop();
}

function draw() {
  background(0);

  // Draw the original image
  image(img, 0, 0);

  // Load image pixels into pixels array
  img.loadPixels();

  // Modify pixels
  for (let i = 0; i < img.pixels.length; i += 4) {
    let value = map(i, 0, img.pixels.length, 0, 200);
    pixels[i] = value;
  }

  // Update image pixels
  img.updatePixels();

  // Draw the modified image
  image(img, img.width, 0);
}

sketch is paused