//taken from // //in this version of the A* algorithm I'm constantly updating the path. The bot moves to //the first step in the projected path, the whole path and closed nodes are drawn simply to //illustrate the algorithm Pathfinder pathfinder; PFont font; int xstep, ystep; void setup(){ size(400,400); framerate(6); pathfinder = new Pathfinder(10, 10, 1, 1); pathfinder.setBot(0, 0, 0); pathfinder.setTarget(0, 9, 9); for(int i = 0; i < pathfinder.wide; i++){ for(int j = 0; j < pathfinder.high; j++){ //create random filled blocks if(j > 1 && j < pathfinder.high - 2 && i > 1 && i < pathfinder.wide - 2 && random(1) < 0.3){ pathfinder.setGrid(i, j, -1); } } } xstep = width / pathfinder.wide; ystep = height / pathfinder.high; font = loadFont("AppleGothic-10.vlw"); textFont(font, 10); } void draw(){ smooth(); background(255); drawGrid(); drawTargets(); drawBots(); Vec2 temp = pathfinder.bestVec2(0, 0); pathfinder.setBot(0, temp.x, temp.y); drawBestVec2(temp); drawLists(); drawPath(); } //if a key is pressed, fill in an element on the grid void keyPressed(){ for(int i = 0; i < pathfinder.wide; i++){ for(int j = 0; j < pathfinder.high; j++){ if(mouseX / xstep == i && mouseY / ystep == j){ if(pathfinder.grid[i][j] == -1){ pathfinder.setGrid(i, j, 0); } else { pathfinder.setGrid(i, j, -1); } } } } } //if the mouse is pressed move the target to that location void mousePressed(){ pathfinder.target[0].x = mouseX / xstep; pathfinder.target[0].y = mouseY / ystep; }