Backtracking Recursiv



void Afis()
{
for (int j = 1; j <= n; j++)
cout << x[j] << " ";
cout << endl;
}

bool OK(int k) {
for (int i = 1; i < k; ++i)
if (x[k] == x[i])
return false;
return true;
}



void back(int k) {
for (int i = 1; i <= n; ++i)
{
x[k] = i;
if (OK(k))
if (k==n)
Afis();
else
back(k + 1);
}
}

//--------------------------------------------------------------
void ofApp::setup(){
cin >> n;
back(1);
}

Texte

In h declaram:

ofTrueTypeFont f;

In cpp scriem:

In start: f.load(“dogicapixelbold.ttf”, 30);

In draw: f.drawString(“scor: ” + ofToString(n), 700, 90);

Lectia 4 Timer

float acum = ofGetElapsedTimef();
cout << acum << endl;

if (acum > interval) {
    o[0] = o[0] + x;
    p[0] = p[0] + y;
    for (int i = l - 1; i > 0; i--) {
        o[i] = o[i - 1];
        p[i] = p[i - 1];
    }


    interval = acum + 0.2;
}

Lectia 3

void ofApp::draw() {
a += d;
b += p;
// c += r;
if (a > 1024)
{
d = -5;
};
if (a < 0) {
d = 5;
};
if (b > 768) {
p = -5;
}
if (b < 0) {
p = 5;
}
if (c > 255)
{
r = -1;
}
if (c < 100)
{
r = 1;
}
if (j > 255)
{
i = -1;
}
if (j < 0)
{
i = 1;
}

a += d;
b += p;

for (int s = 1; s < 6; s++) {
ofSetColor(f , g , z+20*s);
ofDrawRectangle(a , b , x , x);
}
//ofSetColor(ofColor::black);
//ofDrawRectangle(110 , b , 582 , 508);
//ofSetColor(ofColor::gray);
//ofSetLineWidth(5);
//ofLine(110 , 643 , 400 , 135);
//ofLine(400 , 135 , c , 643);
//ofLine(110 , 643 , c , 643);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == OF_KEY_LEFT) {
c-=5;

}
if (key == OF_KEY_RIGHT)
{
c+=5;
}

if (key == OF_KEY_UP)
{
j -= 5;
}
if (key == OF_KEY_DOWN)
{
j+=5;
}
if (key==114)//r
{
f+=10;
}
if (key == 100)//d
{
f-=10;
}
if (key == 103)//g
{
g += 10;
}
if (key == 110)//n
{
g -= 10;
}
if (key == 98)//b
{
z += 10;
}
if (key == 101)//e
{
z -= 10;
}
if (key == 49)
{
x += 5;
}
if (key == 50)
{
x -= 5;
}
cout << key<<" ";

}

Lectia 2

void ofApp::draw(){
	a += d;
	b += 2;
	c += 2;
	if (a > 820)
	{
		d = -20;
	};
	if (a < 195) {
		d = 20;
	};
	ofSetColor(ofColor::blue);
	ofDrawCircle(a , 390 , 200);
	//ofSetColor(ofColor::black);
	//ofDrawRectangle(110 , b , 582 , 508);
	//ofSetColor(ofColor::gray);
	//ofSetLineWidth(5);
	//ofLine(110 , 643 , 400 , 135);
	//ofLine(400 , 135 , c , 643);
	//ofLine(110 , 643 , c , 643);
}

Lectia 1 C++

void ofApp::draw(){
	ofFill();
	ofSetColor(ofColor::orange);
	ofDrawCircle(512,382,382);
//	ofSetColor(ofColor::blue);
	//ofNoFill();
	//ofSetLineWidth(3);
	ofSetColor(ofColor::blue);
	//ofDrawRectangle(178, 200, 666, 358);
	ofSetLineWidth(10);
	ofLine(150, 500, 876, 500);
	ofLine(512, 1, 150, 500);
	ofLine(512, 1, 876, 500);
}