CrescentCrescent
PostsTagsAbout

> Week 1. Twisted Squares

Crescent

01. Info

100 days CSS - Day 44 Twisted Pyramid 사진
100 days CSS - Day 44 Twisted Pyramid 사진

100 days CSS - Twisted Pyramid

완성된 프로세싱으로 만든 소용돌이 치는 사각형들의 모임
완성된 프로세싱으로 만든 소용돌이 치는 사각형들의 모임

There are elements on the lattice points of the black background. Each element consists of squares with different sizes centered at a lattice point. Each square rotates 360 degrees back and forth with the same period. Its speed is slow at the beginning, fast in the middle, and slow again at the end. There is a time difference between squares so that squares in an element do not move simultaneously, forming a wavy movement.

그니깐 대충


02. Process!

요소 하나의 움직임
요소 하나의 움직임
  1. Make a single element
    • Make an array that contains the position of time(시간의 위치) of the square
    • Initialize it with an arithmetic sequence(등차 수열)
    • Use rotate, translate, rect
    • Use easeInOutSine function from easings.net
  2. Extends to a lot of elements
    • Use class for readability
    • Use settings() to use variables at size()
TwistedSquares.pde
// number of squares
int square_size = 8;
// the number of squares in a row(col) 
int N = 4;
// 요소 사이의 거리
int distance = 200;
// 애니메이션 주기
int duration = 800;
TwistedSquares.pde
class Square {
  Timer[] t;
 
  int x;
  int y;
  int sq_size;
 
  Square(int square_size, int duration, int nx, int ny) {
    t = new Timer[square_size];
    for (int i=0; i<square_size; i++) {
      // Initialize the position of time with an arithmetic sequence(등차 수열)
      t[i] = new Timer(((float)i / square_size) * ((float)duration / 4));
    }
    x = nx;
    y = ny;
    sq_size = square_size;
  }
 
  void display() {
    for (int i=0; i<sq_size; i++) {
      float angle = easeInOutSine(t[i].t/duration)*TWO_PI;
 
      translate(x*distance, y*distance);
      rotate(angle);
 
      rect(-(i+1)*8, -(i+1)*8, (i+1)*16, (i+1)*16);
 
      rotate(-angle);
      translate(-x*distance, -y*distance);
 
      t[i].advance();
    }
  }
}
// 0 ~ 1
float easeInOutSine(float x) {
  return -(cos(PI*x)-1)/2;
}
 
class Timer {
  float t;
 
  Timer(float init) {
    t = init;
  }
 
  void advance() {
    t += 2;
    if (t >= duration) t -= 2*duration;
  }
}
TwistedSquares.pde
Square[][] sq = new Square[N][N];
void settings() {
  size((N-1)*distance, (N-1)*distance);
}
 
void setup() {
  frameRate(200);
  noFill();
 
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      sq[i][j] = new Square(square_size, duration, i, j);
    }
  }
}
 
void draw() {
  stroke(#ffffff);
  background(#222222);
  
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      sq[i][j].display();
    }
  }
}

03. 감사의 인사