Interactive Grid System (Livestream)

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

Hey! In this recording of my very first YouTube-livestream i explain how to create an interactive visual system with Processing.

Enjoy!

The results

The images

The code

int amount = 5;
int[][] state = new int[amount][amount];
color fg = #10E09C;
PImage img1, img2, img3;

int mx, my;

void setup() {
  size(900, 900);
  for (int x = 0; x < amount; x++) {
    for (int y = 0; y < amount; y++) {
      state[x][y] = int(random(0, 6));
    }
  }

  img1 = loadImage("1.jpg");
  img1.resize(width, height);

  img2 = loadImage("2.jpg");
  img2.resize(width, height);

  img3 = loadImage("3.jpg");
  img3.resize(width, height);
}

void draw() {
  background(#f1f1f1);

  image(img3, 0, 0);
  float tileW = width/amount; 
  float tileH = height/amount; 
  fill(fg);
  noStroke();
  ellipseMode(CORNER);

  // Check where the mouse is
  mx = int(map(mouseX, 0, width, 0, amount));
  my = int(map(mouseY, 0, height, 0, amount));
  
  // Draw the visual

  for (int x = 0; x < amount; x++) {
    for (int y = 0; y < amount; y++) {

      if (state[x][y] == 0) {

        pushMatrix();
        translate(x*tileW, y*tileH);
        ellipse(0, 0, tileW, tileH);
        popMatrix();
      } else if (state[x][y] == 1) {

        pushMatrix();
        translate(x*tileW, y*tileH);
        rect(0, 0, tileW, tileH);
        popMatrix();
      } else if (state[x][y] == 2) {

        pushMatrix();
        translate(x*tileW, y*tileH);
        triangle(0, 0, tileW, tileH, 0, tileW);
        popMatrix();
      } else if (state[x][y] == 3) {

        int sx = int(tileW*x);
        int sy = int(tileH*y);
        int sw = int(tileW);
        int sh = int(tileH);

        int dx = sx;
        int dy = sy;
        int dw = sw;
        int dh = sh;

        copy(img1, sx, sy, sw, sh, dx, dy, dw, dh);
      } else if (state[x][y] == 4) {

        int sx = int(tileW*x);
        int sy = int(tileH*y);
        int sw = int(tileW);
        int sh = int(tileH);

        int dx = sx;
        int dy = sy;
        int dw = sw;
        int dh = sh;

        copy(img2, sx, sy, sw, sh, dx, dy, dw, dh);
      } else if (state[x][y] == 5) {
      }
    }
  }
}

void countUp(int x, int y) {
  if (state[x][y] < 5) {
    state[x][y]++;
  } else {
    state[x][y] = 0;
  }
}

void mouseReleased() {
  countUp(mx,my);
  saveFrame("out/visual####.jpg");
}

Published by Tim on Thursday March 11, 2021

Last modified on March 20th, 2021 at 19:18


Related

7. January 2021

Processing-Tutorial: Render Videos with the Movie Maker

There are several ways to render video from Processing. In this tutorial I’ll show you the easiest way I could […]

25. September 2020

Processing-Tutorial – Programming Posters

Some of you have asked for it, so here it is: A raw and uncut tutorial in which I explain […]

4. September 2020

Bauhaus 101 – A beginners Processing Tutorial

Hi and welcome to this very condensed and quick tutorial that aims to get you amazed for Creative Coding in […]

20. August 2020

How to use p5.js with Visual Studio Code

In this short tutorial i explain how you can use p5.js with Visual Studio Code. For this purpose, i’ll use […]

27. July 2020

The Magic Triangle

The Magic Triangle is a powerful creativity technique that can be applied to many different areas.

20. March 2020

Processing-Tutorial: Rasterize 3D

In this tutorial I show you how to create abstract 3D portraits from any image file. Here you will learn […]

6. December 2019

Processing-Tutorial: Image-Rasterizer

Level: Beginner & intermediate In this tutorial i’ll guide you through all the necessary steps to rasterize an image with […]

4. November 2019

Processing-Tutorial: WAVES pt. 1

This is the first part of a brand new tutorial-series about Waves, a fundamental skill and feature in Generative Design […]

16. April 2019

Processing-Tutorial: Kinetic Typography 1

In the last years i’ve observed a new tendency in typography and graphic design which has been made possible by […]

14. April 2019

Processing-Tutorial: Video Export

One of the most powerful features of Processing in comparison to all web-based approaches and frameworks (like p5.js) is the […]

1. March 2019

How to rasterize an image with Processing

In this post i’ll teach you how to access the data of an image and how to use it to […]