Categories

L-Train: CODE: Processing Homework

CODE: Processing Homework

Creating a pattern using “for” loop

 

I have used “for” loop to create a pattern. It has 3 parts:

  1. The background: a gradient which changes on changing the values of mouseX (moving the mouse horizontally)
  2. A pattern of ellipses in the center
  3. A pattern of rectangles which rotate on moving the mouseX. The movement takes place only on the borders.

 

Video link: Akshansh_For_Loop_Video_Processing

 

 

 

Here is the code for the same:

//Creating a box pattern using for loop

void setup () {
size(800, 800);
}

 

void draw () {

//creating a background pattern
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
noStroke();
fill(x, y, mouseX);
rect(x, y, 1, 1);
}
}
noFill();
stroke(0);

//Creating an ellipse over the background
for (int a=20; a<width; a+=100) {
for (int b=20; b<height; b+=100) {
ellipse(width/2, height/2, a, b);
}
}

//Creating a rectangle over the background
translate(width/2, height/2);

for (int a=20; a<width; a+=75) {
for (int b=20; b<height; b+=75) {
rotate(mouseX);
rectMode(CENTER);
rect(width/2, height/2, a/3, b/3);
}
}
}

No Comments

Leave a Comment: