Last active
February 27, 2019 21:52
-
-
Save darrenmothersele/6934845 to your computer and use it in GitHub Desktop.
Translation of I.1 from Nature of Code to openFrameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
#include "testApp.h" | |
int main( ){ | |
ofSetupOpenGL(1024,768,OF_WINDOW); | |
ofRunApp(new testApp()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
#include <ofGraphics.h> | |
void testApp::setup(){ | |
ofBackground(255); | |
ofSetColor(0); | |
} | |
void testApp::update(){ | |
w.step(); | |
} | |
void testApp::draw(){ | |
w.display(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "Walker.h" | |
class testApp : public ofBaseApp{ | |
public: | |
Walker w; | |
void setup(); | |
void update(); | |
void draw(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef mySketch_Walker_h | |
#define mySketch_Walker_h | |
class Walker { | |
int x; | |
int y; | |
public: | |
Walker() { | |
x = ofGetWidth() / 2; | |
y = ofGetHeight() / 2; | |
} | |
void step() { | |
int choice = ofRandom(4); | |
if (choice == 0) { | |
x++; | |
} | |
else if (choice == 1) { | |
x--; | |
} | |
else if (choice == 2) { | |
y++; | |
} | |
else if (choice == 3) { | |
y--; | |
} | |
} | |
void display() { | |
ofRect(x, y, 1, 1); | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment