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

Using classes to draw shapes

$
0
0

@sunshine wrote:

I’m having trouble setting up my class to draw 4 Rectangles X 6 Rectangles.
This is my Rectangles.hpp

class Rectangles{
public:
    
    int x;
    int y;
    int width;
    int height;
    
    Rectangles();
    Rectangles(int x_in, int y_in, int width_in, int height_in);
    ~Rectangles();
    void setRectangles(int x_in, int y_in, int width_in, int height_in);
    void print(string label);
    
};

This is my Rectangles.cpp

#include "Rectangles.hpp"

Rectangles::Rectangles()
{
    x = 0;
    y = 0;
    width = 0;
    height = 0;
}
void Rectangles::setRectangles(int x_in, int y_in, int width_in, int height_in)
{
    x = x_in;
    y = y_in;
    width = width_in;
    height = height_in;
}
Rectangles::~Rectangles()
{
    
}
void Rectangles::print(string lable)
{
    cout<<"\nRectangle: "<<lable<<endl;
    cout<<"\n x: "<<x;
    cout<<"\n y: "<<y;
    cout<<"\n width: "<<width;
    cout<<"\n height: "<<height;
}

This is my draw()

void ofApp::draw(){

    for (int i = 0; i<25; i++) {
        ofDrawRectangle(i+180, i + 100, 40, 80);
    }
}

I’m confused on how to set up my class in a way that I am able to use the member functions in my draw() to make 4 Rectangles X 6 Rectangles.

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles