2024年12月9日 星期一

week141414

 week14-1

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

int x = -1, y = -1;
void draw(){
    if(x != -1){
        ellipse(x, y, 1, 1);
        y++;
    }
}

void mouseDragged(){ 
    if(mouseButton == LEFT) 
        line(mouseX, mouseY, pmouseX, pmouseY);
    if(mouseButton == RIGHT) {
        x = mouseX;
        y = mouseY;
    }
}


week14-2

void setup(){
    size(500, 500);
    background(255);
}

void draw(){

}

void mouseDragged(){
    if(mouseButton == LEFT) 
        line(mouseX, mouseY, pmouseX, pmouseY); 
    loadPixels(); 
    for(int i = 0; i < width*height; i++){
        if(pixels[i] != -1) pixels[i] = color(random(255), random(255), random(255));
    }
    updatePixels(); 
 }

week14-3



PImage img;


void setup(){

    size(500, 500);

    img = createImage(500, 500, RGB);

    img.loadPixels();

    for(int i = 0; i < 500*500; i++) img.pixels[i] = color(#FFFFF2);

    img.updatePixels();

}

int x = 250, y =0;

void draw(){

    background(img);

    ellipse(x,y,20,20);

    if(img.pixels[x+y*500]==-14) y++;

}


void mouseDragged(){

    background(img);

    line(mouseX, mouseY, pmouseX, pmouseY);

    loadPixels();

    img.loadPixels();

    for(int i = 0; i < 500*500; i++) img.pixels[i] = pixels[i]; 

    img.updatePixels();

    updatePixels();

}


week14-4

PImage img;

void setup(){
    size(500, 500);
    img = createImage(500, 500, RGB);
}

ArrayList<PVector> p = new ArrayList<PVector>(); // 很多個點
void draw(){
    background(img);
    for(PVector pp : p){
        ellipse(pp.x, pp.y, 20, 20);
        if(pp.y < 498 && img.pixels[int(pp.x) + int(pp.y) * 500] ==-16777216) pp.y++;
    }
}
void mouseDragged(){
    background(img);
    stroke(random(255), random(255), random(255));
    line(mouseX, mouseY, pmouseX, pmouseY);
    loadPixels();
    img.loadPixels();
    for(int i = 0; i < 500 * 500; i++) img.pixels[i] = pixels[i];
    img.updatePixels();
    updatePixels();
    for(PVector pp : p){
        ellipse(pp.x, pp.y, 20, 20);
    }
}

void mousePressed(){
    if(mouseButton == RIGHT){
        p.add(new PVector(mouseX, mouseY));
    }
}

week14-5

void setup(){
    size(500, 500);
    background(#FFFFF2);
}

void draw(){
    if(mousePressed && mouseButton == LEFT) 
        line(mouseX, mouseY, pmouseX, pmouseY);

    if(mousePressed && mouseButton == RIGHT){
        loadPixels(); 
        color cl = pixels[mouseX + mouseY * 500]; 
        color c2 = color(random(255), random(255), random(255));  
        if(cl != c2) myFloodFill(mouseX, mouseY, cl, c2); 
        updatePixels(); 
    }
}

boolean isOK(int x, int y, color cl){
    if(x < 0 || x >= 500 || y < 0 || y >= 500) return false; 
    if(pixels[x + y * 500] != cl) return false;
    return true;
}

void myFloodFill(int x, int y, color cl, color c2){
    pixels[x + y * 500] = c2;
    if(isOK(x+1, y, cl)) myFloodFill(x+1, y, cl, c2);
    if(isOK(x-1, y, cl)) myFloodFill(x-1, y, cl, c2);
    if(isOK(x, y+1, cl)) myFloodFill(x, y+1, cl, c2);
    if(isOK(x, y-1, cl)) myFloodFill(x, y-1, cl, c2);
}


week14-6

void setup (){
  size(500,500);
  PImage img = loadImage("kitty.png");
  cursor(img);
}
  void draw(){
    background(#FFFFF2);
  }


week14-7

PImage imgCute, imgKitty;


void setup(){

    size(500, 500);

    imgCute = loadImage("cute.png");

    imgKitty = loadImage("kitty.png");

    cursor(imgKitty);

    // 可用 https://remove.bg 來將圖片去掉背景

}


void draw(){

    background(#FFFFF2);

    if((frameCount % 120) == 0) cursor(imgCute);

    if((frameCount % 120) == 60) cursor(imgKitty);

}


week14-8

PImage imgBigCute, imgBigKitty, imgCursor;


void setup(){

    size(500, 500);

    imgBigCute = loadImage("bigcute.png");

    imgBigKitty = loadImage("bigkitty.png");

    imgCursor = imgBigKitty;

}


void draw(){

    background(#FFFFF2);

    imageMode(CENTER);

    image(imgCursor, mouseX, mouseY);

    imageMode(CORNER);


    if((frameCount % 120) == 0) imgCursor = imgBigCute;

    if((frameCount % 120) == 60) imgCursor = imgBigKitty;

}









沒有留言:

張貼留言