Logo
  • start
LinkedIn
🎥

Hypercinema Final

offmilk How would you rotate text along a curved path?offmilk How would you rotate text along a curved path?

I've built a home made pressure sensor. It provides 108 values from serial communication that are layed out in 3 circles. The testing_values_sketch_circles.js sketch currently showcases the sensor's locations perfectly.

Currently MAX_PRESSURE is set to 300.

I would like to create a transition between two scenarios, where if all 108 values from serial communication come back as 300, then the scene we're seeing would appear fully magenta.

Essentially, where ever I'm touching the pressure sensor I want to see a change from a blue background to pink, where the size of the area of the change is mapped to the pressure.

But here's the thing. the firstRadius of the innermost circle is currently 130, which means there's a big space in the middle of the sketch.

How can we turn this into more of a coordinate system, where:

  • we have 2 scenes and they mix together - using something that's performant and that can handle all the real time data. Changing pixel by pixel unfortunately won't be fast enough & we eventually want to have the pink scene also include ripples or movement, so seems like shaders would be the way to go but I'm not entirely sure. There's also a p5 shaders library or something like Shaders Park. Feel free to provide other beginner friendly suggestions.
  • I would like to be able to have different modes or almost states.

Something like: if (all sensors are coming back as 0) = animation is at 0%. if 50% of the snesors are coming back at 150, animation is at 50% and therefore we trigger some conditions, maybe like music TBD). If all sensors are coming back as 300, then animation is at 100%, which could trigger ending message to show on the screen. This will be decided later but the logic needs to exist.

  • We make it so that every inch of this circle is mapped to a sensor, almost like a pie (regarless of the physical shape of the sensors forming 3 circles varying in size).

Sound

For noisy music, songs by Händel.

Technical issues

‣

p5.js library, which is the core of our program, doesn't work properly with importing modules

The issue actually seems to be that the p5.js library, which is the core of our doesn't work properly with importing modules.

I googled around and found some old advice:

At the bottom of the module, you have to expose the method using to the browser. Like this:

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

function draw() { background(55); }

function keyPressed() { console.log("presseed"); }

window.setup = setup;

window.draw = draw;

window.keyPressed = keyPressed;

For some reason you don't have to do that to all functions, like background(). Don't know why yet, but am looking into it.

  • -----------

P5 functions that are looked up by P5 itself are in global scope. But p5 can't see into the module. Thus they have to be exposed to the window in the module itself.

This refers to setup, draw, keyPressed/released, mouse and such. Haven't looked up all functions, that P5 looks up at the time the site is loaded.

Functions that are called don't need to be specified like this, as they are all in global scope and the module has access to this already.

I'm not sure if I should follow this advice, but otherwise what could be done, if it's performant - because we're using real time serial communication data, is import all the pages that have functions to be run with the script tag on index.html, and then call the methods inside the SpiralScene directly on the class from the main setup and draw functions.

An example that works with the method above is:

let engine;

let mousyBodies = [];

let ground;

function setup() {

createCanvas(400, 400);

engine = Engine.create();

ground = new Ground(200, 390, 400, 20);

}

function draw() {

background(115, 0, 58);

Engine.update(engine);

for (let i=0; i<mousyBodies.length; i++){

mousyBodies[i].display();

}

ground.display();

}

And then having an external file imported into index.html:

class Ground {

constructor(x, y, w, h) {

this.w = w;

this.h = h;

this.body = Bodies.rectangle(x, y, this.w, this.h, {isStatic: true});

Composite.add(engine.world, this.body);

}

display() {

push(); // push() and pop() = drawing group where transformations apply

rectMode(CENTER);

let x = this.body.position.x;

let y = this.body.position.y;

translate(x, y);

noStroke();

fill(60, 21, 78); // color fill

rect(0, 0, this.w, this.h);

pop();

}

}

Solution

// Under draw function & existing code:

// Expose functions to the global scope
window.preload = preload;
window.setup = setup;
window.draw = draw;
‣

WEBGL: you must load and set a font before drawing text. See loadFont and textFont for more details.

3D in the browser through p5.js

createCanvas(800, 800, WebGL) makes a 3D canvas. Color fill isn’t applied the same way.

Text

How to rotate

offmilk How would you rotate text along a curved path?offmilk How would you rotate text along a curved path?

function setup(){
	createCanvas (400, 300, WEBGL);

function draw() {
	background (175);
	rectMode (CENTER);
	noStroke();
	fill(0, 0, 255);
	rotateZ(ang}e);
	rect (0, 0, 150, 150);
	
	angle += 0.07; 
}

Projectors

  • Short throw
  • Can use Creative Cast -
    Creative CastCreative Cast