I want to have both codes but i cant :(
One code is using a (while)loop and the other is the pattern maker code.
This is my pattern maker code. By using this way I get to control each rectangle in my pattern and I have added a random factor (xi,yi) to it to get structure and structured noise/noise. I can do this by adding xi to the x co-ordinate of my code in rect and adding yi to the y co-ordinate of my code in rect. I can keep adding both of these to each of my rect codes and get a noise as a result.
Here is the code:
int xRepeat = 150;
int yRepeat = 150;
int x = 20;
int y = 20;
int w1 =40;
int a = 10;
int b = 10;
int bw = b+w1+b;
void setup() {
size(500, 500);
smooth();
background(255);
for (int i = 0; i < width/xRepeat; i++) {//loop 1 repeats pattern in the x direction.
for (int j = 0; j < height/yRepeat; j++) {//loop 2 repeats the entire rows vertically.
pushMatrix();//saves untransformed co-ordinates
translate(xRepeat*i, yRepeat*j);// translates the entire coordinate system (is what causes the same thing to be drawn in different places).
myPattern();
popMatrix();//reverts to the saved co-ordinate system that we created using pushMatrix()
}
}
}
void draw() {
}
void myPattern() {
float ix = random(-100,100);
float iy = random(-100,100);
rect(x+a+w1,y+a+w1,bw,bw);
rect(x,y,a,a);
rect(x+a+w1+bw+w1,y,a,a);
rect(x,y+a+w1+bw+w1,a,a);
rect(x+a+w1+bw+w1,y+a+w1+bw+w1,a,a);
rect(x+a,y+a,w1,w1);
rect(x+a+w1+bw,y+a,w1,w1);
rect(x+a,y+a+w1+bw,w1,w1);
rect(x+a+w1+bw,y+a+w1+bw,w1,w1);
rect(x+a+w1+b,y+a,w1,w1);
rect(x+a,y+a+w1+b,w1,w1);
rect(x+a+w1+b,y+a+w1+bw,w1,w1);
rect(x+a+w1+bw,y+a+w1+b,w1,w1);
}
void mousePressed(){
save("image1.jpeg");
}
And this is my (while) loop code. By using this code I can get some extreme structures and especially noise. But I don't think I'll be using this code for my final project.
Here is the code:
int xRepeat = 150;
int yRepeat = 150;
int x = 20;
int y = 20;
int w1 = 40;
int a = 10;
int b = 10;
int bw = b+w1+b;
void setup() {
size(500, 500);
smooth();
background(255);
float i = (random(1));
while(i < 10){
rect(random(500),random(500),x,x);
rect(random(500),random(500),y,y);
rect(random(500),random(500),w1,w1);
rect(random(500),random(500),a,a);
rect(random(500),random(500),b,b);
rect(random(500),random(500),bw,bw);
i = i+0.1;
}
}
void draw(){
}
void mousePressed(){
save("image 1.jpeg");
}
No comments:
Post a Comment