Hi everyone ,
My name is Whiteclaws , and I'm new here , this my fifth try at the Diamond-Square algorithm , and I feel like it's time to ask for some help , p.s; I started learning Java yesterday , so take it easy on me ( the last 4 tries were on a drag n' drop engine )
I know what is the problem , but I don't know how to fix it !
Basically , this ;
package Array.Generation.DiamondSquare; public class DiamondSquare { public static void main(String []args){ // Size 2n+1 int n = 8 ; //DO NOT CHANGE int Size = 2^n+1 ; //Creating Basic Array (l*l) {L} double[][] Array = new double[Size][Size]; //Initialise array /* SEED tl tr * * * * * bl br */ double tl = 0.5 ; double bl = 0.2 ; double tr = 0.8 ; double br = 0.4 ; // Putting Values (X , Y) Array[0][0] = tl ; Array[0][Size-1]= bl ; Array[Size-1][0]= tr ; Array[Size-1][Size-1]= br ; int Space = Size ; //Start of the loop while(Space > 1) { Space = Space/2 ; for(int y = 0 ; y != (Size/Space)-1 ; y++) { for(int x = 0 ; x != (Size/Space)-1 ; x++) { //Square Array[x+Space][y+Space] = Array[x][y]+ // Top Left Array[x+Space*2][y]+ // Top Right Array[x][y+Space*2]+ // Bottom Left Array[x+Space*2][y+Space*2]/4 ; // Bottom Right //Diamond /* Left + o | - + | Sum all the + and divide by 3 to get - ! + o | */ Array[x][y+Space]= Array[x][y]+ Array[x+Space][y+Space]+ Array[x][y+Space*2]/3; /* Right o + | + - | Sum all the + and divide by 3 to get - ! o + | */ Array[x+Space*2][y+Space]= Array[x+Space*2][y]+ Array[x+Space][y+Space]+ Array[x+Space*2][y+Space*2]/3; /* Up + - + | + | Sum all the + and divide by 3 to get - ! o o | */ Array[x+Space][y]= Array[x+Space*2][y]+ Array[x+Space][y+Space]+ Array[x][y]/3; /* Down o o | + | Sum all the + and divide by 3 to get - ! + - + | */ Array[x+Space][y+Space*2]= Array[x+Space*2][y+Space*2]+ Array[x+Space][y+Space]+ Array[x][y+Space*2]/3; } } } } }
Is my last try , and it's working for 2 , but otherwise , it's throwing an error of outbound
Any ideas on how to fix this
Cheers !