Issues with refresh rate?
in
Contributed Library Questions
•
1 month ago
Hey all, I am writing some code that will get OSC messages from supercollider and use that to control some whitney-esque visuals. Originally i took some code from KrazyDad that was a processing transcription of the code present in Whitney's book Digital Harmony. The trouble comes with the lines of code referencing ftime -> which is the amount of time the frame has been running. the code from crazy dad uses millis to control ftime, and i added a modulo to that make an infinite loop of the visuals within set bounds. I am trying to move away from the infinite aspect of it using a for loop to supply the ftime values, however, when i use the loop it does not display the visuals in the same way. I will post the broken code, any help would be appreciated.
import oscP5.*;
import netP5.*;
//Create OSC variable
OscP5 oscP5;
//Create variable to use as OSC trigger for animation
boolean animate = true;
//First step of animation
float stepstart = -1,
//Last step of animation
stepend = 1,
radius,
//X and Y Centers
xcenter,
ycenter,
//Speed of animations
speed = .1;
//Degree to radian multiplier
float deg = 0.0174533;
//Number of points in the animation
float npoints = 500.0;
void setup()
{
size(1000,1000); //Size of window
radius = height*.9/2;
xcenter = width/2;
ycenter = height/2;
oscP5 = new OscP5(this,7771);
noStroke();
}
void draw()
{
background(0);
fill(255);
stroke(255);
if (animate == true){
whitney(1);
}else{
}
}
void whitney(int runs){
// float ftime = ((millis()*0.0001)%1); k replaces ftime
for (int j = 0; j < runs; j++){
for (float k = 0; k < 1; k += 0.001){
float step = stepstart + (k * (stepend - stepstart));
println("ftime = " + k + " step = " + step);
//Calculates the position of each point based on the current step
for (int i = 0; i < npoints; ++i)
{
float points = 360 * (i/npoints);
float a = 2*PI* points * deg;
float radiusi = radius*cos(a*step);
float x = xcenter + cos(a) * radiusi;
float y = ycenter + sin(a) * radiusi;
ellipse((int) x, height-(int) y, 2+k,2+k);
line(x,y,x+1,y+1);
}
}
}
}
void oscEvent(OscMessage theOscMessage){
//store the int from the OSC message in msg
int msg = theOscMessage.get(0).intValue();
if (msg == 1){
animate = true;
}else if (msg ==2){
animate = false;
}
if (msg == 3){
stepend = 5;
stepstart = 5;
}else if (msg == 4){
stepend = 6;
}
}
import oscP5.*;
import netP5.*;
//Create OSC variable
OscP5 oscP5;
//Create variable to use as OSC trigger for animation
boolean animate = true;
//First step of animation
float stepstart = -1,
//Last step of animation
stepend = 1,
radius,
//X and Y Centers
xcenter,
ycenter,
//Speed of animations
speed = .1;
//Degree to radian multiplier
float deg = 0.0174533;
//Number of points in the animation
float npoints = 500.0;
void setup()
{
size(1000,1000); //Size of window
radius = height*.9/2;
xcenter = width/2;
ycenter = height/2;
oscP5 = new OscP5(this,7771);
noStroke();
}
void draw()
{
background(0);
fill(255);
stroke(255);
if (animate == true){
whitney(1);
}else{
}
}
void whitney(int runs){
// float ftime = ((millis()*0.0001)%1); k replaces ftime
for (int j = 0; j < runs; j++){
for (float k = 0; k < 1; k += 0.001){
float step = stepstart + (k * (stepend - stepstart));
println("ftime = " + k + " step = " + step);
//Calculates the position of each point based on the current step
for (int i = 0; i < npoints; ++i)
{
float points = 360 * (i/npoints);
float a = 2*PI* points * deg;
float radiusi = radius*cos(a*step);
float x = xcenter + cos(a) * radiusi;
float y = ycenter + sin(a) * radiusi;
ellipse((int) x, height-(int) y, 2+k,2+k);
line(x,y,x+1,y+1);
}
}
}
}
void oscEvent(OscMessage theOscMessage){
//store the int from the OSC message in msg
int msg = theOscMessage.get(0).intValue();
if (msg == 1){
animate = true;
}else if (msg ==2){
animate = false;
}
if (msg == 3){
stepend = 5;
stepstart = 5;
}else if (msg == 4){
stepend = 6;
}
}
1