2018年11月23日 星期五

week 12, mandala drawing II

example 1:

float cX;
float cY;
int nSegment = 24;

void setup() {

size(600, 600);
cX = width/2.0;
cY = height/2.0;
stroke(200);
noFill();

}

void draw() {
float x;
float y;
float angle;
float r = 200.0;

background(0);

for (int i= 0; i < nSegment; i++) {
angle = i*(PI*2.0)/nSegment;
x = cX+ r*cos(angle);
y = cY+ r*sin(angle);

pushMatrix();
translate(x, y);
rotate(angle);
ellipse(0, 0, 40, 20);
popMatrix();

}

}


example 2:

structured :

float cX;

float cY;

void setup() {

size(600, 600);
cX = width/2.0;
cY = height/2.0;
stroke(200);
noFill();
noLoop();

}

void draw() {

background(0);
for (int i= 0; i< 4; i++)
drawLayer();

}

void drawLayer() {
float x;
float y;
float angle;
float r = 200.0;
int nSegment = 24;

r = random (60, 260);
nSegment = (int) random (8, 36);

for (int i= 0; i < nSegment; i++) {
angle = i*(PI*2.0)/nSegment;
x = cX+ r*cos(angle);
y = cY+ r*sin(angle);

pushMatrix();
translate(x, y);
rotate(angle);
ellipse(0, 0, 60, 30);
popMatrix();

}

}


example 3:
 array:

float cX;
float cY;


int nLayer = 30;
float[] r;
int[] nSegment;
int[] brightness;
float[] rotateRate;

void setup() {

size(600, 600);
cX = width/2.0;
cY = height/2.0;

r = new float[nLayer];
nSegment = new int[nLayer];
brightness = new int[nLayer];
rotateRate = new float[nLayer];

for (int i = 0; i< nLayer; i++) {
r[i] = random(60, 260);
nSegment[i] = (int) random(6, 60);
brightness[i] = (int) random(10, 255);
rotateRate[i] = random(-100.0, 100.0);

}

stroke(200);
noFill();
// noLoop();

}

void draw() {

background(0);
for (int i= 0; i< nLayer; i++)
drawLayer(i);

}

void drawLayer(int nth) {
float x;
float y;
float angle;

stroke(brightness[nth], brightness[nth], 100);
for (int i= 0; i < nSegment[nth]; i++) {
angle = i*(PI*2.0)/nSegment[nth];
x = cX+ r[nth]*cos(angle);
y = cY+ r[nth]*sin(angle);

pushMatrix();
translate(x, y);
rotate(angle +frameCount/rotateRate[nth]);
ellipse(0, 0, 60, 30);
popMatrix();

}

}


example 4:
centered rotate:

float cX;
float cY;


int nLayer = 30;
float[] r;
int[] nSegment;
int[] brightness;
float[] rotateRate;

void setup() {

size(600, 600);
cX = width/2.0;
cY = height/2.0;

r = new float[nLayer];
nSegment = new int[nLayer];
brightness = new int[nLayer];
rotateRate = new float[nLayer];

for (int i = 0; i< nLayer; i++) {
r[i] = random(20, 260);
nSegment[i] = (int) random(6, 60);
brightness[i] = (int) random(10, 255);
rotateRate[i] = random(-100.0, 100.0);

}

stroke(200);
noFill();
// noLoop();

}

void draw() {

background(0);
translate(cX, cY);
rotate(frameCount/150.0);
for (int i= 0; i< nLayer; i++)
drawLayer(i);

}

void drawLayer(int nth) {
float x;
float y;
float angle;

stroke(brightness[nth], brightness[nth], 100);
fill(0, brightness[nth], brightness[nth], 25);
for (int i= 0; i < nSegment[nth]; i++) {
angle = i*(PI*2.0)/nSegment[nth];
x = r[nth]*cos(angle);
y = r[nth]*sin(angle);

pushMatrix();
translate(x, y);
rotate(angle +frameCount/rotateRate[nth]);
ellipse(0, 0, 60, 30);
popMatrix();

}
}

example 5:

float cX;
float cY;


int nLayer = 30;
float[] r;
int[] nSegment;
int[] brightness;
float[] rotateRate;

void setup() {

size(600, 600);
cX = width/2.0;
cY = height/2.0;

r = new float[nLayer];
nSegment = new int[nLayer];
brightness = new int[nLayer];
rotateRate = new float[nLayer];

for (int i = 0; i< nLayer; i++) {
r[i] = random(10, 300);
nSegment[i] = (int) random(6, 60);
brightness[i] = (int) random(10, 255);
rotateRate[i] = random(-100.0, 100.0);

}

stroke(200);
noFill();
// noLoop();

}

void draw() {

background(0);
translate(cX, cY);
rotate(frameCount/map(sin(frameCount/60.0), -1.0, 1.0, -100.0, 100.0));
for (int i= 0; i< nLayer; i++)
drawLayer(i);

}

void drawLayer(int nth) {
float x;
float y;
float angle;

stroke(brightness[nth], brightness[nth], 100);
fill(0, brightness[nth], brightness[nth], 25);
for (int i= 0; i < nSegment[nth]; i++) {
angle = i*(PI*2.0)/nSegment[nth];
x = r[nth]*cos(angle);
y = r[nth]*sin(angle);

pushMatrix();
translate(x, y);
rotate(angle +frameCount/rotateRate[nth]);
ellipse(0, 0, 60, 30);
//rect(-10, -10, 20, 20);

popMatrix();

}
} 

2018年11月22日 星期四

week 11. drawing mandala



Basic sample 1:


float resolution;
float radius = 100;
float circleX;
float circleY;
float offset;

void setup() {
  size(700, 700);
  circleX = 0;
  circleY = 0;
}

void draw() {
  fill(0,0,0,25);
  rect(0,0,width,height);
  translate(width/2, height/2);
  fill(255);
  noStroke();
  offset++;

  resolution = map(sin(offset*0.005), -1, 1, 2, 20);
 // resolution = 20;



  for (int i = 0; i < resolution; i++) {
    float angle = map(i, 0, resolution, 0, TWO_PI);
//    float waveOffset = sin(angle*circles) * 200;
 

 
   float circleOffsetX = cos(angle) * (radius); //xposition
   float circleOffsetY = sin(angle) * (radius); //yposition
  //  float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
  //  float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition
 

    float x = circleX + circleOffsetX;
    float y = circleY + circleOffsetY;
 
    ellipse(x, y, 10, 10);
 

  }
}

Sample 2:

float resolution;
float radius = 100;
float circleX;
float circleY;
float circles;
float circleW;
float circleH;
float offset;

void setup() {
  size(700, 700);
  circleX = 0;
  circleY = 0;
}

void draw() {
  fill(0,0,0,25);
  rect(0,0,width,height);
  translate(width/2, height/2);
  fill(255);
  noStroke();
  offset++;

  resolution = map(sin(offset*0.00025), -1, 1, 11, 13);
  //resolution = 50;
  circles = 400;

  circleW = map(sin(offset*0.05), -1, 1, 1, 8);
  circleH = map(sin(offset*0.05), -1, 1, 1, 8);

  for (int i = 0; i < resolution; i++) {

    float scale = 200;

    float waveAngle = map(i, 0, resolution, 0, TWO_PI * circles);
    float waveOffset = sin(waveAngle) * scale;  //scale the -1 to 1 up

    float angle = map(i, 0, resolution, 0, TWO_PI * 156); //multiply for weirdness

    float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
    float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition

    float x = circleX + circleOffsetX;
    float y = circleY + circleOffsetY;
 
    ellipse(x, y, circleW, circleH);

  }

}

example 3:


float resolution;
float radius = 100;
float circleX;
float circleY;
float circles;
float offset;

void setup() {
  size(700, 700);
  circleX = 0;
  circleY = 0;
}

void draw() {
  fill(0,0,0,25);
  rect(0,0,width,height);
  translate(width/2, height/2);
  fill(255, 255, 0);
  noStroke();
  offset++;

  resolution = map(cos(offset*0.0002), -1, 1, 2, 200);
  circles = 100;


beginShape();
noFill();
  for (int i = 0; i < resolution; i++) {

    float scale = 400;

    float waveAngle = map(i, 0, resolution, 0, TWO_PI * circles);
    float waveOffset = sin(waveAngle) * scale;  //scale the -1 to 1 up

    float angle = map(i, 0, resolution, 0, TWO_PI * 156); //multiply for weirdness
 

    float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
    float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition

    float x = circleX + circleOffsetX;
    float y = circleY + circleOffsetY;
 
    stroke(255);
    //line(x, y, 0, 0);
    vertex(x,y);
 

  }
  endShape(CLOSE);

}

reference:
search "mandala" on
https://www.openprocessing.org/

2018年11月15日 星期四

week 10. using recursion for Sacred Geometry

float radius;
int segment = 6;
float centerX;
float centerY;
int recursionLevel = 3;

void setup(){
 size(600,600);
 background(0);
 stroke(255);
 centerX = height/2;
 centerY = width/2;
}

void draw(){
  background(0);
  radius = dist(centerX, centerY, mouseX, mouseY);
  spiral(centerX,centerY,radius,segment, recursionLevel);
}
void spiral(float x_c,float y_c, float r, int seg,int level){
  level -= 1;
  noFill();
  ellipse(x_c,y_c,2*r,2*r);
    for(int i =0;i < seg; i++){
      float x = x_c+cos(i*2*PI/seg)*r; 
      float y = y_c+sin(i*2*PI/seg)*r;
      point(x,y); 
      ellipse(x,y,2*r,2*r);
    
      if(level > 0){
      spiral(x,y,r,seg, level);
      }
    }
}



example 2:

float radius; int segment = 6; float centerX; float centerY;
int recursionLevel = 3;

void setup(){
size(600,600);
background(0);
stroke(255);
centerX = height/2;
centerY = width/2;
}

void draw(){
background(0);
// radius = dist(centerX, centerY, mouseX, mouseY);
radius = 50;

pushMatrix();
translate(centerX-100, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();

}
void spiral(float x_c,float y_c, float r, int seg,int level){
level -= 1;
noFill();
ellipse(x_c,y_c,2*r,2*r);
for(int i =0;i < seg;i++)

float x = x_c+cos(i*2*PI/seg)*r;
float y = y_c+sin(i*2*PI/seg)*r;
point(x,y);
ellipse(x,y,2*r,2*r);

if(level>0){
spiral(x,y,r,seg, level);
}
}
}



References:

The Illusions of Reality & The Basics of Sacred Geometry (The Patterns of Consciousness) 

https://www.youtube.com/watch?v=zoqTNpok6zw

project 2:

draw mandala or Sacred Geometry (tree of life)

deadline 11/30, 2018
extended to 12/7, 2018

2018年11月8日 星期四

week 9. using sin(x)

sample codes:

float radius;
int segment = 10;
float centerX;
float centerY;

void setup(){
 size(600,600);
 background(0);
 stroke(255);
 centerX = height/2;
 centerY = width/2;
}

void draw(){
  background(0);
  radius = dist(centerX, centerY, mouseX, mouseY);
  spiral(centerX,centerY,radius,segment);
}
void spiral(float x_c,float y_c, float r, int seg){
    for(int i =0;i<=seg;i++){
      float x = x_c+cos(i*2*PI/seg)*r;  //算出x的位置
      float y = y_c+sin(i*2*PI/seg)*r;  //算出y的位置
      point(x,y);  // 畫出點,也能用其他形狀
    }
}



EX:
1. 每次點擊滑鼠,劃一個隨機半徑大小的圓。
2. draw flower of life (生命之花)

reference:

https://processing.org/examples/sine.html

https://processing.org/examples/sinecosine.html

John Whitney
https://www.youtube.com/watch?v=kzniaKxMr2g


Processing Tutorial Sin & Cos


https://www.youtube.com/watch?v=s_KIrIJkLoE