Link Search Menu Expand Document

Paint-the-Canvas Code

Below you can find the canvas code that you can run on the main laptop and project onto a big screen in the room. Note: replace the "localhost" with the server address that you are using for your teaching. In the sense, check that the channel

import nl.tue.id.oocsi.*;
import java.util.*;

OOCSI oocsi;

List<Blob> list = new ArrayList<Blob>(); 

void setup() {
  size(1280, 800);
  background(0);
  ellipseMode(CENTER);
  noStroke();
  smooth();
  frameRate(60);

  // connect to OOCSI
  oocsi = new OOCSI(this, "paint-the-canvas-main", "localhost");
  oocsi.subscribe("OOCSI_Tutorials_Paint_the_Canvas", "paintCanvas");
}

void draw() {
  fill(0, 10);
  rect(0, 0, width, height);

  synchronized(list) {
    for (Blob b : list) {
      fill(b.r, b.g, b.b);
      ellipse(b.x, b.y, b.c, b.c);
    }
    list.clear();
  }
}

// use mouse click to erase the screen
void mousePressed() {
  background(0);
}

void paintCanvas(OOCSIEvent event) {
  Blob blob = new Blob();
  blob.x = event.getInt("x", 0);
  blob.y = event.getInt("y", 0);

  if (blob.x > 0 || blob.y > 0) {
    blob.r = event.getInt("colorR", color(100, 100, 100));
    blob.g = event.getInt("colorG", color(100, 100, 100));
    blob.b = event.getInt("colorB", color(100, 100, 100));
    blob.c = event.getInt("diameter", 10);

    synchronized(list) {
      list.add(blob);
    }
  }
}

class Blob {
  float x, y, r, g, b, c;
}

Copyright © 2013-2024 Mathias Funk. test