顯示具有 03160712_陳世儒 標籤的文章。 顯示所有文章
顯示具有 03160712_陳世儒 標籤的文章。 顯示所有文章

2018年1月22日 星期一

week19 期末作品展示

https://www.youtube.com/watch?v=Y8AZA-_Y1Pw            
                                                                                                                                 

2017年10月23日 星期一

WEEK06

製作爆爆王遊戲
void setup(){
  size(850,500);
}
int userJ=9, userI=5;
float  userX, userY;
int waterN=0;
int []waterJ=new int[100];
int []waterI=new int[100];
void draw(){
  background(#92AD28);
  noStroke();
  for(int x=0;x<17;x++){
    for(int y=0;y<10;y++){
      if((x-y)%2 ==0) fill(#7E9819);
      else fill(#92AD28);
      rect(x*50,y*50,50,50);
    }
  }
  fill(255,0,0); ellipse(userJ*50+25 , userI*50+25, 50,50);
  for(int i=0; i<waterN; i++){
      fill(#93E1F7); ellipse(userJ*50+25 , userI*50+25, 30,30);
  }
}
void keyPressed(){
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP) userI--;
  if(keyCode==DOWN) userI++;
  if(keyCode==' '){ waterI[waterN]=userI; waterJ[waterN]=userJ; waterN++;}
}




2017年10月16日 星期一

week 5

void setup(){
  size(400,400);
}
void draw(){
  background(128);
  strokeWeight(20);
  ellipse(100,200, 180,360);
  ellipse(300,200, 180,360);
 
  ellipse(100,200, 10,10);
  ellipse(300,200, 10,10);
  line(mouseX, mouseY, 100,200);
  line(mouseX, mouseY, 300,200);
}

0`
void setup(){
  size(400,800);
}
float ballX=200, ballY=600;
float ballVX=0, ballVY=0;
float angle=0;
void draw(){
  background(0,128,0);
  fill(#FA9703);ellipse(200,600,100,100);
  line(mouseX, mouseY, 200,600);
  fill(#F9FA03);ellipse(ballX,ballY, 30,30);
  angle = atan2(mouseY-600, mouseX-200);
 
  ballX+=ballVX;
  ballY+=ballVY;
}
void mouseMoved(){
  ballX=200+50*cos(angle);
  ballY=600+50*sin(angle);
}
void mousePressed(){
  ballX=cos(angle);
  ballY=sin(angle);



void setup(){
  size(400,800);
}
float [] ballX=new float[10];
float [] ballY=new float[10];
float [] ballVX=new float[10];
float [] ballVY=new float[10];
float [] angle=new float[10];
int now=0;
void draw(){
  background(0,128,0);
  fill(#FA9703);ellipse(200,600,100,100);
   for(int i=0;i<10;i++){
  fill(#F9FA03);ellipse(ballX[i],ballY[i],30,30);
    ballX[i]+=ballVX[i]; ballY[i]+=ballVY[i];
  }
  angle[now]=atan2(mouseY-600,mouseX-200);
}
void mouseMoved(){
  ballX[now]=200+50*cos(angle[now]); ballY[now]=600+50*sin(angle[now]);
}
void mousePressed(){
  ballVX[now]=cos(angle[now]); ballVY[now]=sin(angle[now]);
  now++;
}




2017年10月2日 星期一

WEEK04

PImage imgBird, imgPig;
void setup(){
  size(800,600);
  imgBird=loadImage("bird.png");
  imgPig=loadImage("pig.png");
  imageMode(CENTER); 
  for(int i=0;i<5;i++){
  for(int j=0;j<4;j++){
  pigX[i][j]=700-i*100;pigY[i][j]=100+j*100;pigAlive[i][j]=true;
  }
  }
}
float birdVX=0,birdVY=0;
float birdX=400,birdY=300;
float birdAX=0,birdAY=0;
float [][]pigX=new float[5][4];
float [][]pigY=new float[5][4];
boolean [][]pigAlive=new boolean[5][4];   
void draw(){
    background(255);
    image(imgBird,birdX,birdY,55,55);
    for(int i=0; i<5; i++){
      for(int j=0;j<4;j++){
      if(dist(pigX[i][j],pigY[i][j],birdX,birdY)<100){
      pigAlive[i][j]=false;
       }
       if(pigAlive[i][j]) image(imgPig,pigX[i][j],pigY[i][j],100,100);
      }
   
    }
   
    line(birdX,birdY,400,300);
    birdX +=birdVX;
    birdY +=birdVY;
    if(birdX<27.5){birdX=27.5; birdVX=-birdVX;} 
    if(birdX>width-27.5){birdX=width-27.5;birdVX=-birdVX;} 
    if(birdY<27.5){birdY=27.5;birdVY=-birdVY;}       
    if(birdY>height-27.5){birdY=height-27.5;birdVY=-birdVY;}   
    birdVX +=birdAX;
    birdVY +=birdAY;
    birdVX*=0.997;   
    birdVY*=0.997;   
}
void mouseDragged(){
  birdX=mouseX;
  birdY=mouseY;
  birdVX=birdVY=birdAX=birdAY=0;
}
void mouseReleased(){
  birdVX=(400-mouseX)/10.0;
  birdVY=(300-mouseY)/10.0;
  birdAY=0.98; 
}

week 03

一、做出憤怒鳥Angry Bird小遊戲

1.讀入圖片,並讓中心點都在圖

PImage imgbird,imgpig;
void setup(){
  size(800,600);
  imgbird=loadImage("bird.png");
  imgpig=loadImage("pig.png");
  imageMode(CENTER);
}
float birdX=400,birdY=300;
float pigX=700,pigY=200;2
void draw(){

  background(255);
  image(imgpig,pigX,pigY,100,100);
  image(imgbird,birdX,birdY,100,100);
}

2.使憤怒鳥有速度、加速度、引力以及彈弓
PImage imgbird,imgpig;
void setup(){
  size(800,600);
  imgbird=loadImage("bird.png");
  imgpig=loadImage("pig.png");
  imageMode(CENTER);
}
float birdX=400,birdY=300;
float birdVX=0,birdVY=0;
float birdAX=0,birdAY=0;
float pigX=700,pigY=200;
void draw(){
  background(255);
  image(imgpig,pigX,pigY,100,100);
  image(imgbird,birdX,birdY,100,100);
  line(birdX,birdY,400,300);
  birdX+=birdVX;
  birdY+=birdVY;
  birdVX+=birdAX;
  birdVY+=birdAY;
}
void mouseDragged(){
  birdX=mouseX;
  birdY=mouseY;
  birdVX=birdVY=birdAX=birdAY=0;
}
void mouseReleased(){
  birdVX=(400-mouseX)/10.0;
  birdVY=(300-mouseY)/10.0;
  birdAY=0.98;
}

3.有邊界碰撞反彈、有擊中判定(完成)
PImage imgbird,imgpig;
void setup(){
  size(800,600);
  imgbird=loadImage("bird.png");
  imgpig=loadImage("pig.png");
  imageMode(CENTER);
}
float birdX=400,birdY=300;
float birdVX=0,birdVY=0;
float birdAX=0,birdAY=0;
float pigX=700,pigY=200;
boolean pigalive=true;
void draw(){
  background(255);
  if(pigalive) image(imgpig,pigX,pigY,100,100);
  image(imgbird,birdX,birdY,100,100);
  if(dist(pigX,pigY,birdX,birdY)<100) pigalive=false;
  line(birdX,birdY,400,300);
  birdX+=birdVX;
  birdY+=birdVY;
  if(birdX<50){birdX=50;birdVX=-birdVX;}
  if(birdX>width-50){birdX=width-50;birdVX=-birdVX;}
  if(birdY<50){birdY=50;birdVY=-birdVY;}
  if(birdY>height-50){birdY=height-50;birdVY=-birdVY;}
  birdVX+=birdAX;
  birdVY+=birdAY;
  birdVX*=0.98;
  birdVY*=0.98;
}
void mouseDragged(){
  birdX=mouseX;
  birdY=mouseY;
  birdVX=birdVY=birdAX=birdAY=0;
}
void mouseReleased(){
  birdVX=(400-mouseX)/10.0;
  birdVY=(300-mouseY)/10.0;
  birdAY=0.98;
}

2017年9月25日 星期一

week02 嗨

void setup(){
  size(800,600);
  colorMode(HSB,100);   
}
void draw(){
  line(mouseX,mouseY,pmouseX,pmouseY);
}
void mousePressed(){
  if(mouseX<100){///strokeWeight()   
  }
  if(mouseX>700){///stroke()    
    stroke(mouseY/6.0,100,100); 
  }
}

void setup(){
  size(800,600);
  rect(width-100,0,width,height); //左框框
  rect(0,0,100,height);  //右框框
  colorMode(HSB,100);///Q:Hue,Saturation,Brightness,0-100
}
void draw(){
  if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY); 
}
void mouseDragged(){  //滑鼠拖曳
  if(mouseX<100){///strokeWeight()
    strokeWeight(mouseY/50);
  }
  if(mouseX>width-100){///stroke() 
    stroke(mouseY/6.0,100,100);
  }
}

調色盤:
noStroke();
colorMode(HSB, 100);
for (int i = 0;i < 100; i++) {
   for (int j = 0; j < 100; j++) {
      stroke(i, 100, 100);
      point(i, j);
   }
}  

ArrayList<Particle> pts;
boolean onPressed, showInstruction;
PFont f;
 
void setup() {
  size(720, 720, P2D);
  smooth();
  frameRate(30);
  colorMode(RGB);
  rectMode(CENTER);
 
  pts = new ArrayList<Particle>();
 
  showInstruction = true;
  f = createFont("Calibri", 24, true);
 
  background(255);
}
 
void draw() {
  if (showInstruction) {
    background(255);
    fill(128);
    textAlign(CENTER, CENTER);
    textFont(f);
    textLeading(36);
    text("Drag and draw." + "\n" +
      "Press 'c' to clear the stage." + "\n"
      , width*0.5, height*0.5);
  }
 
  if (onPressed) {
    for (int i=0;i<10;i++) {
      Particle newP = new Particle(mouseX, mouseY, i+pts.size(), i+pts.size());
      pts.add(newP);
    }
  }
 
  for (int i=0; i<pts.size(); i++) {
    Particle p = pts.get(i);
    p.update();
    p.display();
  }
 
  for (int i=pts.size()-1; i>-1; i--) {
    Particle p = pts.get(i);
    if (p.dead) {
      pts.remove(i);
    }
  }
}
 
void mousePressed() {
  onPressed = true;
  if (showInstruction) {
    background(255);
    showInstruction = false;
  }
}
 
void mouseReleased() {
  onPressed = false;
}
 
void keyPressed() {
  if (key == 'c') {
    for (int i=pts.size()-1; i>-1; i--) {
      Particle p = pts.get(i);
      pts.remove(i);
    }
    background(255);
  }
}
 
class Particle{
  PVector loc, vel, acc;
  int lifeSpan, passedLife;
  boolean dead;
  float alpha, weight, weightRange, decay, xOffset, yOffset;
  color c;
   
  Particle(float x, float y, float xOffset, float yOffset){
    loc = new PVector(x,y);
     
    float randDegrees = random(360);
    vel = new PVector(cos(radians(randDegrees)), sin(radians(randDegrees)));
    vel.mult(random(5));
     
    acc = new PVector(0,0);
    lifeSpan = int(random(30, 90));
    decay = random(0.75, 0.9);
    c = color(random(255),random(255),255);
    weightRange = random(3,50);
     
    this.xOffset = xOffset;
    this.yOffset = yOffset;
  }
   
  void update(){
    if(passedLife>=lifeSpan){
      dead = true;
    }else{
      passedLife++;
    }
     
    alpha = float(lifeSpan-passedLife)/lifeSpan * 70+50;
    weight = float(lifeSpan-passedLife)/lifeSpan * weightRange;
     
    acc.set(0,0);
     
    float rn = (noise((loc.x+frameCount+xOffset)*0.01, (loc.y+frameCount+yOffset)*0.01)-0.5)*4*PI;
    float mag = noise((loc.y+frameCount)*0.01, (loc.x+frameCount)*0.01);
    PVector dir = new PVector(cos(rn),sin(rn));
    acc.add(dir);
    acc.mult(mag);
     
    float randDegrees = random(360);
    PVector randV = new PVector(cos(radians(randDegrees)), sin(radians(randDegrees)));
    randV.mult(0.5);
    acc.add(randV);
     
    vel.add(acc);
    vel.mult(decay);
    vel.limit(3);
    loc.add(vel);
  }
   
  void display(){
    strokeWeight(weight+1.5);
    stroke(0, alpha);
    point(loc.x, loc.y);
     
    strokeWeight(weight);
    stroke(c);
    point(loc.x, loc.y);
  }
}

void setup() {
  size(720,720);
}
void draw(){
  
}
void mouseDragged(){
  ellipse(mouseX, mouseY, 100,100);
void setup(){
  size(720,720,P2D);
}
float pX=-100,pY=-100,r=100;
void draw(){
  ellipse(pX,pY,r,r);
  if(r>3){
     r-=10; 
     pX+=13; 
  }
}
void mousePressed(){
  pX=mouseX;pY=mouseY;r=100;
}
size(500,500);
background(255,174,101); 
PImage img=loadImage("dora.jpg");
image(img,90,90,300,300); 

2017年9月18日 星期一

week1 2X學分的老屁股

練習processing

line(0,0, 100,100);
可以畫出一條線


size(600,400);
line(0,0, 100,100);
rect(10,10,50,50);

void setup(){
  size(600,400);
}
void draw(){
line(mouseX,mouseY, pmouseX,pmouseY);
rect(10,10,50,50);
}



(另一種變化)

void setup(){
  size(600,400);
}
void draw(){
line(mouseX,mouseY, pmouseX,pmouseY);
//rect(10,10,50,50);
}\


void setup(){
  size(600,400);
}
void draw(){
  if(key=='1') {strokeWeight(10); stroke(#27B740);}
  if(key=='2') {strokeWeight(5); stroke(#5427B7);}
line(mouseX,mouseY, pmouseX,pmouseY);
//rect(10,10,50,50);
}


https://www.openprocessing.org/