Hello,
Can you help please?
I’m trying to convert some Processing code into Open Frameworks, but am struggling because OF doesn’t have Stroke.
Here is the original code:
void draw() {
// background(0, 0, 0, 1);
noStroke();
fill(0, 0, 0, 32);
rect(0, 0, width, height);
noFill();
float count = 12;
float i = 0; float j = 0;
float x = width / 2 + (sin(xmotion * 0.5) * width / 16);
float y = height / 2 + (cos(zmotion * 0.75) * height / 16);
for (j = 0; j < 1; j += 0.002) {
float jnorm_j = abs(0.5 - j) * 2;
for (i = 0; i < count; i += 1) {
float norm_i = i / count;
float unit_i = 1 / count;
float inorm_i = abs(0.5 - norm_i) * 2;
float n = noise(inorm_i + xmotion, jnorm_j + ymotion) / 128;
float rad1 = radius + cos(xmotion * PI * 4 + inorm_i * PI * 32 + jnorm_j * PI * 8) / (0.4 + abs(sin(xmotion) * 2));
float rad2 = radius + sin(ymotion * PI * 4 + inorm_i * PI * 32 + jnorm_j * PI * 8) / (0.4 + abs(cos(zmotion) * 2));
float cx = rad1 * sin(norm_i * PI * 2 + n * 4 + xmotion + (j * PI * 2)) + sin(xmotion*2) * 24;
float cy = rad1 * cos(norm_i * PI * 2 + n * 4 + ymotion + (j * PI * 2)) + cos(ymotion*2) * 24;
float cx2 = rad2 * sin((unit_i + norm_i) * PI * 2 + xmotion + (j * PI * 2)) + sin(xmotion*2) * 24;
float cy2 = rad2 * cos((unit_i + norm_i) * PI * 2 + ymotion + (j * PI * 2)) + cos(ymotion*2) * 24;
//stroke(0, 0, 0, 128);
// line(x + cx, y + cy, x + cx2, y + cy2);
line(x + cx / 2, y + cy / 2, x + cx2 / 2, y + cy2 / 2);
stroke(192 + inorm_i * 128 + jnorm_j * 128, 128 * (1-j), 256, 256 * (n * 32));
line(x + cx / j, y + cy / j, x + cx2 / j, y + cy2 / j);
noStroke();
Here is my adaptation:
ofFill();
ofSetColor(0, 0, 0, 3);
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
ofNoFill();
// ofDrawCircle(ofGetWidth()/2, ofGetHeight()/2, ofRandom(100));
count = 12;
float i = 0;
float j = 0;
float x = ofGetWidth() / 2 + (sin(xmotion * 0.5) * ofGetWidth() / 16);
float y = ofGetHeight() / 2 + (cos(zmotion * 0.75) * ofGetHeight() / 16);
for (j = 0; j < 1; j += 0.002) {
float jnorm_j = abs(0.5 - j) * 2;
for (i = 0; i < count; i += 1) {
float norm_i = i / count;
float unit_i = 1 / count;
float inorm_i = abs(0.5 - norm_i) * 2;
//float n = noise(inorm_i + xmotion, jnorm_j + ymotion) / 128;
float n = ofNoise(inorm_i + xmotion, jnorm_j + ymotion) / 128;
float rad1 = radius + cos(xmotion * PI * 4 + inorm_i * PI * 32 + jnorm_j * PI * 8) / (0.4 + abs(sin(xmotion) * 2));
float rad2 = radius + sin(ymotion * PI * 4 + inorm_i * PI * 32 + jnorm_j * PI * 8) / (0.4 + abs(cos(zmotion) * 2));
float cx = rad1 * sin(norm_i * PI * 2 + n * 4 + xmotion + (j * PI * 2)) + sin(xmotion*2) * 24;
float cy = rad1 * cos(norm_i * PI * 2 + n * 4 + ymotion + (j * PI * 2)) + cos(ymotion*2) * 24;
float cx2 = rad2 * sin((unit_i + norm_i) * PI * 2 + xmotion + (j * PI * 2)) + sin(xmotion*2) * 24;
float cy2 = rad2 * cos((unit_i + norm_i) * PI * 2 + ymotion + (j * PI * 2)) + cos(ymotion*2) * 24;
ofSetColor(192 + inorm_i * 128 + jnorm_j * 128, 128 * (1-j), 256, 256 * (n * 32));
ofDrawLine(x + cx / 2, y + cy / 2, x + cx2 / 2, y + cy2 / 2);
ofDrawLine(x + cx / j, y + cy / j, x + cx2 / j, y + cy2 / j);
I’ve dropped the original Stroke values, (192 + inorm_i * 128 + jnorm_j * 128, 128 * (1-j), 256, 256 * (n * 32)), into ofSetColor, without the desired effect. What might I be doing wrong? How can i do the same thing in OF without using Stroke?
Thanks in advance :)