Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 7 months ago.
Game of Life Project
Hey,
I'm trying to display GoL on a N5110 screen using an LPC1768. However I'm having trouble with the code. i don'f fully understand how to implement the rules.
Any help would be much appreciated
This is what I have so far (not finished yet)
- include "mbed.h"
- include "N5110.h"
void plotArray(); void clearCells(); void checkerBoard(); void drawLine(); int getPixel(); void srand(); int nx = 84; int ny = 48; int n = 0; int width = 5; int height = 10; int fill = 1; void randomiseBuffer(); void drawCircle(int x0,int y0,int radius,int fill);
N5110 lcd(p5,p6,p7,p8,p11,p13,p21);
int main() {
lcd.init();
lcd.printString("Welcome to", 15,1); lcd.printString("Conway's", 20,2); lcd.printString("Game of Life", 6,3); lcd.printString("Bilal Saleem",0,5);
wait (3);
clearCells();
lcd.init();
lcd.printString("Please use", 15,1); lcd.printString("the potent", 10,2); lcd.printString("iometer", 10,3); lcd.printString("to vary ", 1,4); lcd.printString("the brightness",0,5);
wait (3);
clearCells(); lcd.randomiseBuffer(); lcd.drawCircle(10,20,10,0); lcd.refresh(); int getPixel(); checkerBoard();
while(1) {
} }
void clearCells() {
for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { lcd.clearPixel(i,j); } } lcd.refresh(); }
int getPixel (int i, int j) {
int n = 0; number of neighbours
if (lcd.getPixel(i-1,j-1)) pixel to top left n++; if (lcd.getPixel(i-1,j)) pixel to left n++; if (lcd.getPixel(i-1,j+1)) pixel to bottom left n++; if (lcd.getPixel(i,j-1)) pixel to top n++; if (lcd.getPixel(i,j+1)) pixel to bottom n++; if (lcd.getPixel(i+1,j-1)) pixel to top right n++; if (lcd.getPixel(i+1,j)) pixel to right n++; if (lcd.getPixel(i+1,j+1)) pixel to bottom right n++; return n; }
void checkerBoard() { loop through every other pixel and turn on pixel for (int i = 0; i < nx ; i+=2) { for (int j = 0; j < ny ; j+=2) { lcd.setPixel(i,j); }
} lcd.refresh(); }