2025年12月10日 星期三

week 15. practice & Q/A

上週枯山水作品補充資料:

人工生命 (Artificial life) 

https://zh.wikipedia.org/wiki/%E4%BA%BA%E5%B7%A5%E7%94%9F%E5%91%BD

Boids (生物群行行為)

https://zh.wikipedia.org/zh-tw/Boids

Processing example:

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

https://www.youtube.com/watch?v=mhjuuHl6qHM&t=425s


online book: 

https://natureofcode.com/autonomous-agents/


search: Boids algorithm simulation


1.  Self portrait practice

2. discussion :

  how to use GAI?

  preprocessing portrait with GAI, then using codes?

  using GAI to generate portraits?

 any other creative ways of using GAI for portraits?

3.

 (1) 自我探索,(可與 AI問答), 訂出自己特質的關鍵字

 (2) 以此關鍵字,繼續探索適合的風格,互動方式

 (3) 可以與  AI 共同開發屬於自己風格的自畫像 

   

2025年11月29日 星期六

week 14. self portrait

1. using image to draw self portrait 
2. 參觀寶藏巖展覽

Typoportraits on IG

Typo Portraits

pointillism portraits

cubist portrait

Question:
 How to generate "typo portraits"?





Example 1:

PImage img;
int smallPoint, largePoint;
PFont f;
float threshold = 80;

void setup() {
size(736, 736);
img = loadImage("portrait.jpg");
smallPoint = 2;
largePoint = 30;
imageMode(CENTER);
noStroke();
background(255);

// Create the font
printArray(PFont.list());
f = createFont("Georgia", 9);
textFont(f);
textAlign(CENTER, CENTER);

}

void draw() {
float value;
color pix;
// if (mousePressed == true) {
background(80);
int counter = 0;
char letter;

float pointillize = map(mouseX, 0, width, smallPoint, largePoint);
float threshold = map(mouseY, 0, height, 0, 255);
for (int x = 0; x < img.width; x+=pointillize) {
for (int y = 0; y < img.height; y+=pointillize){
pix = img.get(x, y);
value = brightness(pix);
if (value > threshold)
fill(0, 255, 0);
else fill(0);
//ellipse(x, y, 5, 5);
counter = int(random(66, 123));
letter = char (counter);
text(letter, x, y);


}
}
// }

}



Example 2:

/**
* Pointillism
* by Daniel Shiffman.
*
* Mouse horizontal location controls size of dots.
* Creates a simple pointillist effect using ellipses colored
* according to pixels in an image.
*/

// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moonwalk.jpg"; */

PImage img;
int smallPoint, largePoint;

void setup() {
size(736, 736);
img = loadImage("portrait.jpg");
smallPoint = 4;
largePoint = 40;
imageMode(CENTER);
noStroke();
background(255);
}

void draw() {
float pointillize = map(mouseX, 0, width, smallPoint, largePoint);
int x = int(random(img.width));
int y = int(random(img.height));
int xWidth = int(random(10, 200));
int yHeight = int(random(10, 200));
int xShift = int(random(-20, +20));
int yShift = int(random(-20, +20));
for (int i = 0; i< xWidth; i++) {
for (int j = 0; j< yHeight; j++) {
color pix = img.get(x+i, y+j);
stroke(pix);
 //ellipse(xShift+x+i, yShift+y+j, pointillize, pointillize);
point(xShift+x+i, yShift+y+j);
}
}
}


Example 3:

float resolution;
float radius = 100;
float circles;
float circleW;
float circleH;
float offset;
PImage img;


void setup() {
  size(736, 736);
  background(0);
  img = loadImage("portrait.jpg");
}

void draw() {
  float value;
  color pix;
  fill(255);
  noStroke();
  offset++;

  resolution = map(sin(offset*0.00025), -1, 1, 5, 50);
  //resolution = 50;
  circles = 200;

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

  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*1.2;  //scale the -1 to 1 up

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

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

    float x = width/2 + circleOffsetX;
    float y = height/2 + circleOffsetY;
    pix = img.get(int(x), int(y));
    value = brightness(pix);
    fill(0, green(pix), blue(pix));
    ellipse(x, y, circleW, circleH);

  }

}

Final Project:
Self Portrait Demo:
最少三種
例如,Andy Warhol 風格,字型風格,拼貼風格,動態曼陀羅風格,...

Dec, 19, 2025

2025年11月23日 星期日

week 13. Project 2 demo & Image

1. Mandala Project Demo

2. Image

 https://www.processing.org/examples/pointillism.html

https://www.processing.org/reference/PImage.html

https://processing.org/tutorials/pixels/


EX:
load your own portrait (在"程式素描本"/Sketch下使用"新增檔案"/Add file,將照片加入程式)
do image process

Final Project:
Self Portrait Demo:
最少三種
例如,Andy Warhol 風格,字型風格,拼貼風格,動態曼陀羅風格,...


Dec.  19, 2025

2025年11月16日 星期日

week 12. Object-Oriented Programming



1.  Mandala Project reference:
http://sciencefictioninterfaces.tumblr.com/

2. object oriented programming:
  https://processing.org/tutorials/objects/
  https://www.youtube.com/watch?v=YcbcfkLzgvs

3. simple particle system

EXercise:
  draw 'array-like' object with OOP
Challenge:
  draw Mandala with OOP 
   (define your own object class for mandala object) 

reference:


mandala OOP example:

Mandala myMandala;
void setup() {
  size(600, 600);
  myMandala = new Mandala();
}

void draw() {
background(0);
 fill(0,0,0);
  rect(0,0,width,height);
myMandala.drawMandala();
myMandala.updateMandala();
}

class Mandala{
float radius;
int segment = 12;
float centerX;
float centerY;
int[] pattern;


Mandala(){
 stroke(255);
 centerX = height/2;
 centerY = width/2;
 pattern = new int[8];
 for (int i= 0; i< 8; i++)
   pattern[i]=(int) random(4);
}
void drawMandala()
{
  background(0);
   fill(0,0,0);
  rect(0,0,width,height);
  radius = 30.0;
  segment = 12;
  noFill();
  pushMatrix(); 
    translate(centerX, centerY);
     rotate(frameCount/40.0);
     translate(-centerX, -centerY);
  for (int i= 0; i< 8; i++){
   radius=radius+25.0;  
   segment=segment+ 6;
    
   
    spiral(centerX,centerY,radius,segment, pattern[i]);
    
  }
  popMatrix();
}
void spiral(float x_c,float y_c, float r, int seg, int pattern){
    for(int i =0;i<seg;i++){
    float theta = i*2*PI/seg;  
     float x = x_c+cos(theta)*r;  //算出x的位置
     float y = y_c+sin(theta)*r;  //算出y的位置
//      point(x,y);  // 畫出點,也能用其他形狀
    ellipse(x_c, y_c, 2*r, 2*r);
    if (pattern == 0) ellipse(x_c, y_c, 2*r+8, 2*r+8);
   if (pattern == 1) drawPattern1(x,y,theta);
   if (pattern == 2) drawPattern2(x,y,theta);  
   if (pattern == 3) drawPattern3(x,y,theta);     
   //pattern  
    
    }
}
void drawPattern1(float x, float y, float theta){
    pushMatrix();
      translate(x,y);
      rotate(theta);
    point(5, 0);
    line(0,10, 20,0);
    line(0,-10, 20, 0);
     popMatrix();
}
void drawPattern2(float x, float y, float theta){
    pushMatrix();
      translate(x,y);
      rotate(theta);
    ellipse(5, 0, 5, 5);
    arc(0, 0, 30, 20, PI*1.5, PI*2.5);
     arc(0, 0, 25, 15, PI*1.5, PI*2.5);
     popMatrix();
}
void drawPattern3(float x, float y, float theta){
    pushMatrix();
      translate(x,y);
      rotate(theta);
     beginShape();
       curveVertex(0,  8);
       curveVertex(0,  8);
       curveVertex(16,  6);
       curveVertex(16,  -6);
       curveVertex(0, -8);
       curveVertex(0, -8);
      endShape();
    beginShape();
       curveVertex(0,  10);
       curveVertex(0,  10);
       curveVertex(20,  8);
       curveVertex(20,  -8);
       curveVertex(0, -10);
       curveVertex(0, -10);
      endShape();
//    bezier(0,-10, 15, -9, 0, 0, 18,0);
//    bezier(0,10, 15, 9,0, 0, 18,0);

     popMatrix();
}
void updateMandala()
{

}  
}

2025年11月9日 星期日

week 11. drawing mandala


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

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

void draw(){
  background(0);
  //radius = dist(centerX, centerY, mouseX, mouseY);
int pattern;
radius = 30.0;
noFill();
for (int i= 0; i< 8; i++){
radius=radius+25.0;
segment=segment+ 6;
pattern = (int) random(4);
    spiral(centerX,centerY,radius,segment, pattern);
}
  
}
void spiral(float x_c,float y_c, float r, int seg, int pattern){
    for(int i =0;i<seg;i++){
  float theta = i*2*PI/seg;
     float x = x_c+cos(theta)*r;  //算出x的位置
     float y = y_c+sin(theta)*r;  //算出y的位置
//      point(x,y);  // 畫出點,也能用其他形狀
    ellipse(x_c, y_c, 2*r, 2*r);
    if (pattern == 0) ellipse(x_c, y_c, 2*r+8, 2*r+8);
if (pattern == 1) drawPattern1(x,y,theta);
if (pattern == 2) drawPattern2(x,y,theta);
if (pattern == 3) drawPattern3(x,y,theta);
//pattern
    }
}
void drawPattern1(float x, float y, float theta){
pushMatrix();
      translate(x,y);
      rotate(theta);
point(5, 0);
line(0,10, 20,0);
line(0,-10, 20, 0);
     popMatrix();
}
void drawPattern2(float x, float y, float theta){
pushMatrix();
      translate(x,y);
      rotate(theta);
ellipse(5, 0, 5, 5);
arc(0, 0, 30, 20, PI*1.5, PI*2.5);
   arc(0, 0, 25, 15, PI*1.5, PI*2.5);
     popMatrix();
}
void drawPattern3(float x, float y, float theta){
pushMatrix();
      translate(x,y);
      rotate(theta);
   beginShape();
       curveVertex(0,  8);
       curveVertex(0,  8);
       curveVertex(16,  6);
       curveVertex(16,  -6);
       curveVertex(0, -8);
       curveVertex(0, -8);
      endShape();
beginShape();
       curveVertex(0,  10);
       curveVertex(0,  10);
       curveVertex(20,  8);
       curveVertex(20,  -8);
       curveVertex(0, -10);
       curveVertex(0, -10);
      endShape();
//    bezier(0,-10, 15, -9, 0, 0, 18,0);
//    bezier(0,10, 15, 9,0, 0, 18,0);

     popMatrix();
}

 
 

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/

also 

2025年11月2日 星期日

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);
}
}
}


example 3:
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, 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,r*2,r*2);
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);
float r1= 2*r*map(sin(frameCount/50.0+i*PI/6.0), -1.0, 1.0, 0.01, 4.0);
ellipse(x,y,r1,r1);
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


https://youtu.be/utMx48aGndI?si=Al7d7bfxDIZP_Ugb

project 2:

draw mandala or Sacred Geometry (tree of life)
4 compositions representing earth, water, fire, wind, (4 elements)
deadline  11/28, 2025

2025年10月26日 星期日

week 9. using sine

(時間往復變化) 
practice:
  用sine 控制一個物件之 
    (1) 大小  scale  (https://processing.org/examples/sine.html)
    (2) 位置  translation  (https://processing.org/examples/sinecosine.html)
    (3) 旋轉(自轉與他轉)  rotation



(線性位移與 sine 曲線位移)

float x, y;
float dim = 80.0;
float dX = 4.0;

void setup() {
  size(640, 360);
  noStroke();
}

void draw() {
  background(102);
  
  x = x + dX;
  
  if (x > width||x<0) {
    dX = -dX;
  } 

  pushMatrix();
  translate(x, height/2-dim/2);
  fill(255);
  rect(-dim/2, -dim/2, dim, dim);
  popMatrix();
  // Transforms accumulate. Notice how this rect moves 
  // twice as fast as the other, but it has the same 
  // parameter for the x-axis value
  pushMatrix();
  translate(sin(map(x,0, width,0, PI))*width, height/2+dim/2);
  fill(0);
  rect(-dim/2, -dim/2, dim, dim);
  popMatrix();
}

(scale 線性與 sine 比較)

float x, y;
float dim = 80.0;
float dX = 4.0;

void setup() {
  size(640, 360);
  noStroke();
  frameRate(20);
}

void draw() {
  background(102);
  
  x = x + dX;
  
  if (x > width||x<0) {
    dX = -dX;
  } 

  pushMatrix();
  translate(width/4, height/2);
  scale(map(x,0,width, 0.25, 4.0));
  fill(255);
  rect(-dim/2, -dim/2, dim, dim);
  popMatrix();
  // Transforms accumulate. Notice how this rect moves 
  // twice as fast as the other, but it has the same 
  // parameter for the x-axis value
  pushMatrix();
  translate(width*0.75, height/2);
  //scale(map(x,0,width, 0.25, 4.0));
 //scale(map(sin(frameCount/40.0), -1.0, 1.0, 0.25,4.0));
  scale(map(sin(map(x,0,width,0.0, PI)), 0, 1.0, 0.25, 4.0));
  fill(0);
  rect(-dim/2, -dim/2, dim, dim);
  popMatrix();
}
(空間切割) 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);  // 畫出點,也能用其他形狀
    }
}

( 空間切割範例)
https://processing.org/examples/star.html

using map
https://processing.org/examples/map.html


example :

void setup() {
size(800, 600);
noFill();
stroke(255, 255, 255);
}
void draw() {
float d;
background(0);
for (int i= 0; i<width; i+=50) {
pushMatrix();
translate(i, 0);
rotate(map(sin((i/40.0+frameCount)/30.0), -1.0, 1.0, -PI/4, PI/4));
line(0, 0, 0, 350);
translate(0, 350);
ellipse(0, 0, 50, 50);
popMatrix();
}
}


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=ehT7d9JPulQ