summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kauerz <akauerz@gmail.com>2012-04-27 17:57:04 +0200
committerAlexander Kauerz <akauerz@gmail.com>2012-04-27 17:57:04 +0200
commit88c86f6cf634f5bf7ff797f0e54f486445ab2b95 (patch)
tree85503712992485168a3f3eeda1643051d2d22f01
parentc35542703af7dc50241da217ce00f15e787ab979 (diff)
downloadledmatrix-master.tar
ledmatrix-master.zip
Langtons Ant impementiert.HEADmaster
-rw-r--r--Matrix_9x14/Ant/Ant.cpp107
-rw-r--r--Matrix_9x14/Ant/CMakeLists.txt27
2 files changed, 134 insertions, 0 deletions
diff --git a/Matrix_9x14/Ant/Ant.cpp b/Matrix_9x14/Ant/Ant.cpp
new file mode 100644
index 0000000..0fb7f13
--- /dev/null
+++ b/Matrix_9x14/Ant/Ant.cpp
@@ -0,0 +1,107 @@
+/*
+Langtongs Ant
+Eine Kooperationsarbeit von Kristof und Alexander
+Version: 0.1
+*/
+
+#include <Arduino.h>
+#include <Charliplexing.h> //Imports the library, which needs to be
+ //Initialized in setup.
+
+#define DELAY 10 //Sets the time each generation is shown
+#define SIZEX 14 //Sets the X axis size
+#define SIZEY 9 //Sets the Y axis size
+#define DIRECTIONS 4 //Defines the amount of dircetions possible
+bool world[SIZEX][SIZEY][2]; //Creates a double buffer world
+long density = 25; //Sets density % during seeding
+
+enum direction {
+ NORTH,
+ EAST,
+ SOUTH,
+ WEST
+};
+
+struct Ant {
+ int x;
+ int y;
+ direction orientation;
+} ant;
+
+void step(){
+ switch (ant.orientation) {
+ case NORTH: ant.y=(ant.y+1)%SIZEY;
+ break;
+ case EAST: ant.x=(ant.x+SIZEX-1)%SIZEX;
+ break;
+ case SOUTH: ant.y=(ant.y+SIZEY-1)%SIZEY;
+ break;
+ case WEST: ant.x=(ant.x+1)%SIZEX;
+ break;
+ }
+}
+
+void turn(){
+ ant.orientation=(direction)((world[ant.x][ant.y][0])?
+ (((int)ant.orientation)+DIRECTIONS-1)%DIRECTIONS :
+ (((int)ant.orientation)+1)%DIRECTIONS);
+}
+
+void toggle(){
+ world[ant.x][ant.y][0]=!world[ant.x][ant.y][0];
+}
+
+
+void cycle(){
+ step();
+ turn();
+ toggle();
+}
+
+//Re-seeds based off of RESEEDRATE
+void seedWorld(){
+ randomSeed(analogRead(5));
+ for (int i = 0; i < SIZEX; i++) {
+ for (int j = 0; j < SIZEY; j++) {
+ if (random(100) < density) {
+ world[i][j][1] = 1;
+ }
+ }
+ }
+}
+
+void setup() {
+ LedSign::Init(); //Initilizes the LoL Shield
+ ant.x = (SIZEX/2);
+ ant.y = (SIZEY/2);
+ ant.orientation = NORTH;
+
+ randomSeed(analogRead(5));
+ //Builds the world with an initial seed.
+ for (int i = 0; i < SIZEX; i++) {
+ for (int j = 0; j < SIZEY; j++) {
+ world[i][j][0] = 0;
+ world[i][j][1] = 0;
+ // world[i][j][0] = 0;
+ }
+ }
+}
+
+
+
+void loop() {
+
+ cycle();
+
+ for (int x = 0; x < SIZEX; x++) {
+ for (int y = 0; y < SIZEY; y++) {
+ LedSign::Set(x,y,world[x][y][0]);
+ }
+ }
+
+
+ delay(DELAY);
+}
+
+
+
diff --git a/Matrix_9x14/Ant/CMakeLists.txt b/Matrix_9x14/Ant/CMakeLists.txt
new file mode 100644
index 0000000..114e686
--- /dev/null
+++ b/Matrix_9x14/Ant/CMakeLists.txt
@@ -0,0 +1,27 @@
+#=============================================================================#
+# Author: QueezyTheGreat #
+# Date: 26.04.2011 #
+# #
+# Description: Arduino CMake example #
+# #
+#=============================================================================#
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) # CMake module search path
+set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Arduino.cmake) # Arduino Toolchain
+set(ARDUINO_LINKER_FLAGS "-lc -lm")
+set(ARDUINO_SDK_PATH ${CMAKE_SOURCE_DIR}/../../arduino-1.0)
+
+cmake_minimum_required(VERSION 2.8)
+#====================================================================#
+# Setup Project #
+#====================================================================#
+project(Langtons_Ant)
+find_package(Arduino 1.0 REQUIRED)
+
+set(FIRMWARE_NAME Ant)
+
+set(${FIRMWARE_NAME}_SRCS Ant.cpp)
+set(${FIRMWARE_NAME}_BOARD uno)
+set(${FIRMWARE_NAME}_LIBS m )
+set(${FIRMWARE_NAME}_PORT /dev/ttyACM0)
+
+generate_arduino_firmware(${FIRMWARE_NAME})