this is the part of the program I want to multithread
int W = 1200,H = 600,threads = 2;
Grid g;
void settings(){
size(W,H);
};
void setup(){
g = new Grid(W,H,10);
//thread(new g).start;
};
void draw(){
background(0);
g.spawn();
fill(255);
text(frameRate,100,200);
};
class Grid{
float w,h,scale,seed = 10,x,y,freq = 1,amp = 1;
int res,cols,rows;
float [][] map;
Grid(float W,float H,int Res){
cols = int(W/Res);
rows = int(H/Res);
res = Res;
map = new float[cols][rows];
scale = 0.05;
seed = 10;
noiseSeed(int(seed));
};
Grid(float X,float Y,float W,float H,int Res){
x = X;
y = Y;
cols = int(W/Res);
rows = int(H/Res);
res = Res;
scale = random(10);
map = new float[cols][rows];
scale = 0.05;
};
void spawn(){
//x = mouseX-W/2;
//y = mouseY-H/2;
amp = map(mouseY,0,height,1,2);
freq = map(mouseX,0,width,1,2);
if(scale<=0)scale = 0.0001;
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
float yy = scale*i*freq;
float xx = scale*j*freq;
noStroke();
float height = map(noise(xx,yy)*amp,0,1,0,255);
color col = 0;
if(height>50)col = color(0, 0, 153);
if(height>100)col = color(204, 204, 0);
if(height>150)col = color(51, 153, 51);
if(height>200)col = color(102, 102, 153);
fill(col);
rect(j*res,i*res,res,res);
}}
//fill(255);
//text(amp,100,210);
};
};
I was hoping to be able to split the for loop into the number of threads I wanted to use.