Week 2: Life Under the Palm Trees

Inspiration:

I was sitting near the library when I looked out the window and saw palm trees. I associate them with this place, with summer, with happiness. I remembered how we decided to count them with my friend when we first arrived, and that there are exactly 36 palms. I liked the geometrical arrangement of palms, so I decided to use them as inspiration for my artwork.

 

 

 


 

Process:

I stylized the palms into swirling lines of varying heights using the random function and the for loop to arrange these strokes into a circle. To make them dynamic, I used the rotate function. In order to understand how they work, I watched this video-tutorial.

I divided the screen into identical rectangles, I used two for loops, placed the spinning palms and their trunks in the form of circles there.

It was necessary to do something with the background, and I wanted to add an interactive part. I watched this video to understand how it works. I decided to make a pattern using arc functions, which, if reduced, resembles a tile on the ground, and if increased, it looks like benches located under palm trees. The way the size changes seemed very symbolic to me, and that’s why I called this work “Life under the palm trees”.


Result:


Code:

//ART WORK

float arcSize = 80;
float yStep = 100;


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

void draw() {
  
  background(224, 224, 224);

  mouseX = constrain(mouseX, 10, width);
  mouseY = constrain(mouseY, 10, height);

  yStep = mouseY;
  arcSize = mouseX;

  noFill();
  stroke(160, 160, 160);
  strokeWeight(5);

  for (int y=0; y<height; y+=yStep) {
    for (int x=0; x<width+arcSize; x+=arcSize) {
      arc(x, y, mouseX, mouseY, 0, TWO_PI);
    }
  }
  
 //grid 

  for (int i=-50; i<width+50; i+=100) {
    for (int j =-50; j<height+50; j+=100) {
      noStroke();
      rectMode(CENTER);
      rect(i, j, 100, 100);
      fill(153, 76, 0);
      ellipse(i, j, 20, 20);
      noFill();
      pushMatrix();
      translate(i, j);
      scale(0.25);

  //palms 

      stroke(76, 153, 0);
      for (int a=0; a<360; a+=1) {
        float x = random(30, 80);
        float y = random(80, 130);
        pushMatrix();
        rotate(radians(a));
        strokeCap(ROUND);
        strokeWeight(4);
        line(x, 0, y, 0);
        popMatrix();
      }
      popMatrix();
    }
  }
}

 

week 2 Using Loops

Inspiration and process

The second week project is related to loops. I decided to work with rectangles, but at first tried to make the pattern strictly ordered. At this particular moment I got an idea about the color to make each rectangle different to each other. 

Then I changed my mind and decided to play with haotic order of the objects drawing on this template from Computer_Graphics_and_Art_May1976

The final result you can watch in this video, the speed of rectangles is not so fast, so we can follow display order of the objects.

The final result is the second one. It can looks like messy as the colors are randomly in background, stroke and rectangles. That is way at first try I commented some part of the code to follow the behavior of the objects.

Code

The code seems to be very short and easy, but I spent a lot of time trying to come to the result I wanted. The one problem I faced is color. First I declared 3 global variables each as a random number and then used them in the background() function, fill() and stroke() in different order to get different combinations of color. This caused the problem that each rectangle was the same color as previous. The solution is to repeat colors inside the loop.

float r=random(0,200);
float g=random(0,200);
float b=random(0,200);

  void setup() {
  size(640, 480);
  background(g,b,r);
  frameRate(1.6);
  
}
  void draw() {
  for (int x = 0; x < width; x += 10) {
    
      float y=random(height);
    //rw is rectangle weight
      float rw=random(80);
      float r=random(8,200);
      float g=random(7,200);
      float b=random(9,200);
      stroke(b, r, g);
      fill(r,g,b);
      rect(x, y, rw, rw, 10);
    //noLoop(); 

    }}

 

I feel like this project is not really interactive, but after the video “ Casey Reas’ Eyeo talk on chance operations” I was really fascinated with random function and played more with varieties of colors.

 

 

 

 

 

kinda art [week 2]

For this assignment of the week, I had an inspiration to recreate Bob Ross’s paintings of the forest. So it’s a great mixture of tall creepy, out-of-nowhere trees and mesmerizing mountains drawn at the back with the reflection of this all being translated on the surface of the water.

Bob Ross style paintings by Kevin Brooks - Back to Bob! Had fun doing this painting again, 2 hours well spent 😊👍 | Facebook

Even though it’s not that tidy, I love how the shape of the tree is chaotic and saved from both up and down when you have no background set.

 

float rotate=0;
float r=0;
color forest= color(128,128,0);

void setup() {
  size(1020,640);
  colorMode(HSB,255);
  
}

void draw(){

  stroke(forest);
  
  for (float x=0; x<width; x+=1){
    point(x,height*noise(x/100, rotate));
  }
  //stroke(forest);
  //for (float x=0; x<width; x+=3){
  //  point(x,height*noise(x/200, rotate),50);
  //}
  //stroke(forest);
  //for (float x=0; x<width; x+=5){
  //  point(x,height*noise(x/300, rotate),10);
  //}
  
  rotate+=0.01;
}

 

but once you put the background to any color, it doesnt save the previous drawings of that line, which is not smth i’m looking for.

next thing i wanted to draw a river by the forest, for that i drew line instead of points and gave stroke color with 4 arguments in it, 4th one being the alpha that gives the transparance from 0 to 255.

when you have no background line of water overwrites itself and covers the previous forest lines, so it’s a clash of two.

However, when I tried to add the background it reminded me of the waves by the seashore, so lovely, soothing, and relaxing.

IMG_3625 

That’s when I decided to go with this idea of imitating sea waves on a sunny day.

float rotate=0;
float r=0;
color forest= color(128,128,0);
color water= color(100,149,237);
void setup() {
  size(1020,640);
  
  
}

void draw(){
  
  background(255,238,161); 
 

  for (float x=0; x<width; x+=1){ 
    stroke(255);
    line(x,height/2+150*noise(x/500, rotate), x, height);
  } //layer1 of wave
  for (float x=0; x<width; x+=1){  
    stroke(water);
    line(x,height/2+200*noise(x/500, rotate), x, height);
  }//layer2 of wave
 
  
  rotate+=0.01;
}

 

Week 2 sufferings

Inspiration that is way out of my league

I am fascinated by the fact that these organic snake is actually a code and not a hand drawn artwork. Overall, the idea of making or attempting to make organic shapes from loops sounds very appealing to me!

I was doing my ellipse loop with the help of “for” function from Processing.org site. I was trying to figure out what each thingy in a bracket meant and manipulated them accordingly. I managed to get a very beautiful loop of circles all the way down to the screen and wanted to make them turn so its similar to a snake. So, I decided to try rotate function. I added it to the code and the image below happened.

I lowkey considered leaving it like this, because it looked pretty :D, but then reality hit me and I had to do some other stuff.

And after these painful screenshots of doing everything and at the same time nothing:

Aruzhan Temirgaliyeva Week 2 Intro to IM  –  press here to see the painful three screenshots I managed to make while suffering on this awful abomination that I cant even call a code. No, this is on the same level as omg why do I have such a poor time management

I came to this final product:

  1. I decided to create a clock since I couldn’t figure out how to make an angular transition of a loop to resemble that  snakes movement and bending;
  2. I created 4 lines of ellipse loops using “for” and “noise” function;
  3. I played around with coordinates to make them align properly;
  4. I found Youtube video on how rotation and angles were made and decided to try it, since there still was a lot of hope I had for making a snaky bending thingy (foolish me);
  5. I tried the code, however couldn’t incorporate it with ellipses and make two separate loops connect.
  6. So I just lost hours understanding that the coordination system is like a paper. How, when you translate you change the coordinates not of the shape but of the grid and the paper itself. How popMatrix saves the coordinates and push returns them to their original state and so on.
  7. Then I just added as far as I could understand the lines and another ellipse to the center of the clock in order to finish of the whole image.
  8. And using lerpColour added gradient between 2 colours so it looked pretty!
//the coordination system is like a piece of paper
//VELOCITY = change in position over time
// ACCELERATION = change in velocity over time
// angle is an angular position, not a vector, single number
float b = 0;
float s = 0;
float a = 0.0; // a is some angle
float aVelocity = 0.0; // angular velocity's some amount
float aAcceleration = 1;
int fromC;
int toC;
int interA;
int interB;

void setup() {
  size(1100, 700);
} 

void draw() {
  background(255);
  stroke(1);
  fromC = color(255,200,200);
  toC = color(230, 0, 0);
  interA = lerpColor(fromC, toC, 0.33);
  interB = lerpColor(fromC, toC, 0.66);

  //ellipse width down
  for (int i=0; i<width; i+=1) {
    s = s + 1;
    float x = noise(s);
    x = map(x, 0, 1, 0, 1100);
    fill(fromC);
    ellipse (x, 600, 50, 50);
  }
  //ellipse height right
  for (int i=0; i<width; i+=1) {
    b = b + 1;
    float x = noise(b);
    x = map(x, 0, 1, 0, -685);
    rotate(PI/2);
    fill(fromC);
    ellipse (x, 1000, 50, 50);
  }
  //ellipse height left
  for (int i=0; i<width; i+=1) {
    b = b + 1;
    float x = noise(b);
    x = map(x, 0, 1, 0, -685);
    rotate(PI/2);
    fill(interA);
    ellipse (x, 50, 50, 50);
  }

  //ellipse width up
  for (int i=0; i<width; i+=1) {
    s = s + 1;
    float x = noise(s);
    x = map(x, 0, 1, 0, 1100);
    fill(interB);
    ellipse (x, 50, 50, 50);
  }
  //god bless the coding train guys
  aAcceleration = map(mouseX, -0, width, -0.001, 0.001);
  a+= aVelocity; //velocity changes its position
  aVelocity += aAcceleration; // velocity changes acceleration
  translate(500, 350);
  rotate (a);
  line(0, 0, 100, 200);
  translate(100, 100);
  fill(toC);
  ellipse(-100, -100, 100, 100);
}
Conclusions and lessons to be drawn:
  • If you think you can do it, you cant;
  • If you have a couple hours to do a week’s work, shame on you and no chocolate for you, life is bitter when you have poor time management;
  • Computer rooms are cold;
  • God bless guys from YouTube channel “The Coding Train” and professing.org;
  • My work fits the meme about”Expectations VS. Reality” :’)
Reference list:
  • https://py.processing.org/reference/lerpColor.html
  • https://www.youtube.com/watch?v=8ZEMLCnn8v0&list=PLRqwX-V7Uu6bgPNQAdxQZpJuJCjeOr7VD&index=8
  • https://www.youtube.com/watch?v=YcdldZ1E9gU&list=PLRqwX-V7Uu6bgPNQAdxQZpJuJCjeOr7VD&index=2
  • https://www.youtube.com/watch?v=qMq-zd6hguc

Art-Work using Loops

INSPIRATION AND EXECUTION

My second week’s project was to create an artwork using loops. Although this sounded very exciting to me initially and I was all charged up to work for it, it took me a long time to think about what I actually wanted to make. Art is relative. There is nothing fixed nor definite. It is one’s imagination driven by creativity and inspiration. I could do anything; the topic was so open-ended that it was difficult to come up with an idea.

I read through some old computer art magazines and was very fascinated by the following picture from the book Computer_Graphics_and_Art_May1976  (p. 6):

“Random Squares” by Herbert Franke

This picture, though simple, conveys the beauty of different blocks co-existing and still being peaceful in chaos. I wanted to create something similar in my art piece which could evoke such a feeling. Thus I started playing with squares on my canvas. To give an effect of chaos, I decided to have squares of different sizes to begin with and then make them move somehow, or rather change their size, to depict the different sizes as seen in the picture above. There was a little problem when I first coded this (see below). Since my width of the rectangle was dependent on frame count, it seemed like the rectangles were growing and shrinking faster and faster with each iteration which created a sense of panic or anxiety rather than calmness.

I solved this using the sine function which gave me a value between 1 and -1 and hence made it easier to reverse direction without affecting the speed (prof. Aaron Sherwood helped me with this). The consistency looked much better and pleasing. It also gave a smooth transition for changing direction. I then decided to add colors in the shades of blue and red to give a bright, happening, yet calming effect (not choosing pastel colors because the sense of chaos and happening still had to be maintained).

However, I still wasn’t fully satisfied with what I was seeing. The white spaces left a void that I wanted to cover. So, I started playing with background colors. In doing so, I accidentally removed the background altogether and what I saw, very well captured the emotion I was trying to bring about. The colors from different origins, each being startling and bright, having their own individuality, growing and shrinking in size, blended with each other so beautifully, producing a soothing effect in its dynamism. I then just tweaked the speed and colors a bit after that to make it look just right.

This is how my final art piece has turned out!

DIFFICULTIES

Besides facing difficulties controlling the speed of my moving boxes, I faced some difficulties initially when coding my boxes. It took me some time to understand how to use loops to code this project. What I was missing was the understanding that whichever loop I use inside my draw() function, would be an additional loop to the draw() loop which is an infinite loop. So, the way to go about it was thinking of it as ‘nested loops’ and exploiting the draw() loop to base the movement of my boxes on it. I first used nested for() loop to position my boxes on the canvas. Then, to move the boxes, I based the rectangle width on the frame count of the draw() loop. It took me sometime to understand that the transition should be based on the draw() loop count because I am not used to thinking of functions as loops and thus initially, I wasn’t using the draw() loop at all to code my assignment.

CODE

float h, w; //to rename height and width
float rectW; //size of square -- changes throught the exxecution
float rectW0; //initial square size
int numBox; //number of boxes

void setup()
{
  background(150);
  size(600, 600);
  h = height;
  w = width;

  rectMode(CENTER);
  rectW = 100;
  rectW0 = rectW;
  numBox = int(w/rectW0);
  //noLoop();
}

void draw()
{
  noFill();
  strokeWeight(0.3);

  int k=0;
  for (int i=0; i<numBox; i++)
  {
    for (int j=0; j<numBox; j++)
    {
      stroke(250-(i+j)*30, (0*i+j)*30, (i+j)*20);
      rect(rectW0/2+rectW0*i, rectW0/2+rectW0*j, rectW-k, rectW-k);
      k=k-1;
    } //close inner for
  } //close outer for
  
  rectW = sin(frameCount*.008)*width/2.2; 
}

[Week 2] Recreating computer art

The assignment for week 2 involves using for() and/or while() loops to create a work of art. I looked through the sources of computer arts and they are very fascinating. I particularly like this following art and decided to try and recreate it with Processing.

My workflow for this piece is as following:

  1. Create the basic construction of grid-like squares (which makes good use of loops)
  2. Add interaction by randomizing the movement of the squares according to mouse movement
  3. Extra: experiment with colors

My final product is the following and the code can be found at the end of this post:

Basic construction

The grid-like foundation of the art is pretty straightforward and problem-free. I use two nested for() loops to draw the rectangles.

Interactive movement

To create the randomized movements of the squares, I make extensive use of the random() function.

Randomizing the shifting of the squares (moving slightly in the horizontal and vertical direction) is also straightforward, but I ran into an issue when trying to slightly rotate the squares. The rotate() function is usually used in tandem with translate() because the shape will be rotated relative to the origin. The problem is that translate() only gets reset after each loop of draw(), so when I want to rotate all of the squares within a single draw() loop, the positions of the squares are mixed up because they get translated further and further from the initial origin.

I found that a good solution to this issue is to use the pair of functions pushMatrix() and popMatrix(). Using these two functions to enclose translate() and rotate() ensures that the coordinate system is restored to its original state before the next square is drawn, making sure all the squares are correctly positioned and rotated.

I also want to have some user interaction with the art so that as the user moves the mouse around the canvas, the closest squares to the mouse will have greatest movements. For this, I use the dist() function to calculate how far a square is from the current mouse position and give each square a distFactor based on the calculated distance. This distFactor will then be used to calculate rotatingFactor and movingFactors to decide the movements of the squares. With this, the piece of art is finished.

Extra: Coloring

I add an extra function to the code so that when the user clicks on the canvas, coloring mode will be on and instead of black border with no fill, the squares will have no border and random colors. The coloring mode part has nothing to do with recreating the original art; I just want to experiment around with random() and colors.

Code

int numOfSquares = 15;
int mouseRadius = 3;
int squareSize;
float movingRange;
boolean colorOn = false;

void setup() {
  frameRate(10);

  size(900, 900);
  squareSize = width/numOfSquares;
  movingRange = squareSize*.1;
  rectMode(CENTER);
}

void draw() {
  background(255);

  for (int i=squareSize/2; i<width; i+=squareSize) {
    for (int j=squareSize/2; j<height; j+=squareSize) {
      float distance = dist(i, j, mouseX, mouseY);
      float distFactor = 1/distance * 100;
      if (distance > squareSize*mouseRadius) {
        distFactor *= .01;
      }
      float rotatingFactor = random(-PI/10, PI/10) * distFactor;
      float movingFactorX = random(-movingRange, movingRange) * distFactor;
      float movingFactorY = random(-movingRange, movingRange) * distFactor;
      
      if (colorOn) {
        noStroke();
        color squareColor = color(random(0, 255), random(0, 255), random(0, 255));
        float alpha = map(distance, 0, width, 0, 255/2);
        fill(squareColor, alpha + random(-10, 10));
      }
      else {
        noFill();
        stroke(0);
      }
      pushMatrix();
      translate(i+movingFactorX, j+movingFactorY);
      rotate(rotatingFactor);
      rect(0, 0, squareSize, squareSize);
      popMatrix();
    }
  }
}

void mouseClicked() {
  colorOn = !colorOn;
}

 

Cole Beasley – Loop Art

Overview:

This week’s task was to make some sort of artwork from the types of loops we had learned in class this week (for() and while()). To give us some inspiration, we were given some magazines on early forms of computer generated art coming out of the 1980s and 90s. Google searches yielded lots of examples to choose from in addition. Many were reminiscent of old Windows screen savers, and often featured bright colors. My favorite of several were the fractals that came up. Some were fairly simple, and others were complex using tricky mathematical formulas. I decided to go ahead and try one that pushed me to understand hard mathematical concepts such as imaginary numbers, and see if I could translate to Java.

Mandelbrot Set:

The Mandelbrot Set is a set of complex numbers that for each complex number, ‘c‘, does not diverge when the value for ‘z’ is iterated in the below formula.

This math was tricky for me as it involved the revolution around a point in a complex plane. Luckily this topic is well documented and this page had great explanations and even a sudocode algorithm to get me started in plotting the phenomena.

I was able to convert the code into similar Java code, and then make changes so that processing could do what it needed.

Problems:

Besides complex math formulas, some problems that were tricky to overcome included converting values to colors on a scale to iterate through with a loop, and a self created extra challenge of animating a zoom functionality to better demonstrate the fractal’s impressive effects.

To translate the value of the algorithm to color in processing, I had to use map() to take a wide range of numbers and make it understandable to a color value. I also decided to use HSB color as it would allow me to use a single variable that could be iterated for hue, rather than three separate values for RGB. This was new to me and took some experimentation to get right.

For zooming, it took me a long time to figure out how to scale to a certain coordinate in the plane, while not distorting in the width or height directions. Eventually I derived the formula on line 38,39 of the code below which involves taking the width and height times a zoom factor with the correct offsets.

Code:

The code for this took several attempts to get right. The initial variables defined are mostly for the animation of the zoom, but also include adjustable parameters for the formulas. I utilized the timeout algorithm which provides a good approximation if a number is or is not in the set. This value could be adjusted to make to the depiction more detailed, at the expense of computational difficulty. I then initialize a workspace with a 1.333 aspect ratio, and set the color mode to HSB for the reasons described previously. I then begin looping. Using nested for loops I iterate over each pixel in the graphic and determine its timeout value using the above mathematical process in a loop. With the timeout value ranging from 0-timeout max value, with 1000 being the one used in this instance, these values need to map to a hue. Since anything above the max timeout value is considered part of the set, they are assigned black, otherwise the value is mapped reversely onto a range from red to violet.

//PSEUDOCODE TAKEN FROM WIKIPEDIA ESCAPE TIME ALGO
//x0 := scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
//y0 := scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
//x := 0.0
//y := 0.0
//iteration := 0
//max_iteration := 1000
//while (x*x + y*y ≤ 2*2 AND iteration < max_iteration) do
//  xtemp := x*x - y*y + x0
//  y := 2*x*y + y0
//  x := xtemp
//  iteration := iteration + 1
    
//color := palette[iteration]
//plot(Px, Py, color)


int WIDTH;
int HEIGHT;
int maxIteration = 10000;  //level of detail
float zoom = 0;  //Can't zoom much past 100,000
float xOffset = 0.004; //(-1 - 1) (-1 zooms in on far left edge, 1 on far right)
float yOffset = -.1; //(-1 - 1) (-1 zooms in on top edge, 1 on bottom)   (0.004, -0.1 is an interesting cord set)

void setup() {
  size(1066, 800);
  WIDTH = width;
  HEIGHT = height;
  colorMode(HSB, 360);
}

void draw() {
  background(0);
  for (int i = 0; i < WIDTH; i++) {
    for (int j = 0; j < HEIGHT; j++) {
      //float x0 = map (i, (zoom*WIDTH/2), (WIDTH-((WIDTH/2)*zoom)), -2.5, 1);
      //float y0 = map (j, (zoom*HEIGHT/2), (HEIGHT-((HEIGHT/2)*zoom)), -1, 1);
      float x0 = map (i, (-WIDTH*zoom)-(xOffset*zoom*WIDTH), (zoom*WIDTH)+WIDTH-(xOffset*zoom*WIDTH), -2.5, 1);
      float y0 = map (j, (-HEIGHT*zoom)-(yOffset*zoom*HEIGHT), (zoom*HEIGHT)+HEIGHT-(yOffset*zoom*HEIGHT), -1, 1);
      float x = 0.0;
      float y = 0.0;
      int iteration = 0;
      while(x*x + y*y <= 2*2 && iteration < maxIteration){
        float xtemp = x*x - y*y + x0;
        y = 2*x*y + y0;
        x = xtemp;
        iteration++;
      }
      if(iteration == maxIteration){
        stroke(0, 0, 0);
      }
      else{
        float hue = map(iteration, maxIteration, 0, 0, 255);
        stroke(hue, 360, 360);
      }
      point(i, j);
    }
  }
  if(zoom == 100000){
    noLoop();
  }
  if(zoom == 0){
    zoom++;
  }
  //println("ran");
  zoom = zoom * 10;
}

Results:

I am happy with how these images came out. It took a lot of time and tweaking of the code but the results were as I was hoping. I played with certain variables such as level of detail at higher levels, and quickly ran out of memory to work with. At high details the variables for the math become so large that they can’t really be stored or have no rounding errors.

Other Recursion Tests:

I enjoyed making this example of a fractal and went forward trying more simple images using polar coordinates and recursion. This one did not use any loops however so it does not count directly for this assignment, just a fun example. I played with some randomization to try and make it look more realistic too.

 

//Recursion parameters
int maxIterations = 9; //Number of iterations

//Tree parameters
int angle = 30; //Angle the branches spread;
float treeStroke = 5; //Starting stroke line
float treeStrokeShrink = 0.5; //Fraction lost every time
float percentDestroy = 1.0; //0-1 how much shorter the branches get with each iteration, 1 is 100%, 0 is no chance
float shorteningPercent = 0.75; // 0-1, How much shorter the branches get
float branchLength;

//Drawing variables

void setup() {
  size(1000, 800);
  branchLength = height/4;
}

void draw() {
  drawTree(0, maxIterations, width/2, height, branchLength, 270, treeStroke);
}

// Iteration that its on, max iterations, x, y, length of line, stroke size
void drawTree(int i, int m, float x, float y, float l, float o, float s){
  translate(x,y);
  
  // Convert polar to cartesian
  float x1 = l * cos(radians(o));
  float y1 = l * sin(radians(o));
  
  // Draw the line and set stroke
  strokeWeight(s);
  line(0, 0, x1, y1);
  
  //Recursion
  if(i < m){
    float randOne = random(0,1);
    if(randOne < percentDestroy){
      pushMatrix();
      drawTree(i + 1, m, x1, y1, l*shorteningPercent, o+angle, treeStroke*treeStrokeShrink);
      popMatrix();
    }
    float randTwo = random(0,1);
    if(randTwo < percentDestroy){
      drawTree(i + 1, m, x1, y1, l*shorteningPercent, o-angle, treeStroke*treeStrokeShrink);
    }
  }
  noLoop();
}

 

Conclussions:

I enjoyed this weeks tasks and pushed myself to try something new to me. It made the assignment more challenging and more rewarding when it finally worked out the way I was hoping. The variables and iterative programming allowed me tot week the code and write minimal amounts once I had an algorithm that worked.

 

 

Week 2: Using For Loops

This week, I’ve been feeling a lot of chaotic energy with balancing my professional commitments, class deadlines, friends, capstone, and job interviews. Thus, I wanted my sketch to reflect the seemingly segmented aspects of my life going a bit berserk.

Processing Sketch of colored squares within squares tiled across sketch

Because the squares ended up moving so quickly and brightly, I wanted to make the default option be a paused version of a sketch with the option to play in case the quick movements bothered anyone. Thus, I ended up adding a pause and play button. I had considered just using a space bar to toggle between pause and play, but wanted to use more visual instructions.

Video of Sketch (Warning: Bright Flashing Lights)

My code is pretty straightforward. I created a function that created each “tile.” I didn’t want each tile to be uniform so I randomly changed the color and number of internal squares when drawing each tile. From there, I simply used a double for loop to create the grid of tiles.

I used an array of colors to store my palette which I created using coolors.co (my go to palette inspiration site).

Something I messed up and fixed: originally, I created a String array, having the hex colors in strings. However, this was not compatible with the fill method so after looking at the Processing documentation, I realized that color was a data type in Processing and was able to create an array using the color primitive.

If I were to repeat this sketch creation again, I would try to avoid having so many nested for loops and do the mousePressed function in a less hard-coded way.

Here’s my code!

//color palette
color[] colors = {#8ac4ff, #7e7f9a, #4FB286, #F3DE8A, #Eb9486};
boolean pause = true;

void setup() {
  size(500, 500);
  rectMode(CENTER);
  //play button
  triangle(width/6, height -50, width/6,  height - 20, width/4.5, height-35);
  fill(colors[0]);
  //pause button
  rect(width/10, height - 35, 5, 30);
  rect(width/10 - 10, height - 35, 5, 30);
  //title
  textSize(20);
  fill(0);
  text("Senior Year", width/3 * 2, height - 35);
}

void draw() {
  //looping through width
  for (int i = 40; i < width; i += 60) {
    //looping through height
    for (int j = 40; j < height- 50; j += 60) {
      drawSquare(i, j);
    }
  }
  //sketch starts paused
  if(pause) {
    noLoop();
  }
}

 void drawSquare(int x,int y) {
  int w = 5;
  //changes number of internal squares within a tile
  float count = random(5,9);
  //picks a color randomly from palette
  color c = colors[int(random(colors.length))];
  fill(c);
  rect(x,y, 10 * w, 10 * w);
  for (float i = count; i > 0; i--) {
    fill(c);
    rect(x,y, i * (count/1.5), i* (count/1.5));
  }
}

void mouseClicked() {
  //if pause button is clicked, toggle button colors and stop loop
  if(mouseX < (width/10 + 5) && mouseX >= (width/10 -15) && mouseY > height - 50 && mouseY <= height -20) {
    pause = true;
    fill(255);
    triangle(width/6, height -50, width/6,  height - 20, width/4.5, height-35);
    fill(colors[0]);
    rect(width/10, height - 35, 5, 30);
    rect(width/10 - 10, height - 35, 5, 30);
    noLoop();
    //if play button is clicked, toggle button colors and start loop

  } else if (mouseX > width/6 && mouseX <= width/4.5 && mouseY > height - 50 && mouseY <= height -20) {
    pause = false;
    loop();
    fill(colors[0]);
    triangle(width/6, height -50, width/6,  height - 20, width/4.5, height-35);
    fill(255);
    rect(width/10, height - 35, 5, 30);
    rect(width/10 - 10, height - 35, 5, 30);
  }
}
  
  

 

1st week – shae not shae

 

Shaikha Alshehhi

Professor Aaron Sherwood

Assignment 1: Self-Portrait

January 25, 2021

Masterpiece (not really) :

 

Objective:

1. To practice the usage of basic processing functions.

2. To explore the functionalities that processing offers

3. To have fun!

 

What I did: 

The plan was to draw a vampire using the tools learned in class. I wanted to take a step further and use functions we did not take. I used the arc function for the mouth and hair. The ellipse functions helped with the eyes, face and blush. I used the circle function for the pupils and the triangle function for the hair. I tried putting on eyelashes, but I was not able to work the eyelashes of the left eye so I erased it :'(

 

 

Code:

size (640, 480);

//background(0, 0, 119);

//face shape
fill(255, 249, 242);
strokeWeight(2);
ellipse(width/2, (height/2)-16, 175, 187);



//left eye
fill(255);
ellipse(275, 210, 35, 20);
fill(0);
circle(275, 210, 10);
fill(255);
circle(274,208, 4);


//right eye
fill(255);
ellipse(360, 210, 35, 20);
fill(0);
circle(360, 210, 10);
fill(255);
circle(359,208, 4);

//hair
fill(0);
triangle(280, 125, 360, 125, 320, 200);
triangle(285, 140, 240, 150, 260, 220);
triangle(240, 140, 240, 300, 200, 305);

triangle(355, 140, 400, 150, 380, 220);
triangle(400, 150, 400, 300, 440, 305);



stroke(0);
fill(0);
arc(320, 165, 173, 135, radians(200), radians(340), CHORD);


triangle(240, 140, 280, 140, 240, 190);
triangle(400, 140, 360, 140, 400, 200);

//nose
line(width/2, 215, (width/2)-5, 245);
line((width/2)-5, 245, width/2, 245);



//teeth
line(290, 270, 300, 280);
line(300, 280, 310, 270);

line(345, 270, 335, 280);
line(335, 280, 325, 270);

//mouth
fill(0,0);
arc(318, 270, 85, 65, 0, PI, 30);
line(275, 270, 360, 270);




//blush right
noStroke();
fill(200, 67, 110, 100);
ellipse(270, 240, 35, 20);
//blush left
noStroke();
fill(200, 67, 110, 100);
ellipse(365, 240, 35, 20);

 

Green

void setup() {
  size(640, 480);
};

void draw () {

  background(60, 100, 55);

int MainFaceX = width/2;
int MainFaceY = height/2;
int FaceSize = 300;

  //mainhead
  fill(255);
  ellipse(MainFaceX, MainFaceY, FaceSize, FaceSize);

  //lefteyeball
  fill(255);
  ellipse(FaceSize-50, MainFaceY-40, FaceSize-200, FaceSize-200);

  //right eyeball
  fill(255);
  ellipse(MainFaceX+80, MainFaceY-40, FaceSize-200, FaceSize-200);

  //mouth
  noFill();
  arc(350, 300, 50, 50, 0, HALF_PI);

  //pupil right
  fill(0);
  ellipse(MainFaceX-70, MainFaceY-40, FaceSize-250, FaceSize-250);

  //pupil left
  fill(0);
  ellipse(MainFaceX+80, MainFaceY-40, FaceSize-250, FaceSize-250);
};

Spend a lot of time to remember which part is what variable, what it affects and how to do properly the line and coordination of everything.

the version I liked the best


#when you have to look discreetly at someone

confusing code:

  • deletes the line, eyeballs and mouth

smooth();
noStroke();
fill(255,0,0);
beginShape();
vertex(50, 15);
bezierVertex(50, -5, 90, 5, 50, 40);
vertex(50, 15);
bezierVertex(50, -5, 10, 5, 50, 40);
endShape();

https://www.processing.org/discourse/beta/num_1246205739.html - credit