#include "rectangle.h" rectangle::rectangle(){ sizePct = 0.0f; sizeBegin = 120; sizeEnd = 0; sizeShaper = ((rand()%500+1)/50); alpha = 0.0f; alphaPct = 0.0f; alphaBegin = 255; alphaEnd = 0; alphaShaper = 4.0f; posPct = 0.0f; posShaper = (rand()%400+201)/60; } void rectangle::init(int x, int y){ sizePct = 0.0f; alphaPct = 0.0f; posPct = 0.0f; posa.x = x; posa.y = y; posb.x = rand()%ofGetWidth()+1; posb.y = (ofGetHeight()/2); } void rectangle::draw() { ofSetRectMode(OF_RECTMODE_CENTER); ofEnableAlphaBlending(); ofSetColor(255, 0 ,0, alpha); ofFill(); ofRect(pos.x, pos.y, size,size); ofDisableAlphaBlending(); } void rectangle::update(){ controlSize(); controlAlpha(); controlPos(); } void rectangle::controlSize(){ if (sizePct < 1) { sizePct += 0.025f; } interpolateSize(sizePct); }; void rectangle::controlAlpha(){ if (alphaPct < 1) { alphaPct += 0.025f; } interpolateAlpha(alphaPct); } void rectangle::controlPos(){ if (posPct < 1) { posPct += 0.025f; } interpolatePos(posPct); } void rectangle::interpolateSize(float pct){ pct = powf(pct, sizeShaper); size = (1-pct) * sizeBegin + (pct) * sizeEnd; } void rectangle::interpolateAlpha(float pct){ pct = powf(pct, alphaShaper); alpha = (1-pct) * alphaBegin + (pct) * alphaEnd; } void rectangle::interpolatePos(float pct){ pct = powf(pct, posShaper); pos.x = (1-pct) * posa.x + (pct) * posb.x; pos.y = (1-pct) * posa.y + (pct) * posb.y; }