We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm new to processing and I'm working with this code.. while I accomplished to fade the background I wonder how to change the stroke weight with the same data the background changes. Thanks in advance. This is my code:
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioPlayer mySound;
Serial port;
float brightness;
void setup() {
size(1000, 500,P3D);
String portName = Serial.list()[2];
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
port.bufferUntil('\n');
noFill();
strokeWeight(1);
minim = new Minim(this);
mySound = minim.loadFile("bb.mp3");
mySound.play();
mySound.loop();
}
int n=0;
void draw ()
{
background (brightness, 0, 25);
translate(width/2,height/2);
for(int i = 0; i < mySound.bufferSize() - 1; i++) {
stroke(random(250),random(250),random(250));
rotateX(n*-PI/6*0.05);
rotateY(n*-PI/6*0.05);
rotateZ(n*-PI/6*0.05);
triangle (i,i,mySound.left.get(i)*50,mySound.left.get(i)*50,i,i);
}
n++;
}
void serialEvent (Serial port)
{
brightness = float (port.readStringUntil ('\n'));
}
Answers
@realdapsis -- without testing your code, but just looking at it:
Currently your brightness is a variable declared at the top:
...and you assign a value to it in your
serialEvent()
function:...and you use that value in
draw()
to change the background of the screen:So. Currently in draw you set the stroke like this:
Based on the example of how your brightness works: How could you change this code so that
stroke()
uses a variable -- and the variable is assigned during your serialEvent?