Circular Noise Creator mainly for NDEA versions
package make_noise;
import java.util.ArrayList;
/**
* Created by LENOVO on 25-10-2015.
*/
public class make
{
ArrayList<String> noise;
int h,k; // the centre for noise propagation
int r; //the radius of the intensity of the noise;
int arraywidth;
public make(int h,int k,int r,int arraywidth)
{
noise=new ArrayList<String>();
this.h=h;
this.k=k;
this.r=r;
this.arraywidth=arraywidth;
shout();
}
private void shout()
{
//function that computes the noise coordinates
for(int i=0;i<=r;i++)
draw_noise_at_level(i,1);
for(int i=r+1;i<=arraywidth;i++)
draw_noise_at_level(i,(i-r)+1);
filter();
remove_duplicates();
//for(int i=0;i<noise.size();i++)
//System.out.println(noise.get(i));
/* for(int i=0;i<noise.size();i++)
System.out.println(noise.get(i));*/
}
private void draw_noise_at_level(int level,int step)
// level signifies radius of the circle
// step signifies the number of bits to be left
// while the noise propagates
{
if(level==0) //not bothering if the radius is zero
{
noise.add(h+","+k);
return;
}
int x,y,xend;
xend=level/(int)Math.sqrt(2);
x=0;
while(x<xend)
{
y=(int)Math.sqrt(level*level-x*x);
noise.add((x+h)+","+(y+k));
noise.add((y+h)+","+(x+k));
noise.add((-x+h)+","+(y+k));
noise.add((x+h)+","+(-y+k));
noise.add((-x+h)+","+(-y+k));
noise.add((-y+h)+","+(x+k));
noise.add((y+h)+","+(-x+k));
noise.add((-y+h)+","+(-x+k));
x=x+step;
}
}
private void filter()
{
//function to remove the negetive
ArrayList<String> tmp=new ArrayList<>();
for(int i=0;i<noise.size();i++)
{
String[] array=noise.get(i).split(",");
int n1=Integer.parseInt(array[0]);
int n2=Integer.parseInt(array[1]);
if(n1>0 && n2>0)
{
tmp.add(noise.get(i));
//System.out.println(noise.get(i));
}
}
noise.clear();
for(int i=0;i<tmp.size();i++)
{
noise.add(tmp.get(i));
// System.out.println(tmp.get(i));
}
tmp.clear();
}
private void remove_duplicates()
{
//to remove duplicate noise coordinates
ArrayList<String> tmp=new ArrayList<String>();
int check;
for(int i=0;i<noise.size();i++)
{
String str=noise.get(i);
check=0;
for(int j=0;j<tmp.size();j++)
{
if(str.equals(tmp.get(j))==true)
{
check++;
}
}
if(check==0)
tmp.add(str);
}
noise.clear();
for(int i=0;i<tmp.size();i++)
noise.add(tmp.get(i));
}
public ArrayList<String> get_noise()
{
return noise;
}
}