Recitation 7: Functions and Arrays

Gucci Array practice (Because the initial color looks very gucci-ish).

Step 1:

//rec 7, gucci
star[] star;
color bg = #000300;

void setup(){
  size(800, 800);
  star = new star[50];
  for (int i = 0; i< star.length; i++){
    star[i]=new star();
  }
}

void draw(){
  background(bg);
  for (int i = 0; i< star.length; i++){
    //star[i].display();
    star[i]. grid();
  }
}

Inside the class star:

class star{
  color fg = #00620F;
  color ct = #AA3F00;
  float x;
  float y;
  float diameter= 50;
  
  
  //void display(){
  //  noStroke();
  //  fill(fg);
  //  ellipse(x, y, diameter, diameter);
  //}
  
    void grid(){
    for (int x = 0; x<width; x= x+60){
      for (int y = 0; y < height; y= y+60){
        strokeWeight(2);
        fill(fg);
        ellipse(x, y, diameter, diameter);
        strokeWeight(2);
        fill(ct);
        ellipse(x, y, diameter/2, diameter/2);
      }
    }
  }
  
}

In this step I found out using a class system is much more organized for me than an array, since I want all of them to be the same. In my understanding it is better to alter specific elements within a group, therefore I only included array but did not focus on using array to build the program.

Preview: 

Step 2:

I then made my circles change color while the overall scale is changing, here is the code.

//rec 7, gucci
star[] star;
color bg = #000300;

void setup(){
  size(800, 800);
  star = new star[50];
  for (int i = 0; i< star.length; i++){
    star[i]=new star();
  }
}

void draw(){
  background(bg);
  for (int i = 0; i< star.length; i++){
    //star[i].display();
    star[i]. grid();
    //star[i]. changeColor();
  }
}

 Inside the class[star]:

螢幕錄製 2021-11-08 下午5.58.28

class star {
  int fg = 25;
  color ct = color(random(255), random(255), random(255));
  ;
  int x;
  float y;
  float diameter= 50;
  int changeColor = 1;
  int changeSize = 5;
  int changeRatio = 5;
  //int changeSize= 5;



  //void display(){
  //  noStroke();
  //  fill(fg);
  //  ellipse(x, y, diameter, diameter);
  //}

  void grid() {
    for (int x = 0; x<width; x= x+60) {
      for (int y = 0; y < height; y= y+60) {
        strokeWeight(2);
        colorMode(HSB);
        fill(fg, 100, 100);
        ellipse(x, y, diameter, diameter);
        strokeWeight(2);
        fill(ct);
        ellipse(x, y, diameter/2, diameter/2);
      }
      if (fg>=100 || fg<=0) {
        changeColor = -changeColor;
      }
      fg = fg+changeColor;
      if (diameter >= 60|| diameter<=0){
        changeSize = -changeSize;
      }
      diameter = diameter+ changeSize;
    }
    if (x >=60 || x<=0){
      if (y >= 60 || y <=0){
        changeRatio= -changeRatio;
      }
      changeRatio =x+changeRatio;
    }
  }
}

I actually struggled a little bit on how to let the size of each circle change, I first created a new function in class star (As you can see its called change color), but then I failed, because I notice the two circles are sharing value x and y. So I simply added 3 if loops in the grid function, so it can have animation.

  • Q1: In the reading “Art, Interaction and Engagement” by Ernest Edmonds, he identifies four situations in an interactive artwork: ‘Static’, ‘Dynamic-Passive’, ‘Dynamic-Interactive’ and ‘Dynamic-Interactive(Varying)’. From the exercise you did today which situations you identify in every part you executed? Explain.
    • I personally think todays exercise is dynamic passive, but not completely applicable. It depends, if I add mousePressed or keyPressed, it could also apply to Dynamic interactive. The reason why I think this exercise is Dynamic-Passive is because the program, or “internal mechanism” according to Ernest Edmonds, is the loops I wrote within the program. Due to the loops, the program will change when it detects specific data reaches a threshold. The reason why I think it doesn’t apply totally as “dynamic-passive” is because there is not external factors that can alter the look of the piece. Such as human interaction, or sensors that detects temperature, sounds, pressure..etc. But it is definitely potentially dynamic interactive and dynamic interactive (varying).
  • Q2: What is the benefit of using arrays? How might you use arrays in a potential project?
    • Like how I stated previously, I think array is very useful if you want to change one specific element within a group. According to Shiffman, he said if you meet a project that have thousands of elements, array might not be a good idea (because it will burn the computer), so I guess there will be another approach for a bigger project. But for projects that only involves several, using array will be perfect. It is so convenient if you want to change, for example, the 10th or 24th lamp in you “lamp forest”. You can easily orient to [24] instead of rewrite the whole program, so I think array is very beneficial if you want to work on a project that isn’t gigantic.

Leave a Reply

Your email address will not be published. Required fields are marked *