int s=1; int IDcount=0; float shadeStart=0; static int shadeWidth=8; static int bord=5; static int backCol=#F0f0f0; static int borCol=#000000;//#EF7639; static int terCol=0xFFf0f0f0; static int inCol=0xCCFFFFFF; static int shadeCol=0xFFEF7639; class unit { int nodeloc; int dest; int force; int prog; int tot; } class node { int x, y; int allegiance; int count; int ID; ArrayList connected; node(int xi, int yi, int all) { x=xi; y=yi; connected=new ArrayList(0); count=0; allegiance=all; ID=IDcount++; } void connect(node n) { float linedist=dist(x, y, n.x, n.y); println("distance:"+linedist); for (int i=0; i101) { float angle=atan2(n.y-y, n.x-x); linedist=min(linedist/2, 100); if (newNode(x+floor(linedist*cos(angle)), y+floor(linedist*sin(angle)), 0)) { connect(nodes.get(nodes.size()-1)); sel=nodes.size()-1; println("new node"); } return; } connected.add(n); n.connected.add(this); } } boolean newNode(int x, int y, int all) { if (x<0||x>width||y<0||y>height)return false; for (int i=0; irad||dy>rad)return false; return dist(0, 0, dx, dy) nodes=new ArrayList(); boolean clicked=false; int sel=-1; int numSel=-1; void setup() { size(600, 600); noStroke(); fill(0); strokeWeight(5); newNode(300, 300, 0); newNode(50, 50, 1); //newNode(50,0,1); newNode(120, 10, 1); newNode(160, 95, 0); noCursor(); } void draw() { int w=width; int h=height; PGraphics territory=createGraphics(w, h); PGraphics border=createGraphics(w, h); PGraphics enemy=createGraphics(w, h); PGraphics white=createGraphics(w, h); PGraphics shade=createGraphics(w, h); //PGraphics lines=createGraphics(width,height); territory.beginDraw(); border.beginDraw(); enemy.beginDraw(); //lines.beginDraw(); territory.background(0); territory.fill(255); territory.noStroke(); border.background(0); border.fill(255); border.noStroke(); enemy.background(0); enemy.fill(255); enemy.noStroke(); /* lines.fill(0); lines.noStroke(); lines.textAlign(CENTER, CENTER); textSize(15); lines.background(0,0); lines.blendMode(REPLACE); */ for (int i=0; i49) { dragdist=min(dragdist, 100); float angle=atan2(mouseY-nodes.get(sel).y, mouseX-nodes.get(sel).x); if (newNode(nodes.get(sel).x+floor(dragdist*cos(angle)), nodes.get(sel).y+floor(dragdist*sin(angle)), nodes.get(sel).allegiance)) { nodes.get(sel).connect(nodes.get(nodes.size()-1)); sel=nodes.size()-1; println("new node"); } else { int click=-1; float best=30; for (int i=0; i