Newbie Drawing Question

Hello,

I am new to the openframeworks and trying to get my head around a few things. So I was wondering if you could help.

  1. I have noticed then when the draw function is executed in oF that it is deletes or covers us the previous frame and this is very useful in many applications but when I am trying to draw something this is obviously an a problem,

In “processing” I can write the following code

  
  
  
void setup(){  
  size(600, 600);  
  background (255);  
}  
  
void draw(){  
  ellipse (mouseX,mouseY,50,50);  
}  
  
  

And it produces the following effect (attached image)

How can I get this same effect in oF, where the previous frame information is preserved?

  1. Is there a way to create a variable for a shape like a circle or rectangle

for example I know you create a circle by
ofCircle(float x, float y, float radius)

But is there a way to create a variable for this circle so I can reference it later.

Something like

myCircle = ofCircle(float x, float y, float radius);

so later I can manipulate the properties like,
myCircle.x = newXpos

Thanks

Hi,

You can create a circle object in many different ways, a simple route can be using a struct, so in your testApp.h after the includes do something like this:

  
struct CustomCircle {  
	float x;  
	float y;  
	float radius;  
	  
	ofColor color;  
	  
	void draw() {  
		ofSetColor( color );  
		ofCircle( x, y, radius );  
	}  
};  

Then you create you circle objects like this:

  
CustomCircle myCircle;  

And in your testApp.cpp:

  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	ofBackground( 0, 0, 0 );  
	ofSetBackgroundAuto( false );  
	  
	myCircle.x			= 100;  
	myCircle.y			= 100;  
	myCircle.radius		= 100;  
	myCircle.color		= ofColor( 255, 5, 0 );  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	myCircle.x = ofGetMouseX();  
	myCircle.y = ofGetMouseY();  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	myCircle.draw();  
}  

More information about structs here http://www.cplusplus.com/doc/tutorial/structures/

And to achieve the effect you want, just call this in the setup method:

  
ofSetBackgroundAuto( false );  

Also check the OF wiki page, it has lost of documentation for beginners http://wiki.openframeworks.cc/index.php?title=Main-Page

Hope that helps

  • rS

@nardove

Thank you so much for your help,
This is exactly what I needed.

I never heard of structs before so this is very helpful.
I was looking for what to call objects in oF and now to initiate them, so this is great.

Everything you provided is much appreciated.