Hello!
I’m quite new and am wanting to convert an old sketch I did from processing to OF but it isn’t quite working and ofRotate X,Y,Z are deprecated. Any advice on how I can get around this?
PROCESSING SKETCH
float a = 0; //counter
int sz = 10; //size of rects
void setup() {
size(600, 600, P3D);
background(0);
rectMode(CENTER);
}
void draw() {
background(0);
for (int i = sz; i < width; i += sz*2) { //for loop for x axis
for (int j = sz; j < height; j += sz*2) { //for loop for y axis
pushMatrix();
translate(i, j); //translate so each rect is draw at its own 0,0
float transform = PI+sin(a)*3;
rotateZ(transform); //rotate on XYZ angles
rotateX(transform);
rotateY(transform);
float move = PI/2+sin(a); //float to keep track
float opac = map(move, 0.5, 2.6, 50, 255);//mapping opacity to movement - so that rects opacity changes dependent on cycle of rotation
drawRect(sz+move*sz/2, opac); //the d (size of rect) is effected by rotation
popMatrix();
}
}
a+= 0.02; // a increments to change the effect on sin
}
void drawRect(float d, float o) { //two variables d = size of rect and o is opacity
fill(255, o);
rect(0, 0, d, d);
}
OPEN FRAMEWORKS
//--------------------------------------------------------------
void ofApp::setup(){
ofSetWindowShape(600, 600);
ofBackground(0);
ofRectMode(CENTER);
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0);
// float a = 0; // counter
// int sz = 10; // size of rects
for (int i = sz; i < ofGetWidth()-sz; i += sz*2) {//for loop for x axis
for (int j = sz; j < ofGetHeight()-sz; j += sz*2) { //for loop for y axis
ofPushMatrix();
ofTranslate(i,j);
float angle = PI+sin(a)*3;
ofRotateZ(angle); //rotate on XYZ angles
ofRotateX(angle);
ofRotateY(angle);
float move = PI/2+sin(a); //float to keep track
float opac = ofMap(move, 0.5, 2.6, 50, 255);//mapping opacity to movement - so that
//the rects opacity changes dependent on cycle of rotation
drawRect(sz+move*sz/2, opac); //the d(size of rect) is effected by rotation
ofPopMatrix();
}
}
a+= 0.02; // a increments to change the effect on sin
}
//--------------------------------------------------------------
void ofApp::drawRect(float d, float o){
ofSetColor(255, o);
ofDrawRectangle(0, 0, d, d);
--------------------------------------------------------------
Thanks!