Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Last active Feb 27, 2019
Embed
What would you like to do?
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