Gradually Growing Shape

I would like to make a shape smoothly and slowly gradually grow in size. I have tried to use ofScale(); but it moves too quickly and not as smooth as I would like. Any ideas on another approach?

Hi, you can use ofScale(...) with no problems at all. The thing is that you have to control the value you pass to it. The simplest would be to have a float declared in the h file which you increment on each frame and then pass it to ofScale.
ofApp.h file

#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
		void setup();
		void update();
		void draw();
	float scaleFactor;
#include "ofApp.h"
void ofApp::setup(){

scaleFactor = 1; // give it an initial value. 1 means no scaling

void ofApp::update(){
void ofApp::draw(){
ofPushMatrix();// scaling will affect only what you draw between push matrix and pop matrix.

// draw something


scaleFactor += 0.01; // change this value to make it faster or slower. if the value is possitive it will grow, if it is negative it will shrink


Be aware that scaling happens around the origin, (0,0), so if you want to scale around a different point you need to apply an ofTranslate before scaling. Search the forum, this has been answered several times.

if you want a fancier way to deal with how scaleFactor starts or stops you will need some kind of easing. Take a look at there are several addons for doing easing.

1 Like