Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

How to create infinite rectangles that grow out of the screen?

$
0
0

@ananasler wrote:

Hi,
I’d like to create an infinite loop, where little rectangles grow every two seconds or so from the center of the screen, rotate and grow until they reach the borders of the screen and then disappear.

I’m stuck with scaling - it makes the shapes go back and forth. The solution is probably simple, as always, and help would be appreciated!

(When I get the mechanics right, I’m planning to change the rectangles to a photo :slight_smile:)

Love,
A

 #include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofBackground(255);
    noOfDoors = 8;
}

//--------------------------------------------------------------
void ofApp::update(){
    phase++;
}

//--------------------------------------------------------------
void ofApp::draw(){
  
    float phaseDiff = 90/noOfDoors; 
    
    for (int i=0; i<ofGetWidth; i++){
         door(phase +  i * phaseDiff);
    }
}

//--------------------------------------------------------------
void ofApp::door(float phase){

    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    ofRotateZDeg(phase);
    float s = abs(sin(ofDegToRad(phase)));
    s =ofMap(s, 0, 1, 0, 3);
    ofScale(s);
    ofSetRectMode(OF_RECTMODE_CENTER);
    
    ofColor c1 = ofColor (255,0,0);
    ofColor c2 = ofColor (0,0,255);
    ofColor c3 = c1.getLerped(c2, s);
                              
    ofSetLineWidth(3);
    ofNoFill();
    ofSetColor(c3);
    ofDrawRectangle(0, 0, 100, 100);
    ofPopMatrix();
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles