Assignment 2: The Persian Rug Mistake

The concept

Rugs have always amazed me. As a kid I remember zoning out and into the finite loops of perfection, thinking about the elaborate patterns, the subtle details, and the mesmerizing color palettes that bring so much life to our house. There is, however, one intentional, imperfect stitch in every traditional handwoven, otherwise perfect rug. Muslim artists honor the ‘Persian rug mistake’ as a reminder that only Allah is capable of creating perfection.

My generative artwork is inspired by rug patterns [which includes many unintentional flaws].

rug pattern example
Rug pattern example

Code highlight

Lots of loops, lots of functions, and a little bit of OOP.

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
class Rectangle {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.height = 500;
    this.width = 4;
  }
  
  move(m) { 
    this.m = m;
    rotate(angle);
    
    if (freeze_flag == 1) {
      rotate(angle);
      angle += m;
    }
  }
  
  show(fill_color, stroke_color) {
    this.fill_color = fill_color;
    this.stroke_color = stroke_color;
    fill(fill_color);
    stroke(stroke_color);
    rect(this.x, this.y, this.height, this.width);
  }
}

function Dandelion(x, y) { 
  
  // number of rectangles
  for(i=0; i<70;i++) {
    dandelion = new Rectangle(x,y);
    
    if(reverse_flag == 1) {
      dandelion.show("#87CEEB", 10);
    } else {
      dandelion.show("#f4c2c2", 10);
    }
    // you can control the speed of rectangles by changing the argument
    dandelion.move(0.0001);
  }
}

function draw() {
  if(reverse_flag == 1){
    background("#f4c2c2");
  } else {
    background("#87CEEB");
  }
  
  //this is where i want the rectangle to rotate from which is the center
  translate(width/2, width/2);
  // translate(300, 300);
  rectMode(CENTER);
  
  Dandelion(0,0);
  Dandelion(0,100);
  Dandelion(0,150);
  // Dandelion(0,200);
  // Dandelion(0,250);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

Embedded sketch

Here is my pattern, using only rectangles.

Two of my saved patterns:


Reflection and ideas for future work or improvements

I would love to use more elaborate patterns by defining more classes of geometrical shapes and adding more layers/colors. I would also probably not use the move() function because when many layers are involved the constant movement of the objects are not very kind to the eyes. I think choosing a good color palette and getting the right width and height for the shapes would enhance the pattern significantly. There are lots of opportunities to make the work more interactive e.g. letting the user pick the geometrical shapes, control the size of different objects, try out different color combinations, etc.

sunset under the palms

This artwork got inspired by a sunset drive two days ago. The view looked so pretty so I thought of recreating it through p5.js.

I started with drawing the palm trees using while() to have them all line up in the same line. I drew the leaves using arcs and lines.

//palm trees 
  while (x < width) {
    stroke(149, 99, 71);
    strokeWeight(1.6);
    fill(136, 96, 77);
    rect(x, 53, 5, 45);
    noFill();
    stroke("green");
    strokeWeight(1);
    line(x + 5, 50, x + 20, 30);
    line(x, 50, x - 20, 30);
    line(x, 50, x + 20, 30);
    line(x - 3, 50, x + 15, 35);
    arc(x + 32, 70, 90, 70, PI, PI + QUARTER_PI);
    arc(x + 20, 70, 90, 70, PI, PI + QUARTER_PI);
    arc(x + 45, 55, 90, 100, PI, PI + QUARTER_PI);
    arc(x + 45, 55, 90, 120, PI, PI + QUARTER_PI);
    arc(x + 43, 50, 90, 40, PI, PI + QUARTER_PI);
    arc(x + 20, 70, 70, 40, PI, PI + QUARTER_PI);
    x = x + 50;
  }

I also wanted to create a sunset animation with a circle moving as the sun and the moon appearing slowly. To create a more night effect, I also added stars and it slowly disappears by dawn.

let sunX = 100;
let sunY = 50;
let sunset = 0;

fill("yellow");
  circle(sunX, sunY, 50);

  //sun moving
  if (sunY < height + 20) {
    sunX = sunX + 3;
    sunY = sunY + 1;
    sunset = sunset + 3;

 //moon
fill(255, sunset);
circle(460, 30, 40);

The final result:

I really liked playing with loops and variables (global & local). For improvements, I would like to add more background objects (clouds, grass..) and play with more functions and loops.

Aisha – Loop Art

Before working on my assignment I decided to keep practicing with loops to get myself comfortable with it. Once I did I began brainstorming some ideas and after doing research for inspiration I committed to an idea.

As a background, I  used a for loop to add a pattern of multiple small lines to give a sort of grainy feeling to this piece of work. After I accomplished this, I used Jeff Thompson’s video on youtube to help me with the animation of the squares. I placed the larger square in the center and had a global variable ‘angle’ that made the shape continuously rotate. After this, I created two rings of squares around the initial square. However, instead of keeping it in the center, I made it move around as well as rotate. I’m not going to lie this wasn’t intentional I was just experimenting and I ended up liking it. This is the piece of code I’m most proud of:

// ring of squares rotating
 for (let a=0; a<radians(360); a+=radians(30)) {
   push();
   translate(140,140);   
   rotate(a);   // rotate each by 30º
   translate(0, 80);  // puts it around the center square
   rotate(-angle);  // rotate the other way
   fill(random(0), random(255), random(255), random(255));
   rect(0,0, 25);
   pop();
 }

 for (let a=0; a<radians(360); a+=radians(30)) {
   push();
   translate(140,140);   
   rotate(a);               
   translate(0, 120);             
   rotate(-angle);                 
   fill(random(0), random(255), random(255), random(255));
   square(0,0, 20);
   pop();
 }

My sketch:

 

Improvements for next time:

– What I wanted to do but couldn’t achieve in this assignment was change the colors by mousePressed. So next time I’d really like to achieve this.

-I’d also think I should slow down the framerate a bit as the colors are changing too quickly and could cause a headache if you look at it for a long time.

Loops

Concept 

My initial design wanted to consist offer piece that is resembled modern art. I was trying to find loop designs to inspire what I had in mind. I decided to go with this piece of art since the lines dropping from the top kind of symbolize a cage. While the rain that flows shows the idea of gloominess that I was going for. the ball in the middle is vibrant and is just going back and forth Finally escapes the screen. The ellipses on top and on the bottom are constantly Still in the background I placed randomly put ellipses.  so while the majority of the painting remains constant there is always something in the background that’s different for every individual.

Methodology 

Firstly, I created the function for the ellipses I used in the background. Then I use the draw function to create both the lines and the rain. Additionally, I created the moving ellipses and give it the coordinates on where to start and stop and I did not want it to blend in with the background rather to create a line to show its path I kept in the print code I used to just give a bit of word play to the art piece

Things I Could Improve On

I initially wanted the rain pattern to go fall not only they diagonally to the right but also the diagonally to the left. I also wanted the major ellipses in the middle to have an opposing one falling from top to bottom. I was thinking of also making more ellipses Forming an X shape but I thought that would ruin the piece.

Digital art

Concept:
For this assignment, I practiced a lot with the new features and made different digital artworks, just to try and play with all the different features and possibilities of loops. Thus, looking at different patterns, I remembered stained glass windows. Stained glass is a special kind of monumental and decorative art. .Stained-glass windows can be considered transparent paintings, drawings, patterns made of glass or on glass.
In the process of getting to know “loop” I discovered the random() function (which is my favorite due to its unlimited possibilities). Before getting to the idea itself, I played around with different shapes and “for” loops.

I tried to recreate like a stained glass picture. As a base, I took an autumn illustration from the internet and uploaded it into my code, after which I created something similar to a stained glass painting using the “for” loop. There were some tutorials from “The Coding Train” and a couple of other sources that I found helpful(https://www.youtube.com/watch?v=ig0q6vfpD38
https://www.youtube.com/watch?v=V56cH9R_X4k).

Reflections&future improvements:
I think that this task helped me a lot to understand correctly the work of for loop, random(), role of each variable and the importance of deep analysis before work. With more experience and practice, I hope to create similar interactive patterns with animations. For example, so that different stained-glass windows change when clicked. In the next works, I want to learn more advanced animations, like creating moving waves (in the form of patterns. )

Assignment 2: Work of Art with Loops

Concept

In this assignment, I decided to come up with a simple work of art that represents in some way a great board game that I like to play. Whenever I play chess, I feel that I get detached from this world and find myself in a completely different place. In that new place, I try to find the best strategies to win the game and while doing so I get drowned in my thought. Therefore, I believe that this drawing would show part of the experience I face while playing chess.

In the above drawing, I used squares of a repeating nature to be able to design a chessboard. On top of this board, I added a series of circles with a common center across the different parts of the chessboard. I wanted through these circles to visualize the kind of thought process and confusion that a chess player faces during the game. These circles form a whirlpool which is like what happens to me when my opponent plays a strong move in the game that puts me into a whirlpool of confusion.

Furthermore, I added these wavy-looking lines to the drawing to make it more appealing. I believe that these lines represent the line of thought of a chess player who tries to think about his next five moves before playing his current move. In addition, these lines look like a sound wave that is usually used as a means of communication between two people. This is because I find chess as a way for people’s minds to communicate without them even talking. I was very happy to be able to come up with these wavy lines, you can find the code for these lines attached below.

Code for drawing wavy lines

To draw the lines in this way I used two nested for loops and I began by drawing a point, the x-coordinate of this point increments by a value of 5 each iteration. While the y-coordinate is dependent on the x value as I used a sin function to control the position of the points in the next iterations. Using only one for loop I would have been able to come up with only one wavy line. However, to come up with these lines along the whole canvas I decided to use another for loop that controls the vertical translation of the sin function.

Possible Improvements

 

I was so satisfied to come up with this artwork and was not expecting it to look this way when I first thought about it. However, I believe that this drawing needs a bit more work to look better and more satisfying for the viewer. I feel that by looking at the drawing for a long time the viewer might find it confusing. Therefore, to make it look better to the eye I might decrease the number of lines intersecting each other in the drawing. In addition, by adding animation to the waving lines and being able to come up with spiral-looking whirlpools instead of circles I might be able to deliver my message in a better way.

Assignment 2: Loop Art

Concept

For this project, I was inspired by figure skating ice, where many patterns are left by the blades of skates from jumps, spirals, and spins. I decided to make an art pattern that resembles the after-spin effect like in this video:https://www.youtube.com/watch?v=ss_3secVE_c

I also wanted to make an effect of ice flakes during the interaction of blade and ice, so there are mini circles going around.

For the execution of the code, I used the tutorial for making spirals(https://www.youtube.com/watch?v=wSNYOYlRsBE) and made loops out of them.

Code Snippets

Code for spiral loops

var angle  = 0.0;
var offset = 10;
var scalar = 1;
var speed = 0.01;   

function draw() {
  for(let i=10;i<=width; i=i+50){
    stroke(153,204,255);
    var x = offset + cos(angle) * scalar;
    var y = offset + sin(angle) * scalar;
    ellipse(x + i, y+ i,1,1);
    angle += speed;
    scalar += speed;  
  }
}

I also was playing with bezier and spiral formula, but combining them together went chaotic, so I only left the formula and a funny string tornado appeared:

Reflections

For future improvements, I would like to add user interactions where users could point out where the spiral starts. Also, I want to learn to work with frames for more fun animations. I also understood that a lot of animations require the usage of complex formulas and trying iterating code again and again. That’s why, I really want to untangle this complex process.

 

Week 2: ‘Rhythm and Chaos’: An Attempt at Generative Art

The idea:

For our second assignment we were tasked to create a generative art piece using loops in p5js. For me, art has always been a creative expression which is not strictly restricted to visual perception. One of my favorite art forms (and the one I spend the most time indulging in) happens to be music. So I wanted to incorporate music into this assignment from the get go. This is what I ended up creating after long hours of working this weekend. A simple click and it comes to life!

The process:

I started by looking up the Coding Train‘s videos (of course!) for incorporating music into my p5js file. I found about the preLoad() function which helped me upload and play one of my favorite tracks, ‘La Cuidad’ by Odezsa right inside the browser.

Next I knew I wanted to create something that would respond to the music. After a bit of searching Dan Shiffman from the Coding Train came to the rescue again. I spent an entire day learning about Fourier Transforms and the built in FFT object from this video and the reference page on p5js’s site:

This taught me how to display waves based on amplitude, frequency of the music. To make it more visually appealing I used for loops and played around with trigonometric functions (sine and cosine) to transform the straight line of waves into a circle. This gave me a half circle and I had to repeat the for loop with a negative value of sine to get a full circle. I’m sure there must be a more efficient way to do this, but this is how far my brain cells could go. I also used map() function with help from the reference page (and a lot of trial and error) to keep the waves within the bounds of the canvas. You’ll notice most of the values are hard-coded so this of course is an area I could improve on.

When I listen to music, it almost transports me to a different realm; I feel lost and immersed but in a good way. With a day to go till the deadline, I wanted to incorporate some of that feeling into this piece. And what better than getting lost in a star field in space?! As a form of habit I searched up ‘Star Field Coding Train’ on YouTube (God bless Dan Shiffman). I watched this video but it was full of advanced functions and most it flew past my ears. I do, however, know how to create classes (I did that for my first assignment too). So, I created a class for the stars and since I am familiar with vectors, velocity, and acceleration from high-school Physics, I read into the reference pages in p5js and figured out how to make stars fly towards the screen from the resting circumference of the circle. Here’s a code snippet of the class:

class Star {
  constructor() {
    //a fixed scalar multiple for uniform visual effect
    this.start = p5.Vector.random2D().mult(150);
    //vector for initial velocity
    this.velocity = createVector(0, 0);
    this.acceleration = this.start.copy().mult(random(0.001, 0.00001));
  }

  move(check) {
    this.velocity.add(this.acceleration);
    this.start.add(this.velocity);
    if (check) {
      // adding more speed if the .getEnergy method returns higher frequencies, by just adding more of the same method
  this.start.add(this.velocity).add(this.velocity).add(this.velocity);
      // this.start.add(this.velocity);
      // this.start.add(this.velocity);
    }
  }
  //stars i.e. ellipses of random sizes
  display() {
    noStroke();
    fill(255, 255, 255);
    ellipseMode(CENTER);
    ellipse(this.start.x, this.start.y, random(2, 5));
    // console.log(this.start.x, this.start.y);
    // line(this.start.x,this.start.y,(this.start.x + 1),(this.start.y + 1));
  }
}

Another part of the code which I like is using the .getEnergy() method of the FFT object to increase the velocity of the stars depending on the frequency of the track. I created a boolean statement to return True or False if the music crossed a certain frequency. If True, I increased the velocity by repeating the velocity method.

//FFT methods
let waves = fft.waveform();
fft.analyze();
//star speed responding to beats
let bounce = fft.getEnergy(20, 200);
let p = new Star();
stars.push(p);

  for (i = 0; i < stars.length; i += 1) {
    stars[i].move(bounce > 230);
    stars[i].display();
  }

Things to improve on:

The star field Dan Shiffman demonstrated was more beautiful, and stars had a trailing and fading effect to them. I think I can spend more time trying to learn all those functions for future projects. Also, a lot of the conditions in the for loops are hard coded, which I will try to improve on for future projects.

Outro:

For finishing touches, I randomized the R,G,B values of the stroke color and the stroke weight to create a vibrant sense of chaos. I think when the piece comes to life, this will give the audience a sense of rhythm within chaos, which music brings to my life every single day.

Assignment 2: Art Patterns Using Loops

My idea was to create a spiraling pattern of mini-circles that change color when the user moves the mouse. This idea was motivated by the milky way galaxy that appears in a spiral form.

The Milky Way Galaxy | AMNH

After thinking through several ways to color the patterns, I ended up changing the colors by random and at the same time with the movement of the mouse pointer. The code for the coloring is shown below:

The embedded sketch of the assignment:

Reflections:

It’s interesting how the frame rate changes the perception of the art. I will explore the different frame rates and how they affect my perception of the design. Also by changing the angle of the circles and the speed at which they change, the design changes in many different ways. I will most likely explore the different designs by changing the angle and speed.

Assignment 2

Concept

I was inspired by Case Reas’ talk and his showing of Jared Tarbell’s Invader Fractal. The concept that the contrast in a group of squares could trick the brain into perceiving different shapes was intriguing to me. I wondered if increasing the complexity of artwork such as Fractal invaders could trick our perception into making more complicated constructions out of random arrangements. What if I changed the colors used? Or the frame rate? I tried to answer these questions through the assignment.

Implementation
//Fucntion to draw a quadrat of fractals
function drawfractals_1(c1, c2){
  //Nested for loops used to create rectangles for each row 
  for (let j=0; j<4; j++){
    for (let i=0; i<4; i++){
      //array to select integers from
      let bin_array = [0,1];
      //selects randomly from 0 or 1
      let r_num= random(bin_array);
      //fills with black if random number returned is 0
      if (r_num == 0){
        fill(c1);
        rect(i+(50*i), j+(50*j), sq_width, sq_height);
      }
      //fills with white if random number returned is 1 
      else {
        fill(c2);
        rect(i+(50*i), j+(50*j), sq_width, sq_height);
      }
    }    
  }
}

This part of the code is the function that generates one section of the random squares. It creates a random pattern by choosing whether the color will be dark or light through an binary array passed through the random() function.

Embedded sketch

Here the fractals or images are created by splitting the sketch into 4 quadrants which generate on their own a random pattern. Every iteration also has a random chance of possessing a different complimentary color combination.

I also thought that making the sketch go blank when clicked on would help someone refocus and find shapes in the patterns formed.

Reflection and ideas for future work or improvements

After staring at the patterns generated for hours, I have realized that it is probably the greater simplicity in the original fractal invaders artwork, which mirrors the pattern generated on half of the sketch to the other half, that creates some sort of meaning in our minds. I am slightly disappointed by the bulkiness and inefficiency of the code as it has multiple functions carrying out the the same process, on the same type of object. Here I can overcome the issue by using a class for the square. This would have allowed me to manipulate the randomness and animation of the squares and overall artwork much easier.