Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Last active February 27, 2019 21:52
Show Gist options
  • Save darrenmothersele/6934845 to your computer and use it in GitHub Desktop.
Save darrenmothersele/6934845 to your computer and use it in GitHub Desktop.
Translation of I.1 from Nature of Code to openFrameworks
#include "ofMain.h"
#include "testApp.h"
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW);
ofRunApp(new testApp());
}
#include "testApp.h"
#include <ofGraphics.h>
void testApp::setup(){
ofBackground(255);
ofSetColor(0);
}
void testApp::update(){
w.step();
}
void testApp::draw(){
w.display();
}
#pragma once
#include "ofMain.h"
#include "Walker.h"
class testApp : public ofBaseApp{
public:
Walker w;
void setup();
void update();
void draw();
};
#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