InitGraph(); rows=31;cols=47; ScaleWindow(0, 0,cols+1, rows+1); Colour(Black); BoxFill(0,0,cols+1,rows+1); pic=new Array(cols+1);marked=new Array(cols+1); for(var i = 0;i<=cols;i++){ pic[i]=new Array(rows+1);marked[i]=new Array(rows+1); } var white = true, black = false; var yellow = "yellow"; var d, i, j, il, jl, istep, jstep, xold, yold; var lightest=100, darkest=100, greyline100, fade=1; var trail=0, straight=0, diff=0, kk=false; var here=false, beenthere=false; var thresh = 5; //1024 / cols * 4; vi=new Array(1, 1, 0,-1,-1,-1, 0, 1); vj=new Array(0, 1, 1, 1, 0,-1,-1,-1); //directions N, NE etc. function Spot () { c = pic[i][j]; ColourRGB(c,c,c); BoxFill (i - .5, j - .5, 1, 1); } function Dot(p, q) { LineStart(p+.5, q+.5); } function hop (x) { y = x & 7; istep = vi[y]; //N/S component of direction y jstep = vj[y]; //E/W component of direction y i = i + istep; if (i > cols){i = 0;}; if (i < 0){i = cols - 1;}; //new i, correct if off the edge j = j + jstep; //new j, correct if off the edge if(j > rows){j = 0;}; if (j < 0){j = rows - 1;}; } function Look (x) { //move in direction x and look at new point var r; hop (x); l = pic[i][j]; //value of new point if (l > greyline) { //compare with mid level r=white; Colour(Red); Dot(i,j); //red dot if lighter }else{ r=black; Colour(Green); Dot(i,j); //green dot if darker } //update lightest and darkest to track extremes, //fading together slowly if(l>lightest){lightest=l;}else{lightest=lightest-fade;}; if(l
thresh){return r}else{return here;}; //if too flat return same as last time } function notepoint() { //middle of last step if(marked[i][j]) {beenthere = true;}; marked[i][j]=true; Colour(yellow); Dot(i - istep / 2, j - jstep / 2); if(kk){ if(Math.abs(i - xold) + Math.abs(j - yold) < 4){ LineTo(xold, yold); } //draw a line from old point } xold = i +.5 - istep / 2; //remember old point yold = j +.5 - jstep / 2; kk = true; trail = -4; //allow turns } function turn (x) { trail = trail + 1; //how far since last edge? straight = straight + 1; //how far since last turn? if(8 * straight > trail){ //if far enought then d = (d + x) & 7; //turn in direction x straight = 0; //and restart counting from turn } } //Set up picture with a diamond on shaded ground m=(rows+cols)/2; for (i = 0;i<=cols;i++){ for (j = 0; j<=rows;j++) { p = Math.abs(i - cols/2); q = Math.abs(j - rows/2); if ((p+q)