GithubHelp home page GithubHelp logo

ofxyz / ofxgameoflife Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bernardoaraujor/ofxgameoflife

0.0 1.0 0.0 7 KB

openFrameworks addon of Conway's Game of Life

License: Other

Makefile 22.42% C++ 77.58%

ofxgameoflife's Introduction

ofxGameOfLife

openFrameworks addon of Conway's Game of Life.

I'm working on a terminal-based Game of Life oF app, so I thought having a general purpose ofx implementation would be useful. This addon is based on Chris Roby's implementation, which can be found at https://github.com/croby/conway-of.

The main abstraction of ofxGameOfLife is the grid system. The grid can be retrieved with game.getGrid(), while individual cells can be retrieved with game.getCell(i, j).

Released under the MIT License.

Developed and tested under openFrameworks v0.10.0 on Ubuntu 16.04.

image

Example:

declare ofxGameOfLife at ofApp.h:

ofxGameOfLife game;

then setup the game, update and draw at ofApp.cpp:

//--------------------------------------------------------------
void ofApp::setup(){
    int cellSize = 6;

    game.setup(ofGetWidth(), ofGetHeight(), cellSize);
    game.gliderGun(ofGetWidth()/3/cellSize, ofGetHeight()/2/cellSize);
}


//--------------------------------------------------------------
void ofApp::update(){
    game.update();
}

//--------------------------------------------------------------
void ofApp::draw(){
    int cellWidth = 6;
    int cellHeight = 6;

    for (int i=0; i<game.getCols(); i++) {
		for (int j=0; j<game.getRows(); j++) {
            cell thisCell = game.getCell(i, j);
			ofSetColor(150, 150, 150);
			ofNoFill();
			ofRect(i*cellWidth, j*cellHeight, cellWidth, cellHeight);
            if (thisCell.currState == true) {
				ofSetColor(thisCell.color.r, thisCell.color.g, thisCell.color.b);
				ofFill();
				ofRect(i*cellWidth, j*cellHeight, cellWidth, cellHeight);
				ofNoFill();
			}
		}
	}
}

Contact: [email protected]

ofxgameoflife's People

Contributors

bernardoaraujor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.