// Snake Charmer, Aaron Steed 2006 // Architectural snakes using the BFS algorithm to find food and endlessly grow // Processing 118 import processing.opengl.*; import aStarLibrary.*; AStar aStar; int cubeSize; float cubeScale, x, y, z; Snake [] snake; Egg egg; PFont font; int [] dim, hDim; float [] spin = { 0.0, 0.01, 0.02, 0.03, 0.05, 0.03, 0.02, 0.01}; int s = 0; int realSize; void setup() { size(600, 450, OPENGL); frameRate(24); cubeSize = 40; cubeScale = width/cubeSize; aStar = new AStar(); aStar.wrap = true; aStar.bfs = true; aStar.offset = new float [] { -cubeScale * cubeSize / 2, -cubeScale * cubeSize / 2, -cubeScale * cubeSize / 2}; dim = new int [] { cubeSize, cubeSize, cubeSize}; aStar.makeCuboidNodes(dim, cubeScale); realSize = aStar.nodes.size(); snake = new Snake[4]; int [] colTable = new int [] { color(255), color(230, 40, 40)}; for(int i = 0; i < snake.length; i++){ Node n = null; while(n == null){ n = (Node)aStar.nodes.get((int)random(aStar.nodes.size())); if(!n.walkable){ n = null; } } snake[i] = new Snake(n, 10, colTable[i%colTable.length], cubeScale); } egg = new Egg(); x = y = z = 0.0; } void draw(){ //scale(2.0); smooth(); background(255); ambientLight(100, 100, 100); directionalLight(150,150,150,0,0,-1); translate(width/2, height/2); if(!mousePressed){ rotateX(x); rotateY(y); rotateZ(z); } else{ rotateY((TWO_PI / width) * mouseX); rotateX((TWO_PI / height) * mouseY); } x = (x + spin[s]) % TWO_PI; y = (y + spin[(s + 1) % spin.length]) % TWO_PI; z = (z + spin[(s + 2) % spin.length]) % TWO_PI; if(random(1.0) > 0.95){ s = (s + 1) % spin.length; } egg.draw(); for(int i = 0; i < snake.length; i++){ snake[i].draw(); } }