xxxxxxxxxx
111
var grid;
function preload(){
grid = loadJSON('data.json');
}
function setup() {
console.log(grid);
coord = grid.coord;
createCanvas(400, 400);
var xstep = 25;
var ystep = 18;
var terskel = 30;
for (var i = 0; i < coord.length; i++){
var thisX = coord[i][0];
var thisY = coord[i][1];
var thisZ = coord[i][2];
var avgZ;
if (i < xstep || (i > (coord.length - xstep) ) || (i % xstep == 0)||(i % xstep == xstep-1)){ //"på kanten"
if (i < xstep){ // SJEKK NEDERSTE RAD
if (i == 0){
var z = coord[i+xstep+1][2];
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
else if( i == xstep-1){
var z = coord[i+xstep-1][2];
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
else{
var z = coord[i+xstep+1][2];
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
} // SLUTT NEDERSTE RAD
else if(i > coord.length-xstep){ // ØVERSTE RAD
if (i == coord.length+1-xstep){ //første punkt på øverste rad 425
var z = coord[i+1-xstep][2]; //401
if (Math.abs(thisZ - z) > terskel){
coord[i][2] = z;
}
}
else if (i == coord.length){ //siste punkt på øverste rad 449
var z = coord[i-xstep-1][2]; //423
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
else { //alle andre punkt på øverste rad
var z = coord[i-xstep][2]; //423
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
} // SLUTT PÅ ØVERSTE RAD
else { //alle andre rader
if (thisX == coord[i-1][0]){ //siste punkt i raden
var z = coord[i-1][2];
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
else{ // Første punktet i raden
var z = coord[i+1][2];
if (Math.abs(thisZ - z) > terskel){
coord[i][2]= z;
}
}
} // Slutt på alle andre rader
} // Slutt på "if på kanten"
} // slutt på for
}
function draw() {
background(255,0,0);
textAlign(CENTER);
fill(255,255,255);
stroke(0);
textSize(80);
translate(height/2, width / 2);
text('loading...',0,0);
noLoop();
}