顯示具有 04160090_劉甄臻 標籤的文章。 顯示所有文章
顯示具有 04160090_劉甄臻 標籤的文章。 顯示所有文章

2017年10月23日 星期一

Week06 爆爆王

爆爆王


畫出類似爆爆王的地面:

void setup()
{
  size(850,500);
}
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);
    }
  }
}

做出人物:

void setup()
{
  size(850,500);
}
int userJ=9,userI=5;
float userX,userY;
void draw()
{
  background(#92AD28);
  noStroke();
  for(int i=0;i<10;i++)
  {
    for(int j=0;j<17;j++)
    {
      if((j-i)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(j*50,i*50,50,50);
    }
  }
  fill(255,0,0);
  ellipse(userJ*50+25,userI*50+25,50,50);
}
void keyPressed()
{
  if(keyCode==LEFT)userJ--;
  if(keyCode==RIGHT)userJ++;
  if(keyCode==UP)userI--;
  if(keyCode==DOWN)userI++;
}

加上水球:

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 i=0;i<10;i++)
  {
    for(int j=0;j<17;j++)
    {
      if((j-i)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(j*50,i*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(waterJ[i]*50+25,waterI[i]*50+25,30,30);
  }
}
void keyPressed()
{
  if(keyCode==LEFT)userJ--;
  if(keyCode==RIGHT)userJ++;
  if(keyCode==UP)userI--;
  if(keyCode==DOWN)userI++;
  if(key==' '){waterI[waterN]=userI; waterJ[waterN]=userJ; waterN++; }
}

鱷魚咬手指

畫出基本型:

void setup()
{
  size(500,500);
}
void draw()
{
  background(255);
  fill(0,155,0);
  ellipse(250,250,300,300);
  for(int i=0;i<9;i++)
  {
    fill(255);
    rect(110+i*30,200,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 200<mouseY && mouseY<200+30)
    {
      fill(0);
      rect(110+i*30,200,30,30);
    }
  }
  for(int i=0;i<9;i++)
  {
    fill(255);
    rect(110+i*30,300,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 300<mouseY && mouseY<300+30)
    {
      fill(0);
      rect(110+i*30,300,30,30);
    }
  }
}

畫出壞的牙齒:

int bad=0;
int[] all=new int[18];//{0,-1,0,0,0,0,1,0,0,0,.......}
void setup()
{
  size(500,500);
  bad = int(random(18));
  println(bad);
}
void draw()
{
  background(255);
  fill(0,155,0);
  ellipse(250,250,300,300);
  for(int i=0;i<9;i++)
  {
    fill(255);
    rect(110+i*30,200,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 200<mouseY && mouseY<200+30)
    {
      fill(0);
      rect(110+i*30,200,30,30);
    }
    if(bad==i){fill(255,0,0);rect(110+i*30,200,30,30);}
  }
  for(int i=0;i<9;i++)
  {
    fill(255);
    rect(110+i*30,300,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 300<mouseY && mouseY<300+30)
    {
      fill(0);
      rect(110+i*30,300,30,30);
    }
    if(bad==i+9){fill(255,0,0);rect(110+i*30,300,30,30);}
  }
}

消除牙齒:

int bad=0;
int[] all=new int[18];//{0,-1,0,0,0,0,1,0,0,0,.......}
void setup()
{
  size(500,500);
  bad = int(random(18));
  println(bad);
}
boolean bGameOver=false;
void draw()
{
  if(bGameOver)
  {
    background(255,0,0);
    return;
  }
  background(255);
  fill(0,155,0);
  ellipse(250,250,300,300);
  for(int i=0;i<9;i++)
  {
    if(all[i]==-1) continue;
    fill(255);
    rect(110+i*30,200,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 200<mouseY && mouseY<200+30)
    {
      fill(0);
      rect(110+i*30,200,30,30);
      if(mousePressed && all[i]!=1) all[i]=-1;
      if(mousePressed && all[i]==1) bGameOver=true;
    }
    //if(bad==i){fill(255,0,0);rect(110+i*30,200,30,30);}
  }
  for(int i=0;i<9;i++)
  {
    if(all[i+9]==-1) continue;
    fill(255);
    rect(110+i*30,300,30,30);
    if(110+i*30<mouseX && mouseX<110+i*30+30 && 300<mouseY && mouseY<300+30)
    {
      fill(0);
      rect(110+i*30,300,30,30);
      if(mousePressed && all[i+9]!=1) all[i+9]=-1;
      if(mousePressed && all[i+9]==1) bGameOver=true;
    }
    //if(bad==i+9){fill(255,0,0);rect(110+i*30,300,30,30);}
  }
}

2017年10月16日 星期一

Week03 小朋友

小朋友下樓梯

void setup(){
  size(600,500);
}
int boardX=227, boardY=400;
int kidX=300, kidY=250;
void draw(){
 background(0);
 rect(boardX, boardY, 200, 50);
 rect(kidX, kidY, 50, 50);
 if(kidX>boardX-50 && kidX<boardX+200 && kidY>boardY-50)
 {
   
 }
 else kidY++;
 
 kidX=mouseX;
}

Week02 小畫家

利用滑鼠點及改變筆刷粗細和顏色

1.跑出基本型

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

2.調色盤

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

畫出圖形

1.圓形

void setup() {
  size(720,720);
}
void draw(){
  
}
void mouseDragged(){
  ellipse(mouseX, mouseY, 100,100);

2.圓形並縮小移動

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

3.匯入圖檔並加上背景音樂

size(500,500);
background(255,174,101); 
PImage img=loadImage("download.jpg");
image(img,90,90,300,300);

4.改變滑鼠圖案

PImage img1,img2;
void setup()
{
  size(500,500);
  img1 = loadImage("download.jpg");
  img2 = loadImage("images.jpg");
}
void draw()
{
  background(255,174,101);
  image(img2,mouseX,mouseY,100,100);
  image(img1,90,90,300,300);
}

Week05 眼珠

畫出一雙眼睛且眼睛會照著滑鼠方向移動


1.畫出眼白部分

void setup()
{
  size (400,400);
}
void draw()
{
  background(128);//gray
  strokeWeight(20);//粗細
  ellipse(100,200,100,360);//圓心座標    x長  y長
  ellipse(300,200,180,360);//圓心座標    x長  y長
}

2.再畫出黑眼珠

void setup()
{
  size (400,400);
}
void draw()
{
  background(128);//gray
  strokeWeight(20);//粗細
  ellipse(100,200,100,360);//圓心座標    x長  y長
  ellipse(300,200,180,360);//圓心座標    x長  y長
  
  ellipse(100,200,10,10);//圓心座標    x長  y長
  ellipse(300,200,10,10);//圓心座標    x長  y長

}

3.完成

void setup()
{
  size (800,800);
}
void draw()
{
  background(128);//gray
  strokeWeight(20);
  ellipse(100,200,100,360);
  ellipse(300,200,180,360);
  
  //ellipse(100,200,10,10);
  //ellipse(300,200,10,10);
  float angle1 = atan2((mouseY-200)/2,mouseX-300);
  float newX1 = 300+100*cos(angle1)/2;
  float newY1 = 200+200*sin(angle1)/2;
  ellipse(newX1,newY1,10,10);
  float angle2 = atan2((mouseY-200)/2,mouseX-300);
  float newX2 = 300+100*cos(angle2)/2;
  float newY2 = 200+200*sin(angle2)/2;
  ellipse(newX2,newY2,10,10);
}

泡泡砲塔

1.跑出基本型

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(){
  ballVX=cos(angle);
  ballVY=sin(angle);
}

2.增加砲彈

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 跳跳跳

憤怒鳥

憤怒鳥


找圖檔 --名字.png

拉進去processing 裡面 (Ctrl+K 打開程式目錄)

程式碼:

PImage imgBird, imgPig;

void setup(){
  size(800,600);
  imgBird=loadImage("bird.png");
  imgPig=loadImage("ppig.png");
  imageMode(CENTER);
}
float birdX = 400, birdY = 300;
float birdVX = 0, birdVY = 0;
float birdAX =0, birdAY = 0;
float pigx=700, pigy=100;
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.995;
  birdVY *= 0.995;
}
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;
}

執行後跑出


讓憤怒鳥出現多個


程式碼:
PImage imgBird, imgPig;
float birdX = 400, birdY = 300;
float birdVX = 0, birdVY = 0;
float birdAX =0, birdAY = 0;
float [][]pigx=new float[5][4];//宣告豬X,Y位置陣列
float [][]pigy=new float[5][4];
boolean [][]pigAlive=new boolean[5][4];//每隻豬存活陣列
void setup(){
  size(800,600);
  imgBird=loadImage("bird.png");
  imgPig=loadImage("ppig.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;//每隻豬產生的位置
    }
   
  }
}
void draw(){
  background(255);
  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);
    }
  }
  
  image(imgBird, birdX, birdY, 100, 100);
  
  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.995;
  birdVY *= 0.995;
}
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;
}

執行後跑出

放入音樂


程式碼:

import processing.sound.*;
SoundFile sound;
void setup(){
    size(800,600);
    sound = new SoundFile(this,"tt.wav");
    sound.play();
    sound.loop();
}



import ddf.minim*;

Minim minim;
AudioPlayer player;

void setup(){
    size(800,600);
    minim = new Minim(this);
    player = minim.loadFile("tt.wav",2048);
    player.play();
    //player.loop();
}
void draw(){

}
將音樂放入目錄並調整設置

2017年9月18日 星期一

Week01 畫畫畫

畫線:

開啟    "processing"      

寫畫線程式    "line(0,0,100,100) ;"      

查功能、畫方塊(畫線的延伸):

開啟    "在參考文檔中搜索"     

跳出網頁,有英文解說   

以網頁延伸出來的程式寫出方塊  "rect(10,10,50,50);"
程式碼:在(10,10)的地方畫出一個50*50的方形






改變視窗大小:

寫出程式碼  "size(500,500);"


寫出程式碼:
void setup(){
  size(500,500);
}
void draw(){
  line(mouseX,mouseY,pmouseX,pmouseY);
  //rect(10,10,50,50);
}

mouse 利用滑鼠去畫,pmouse 先前滑鼠位子

改變筆刷顏色、粗細:

利用"顏色選擇器"去挑選自己想要的顏色


寫出程式碼:
void setup(){
  size(500,500);
}
void draw(){
  if(key=='1') {strokeWeight(10); stroke(#FF0307);}
  if(key=='2') {strokeWeight(5); stroke(#1603FF);}

  line(mouseX,mouseY,pmouseX,pmouseY);
  //rect(10,10,50,50);
}

strokeWeight(10); 其中 "10" 為粗細大小,stroke(#FF0307); 其中 "#FF0307" 為顏色色彩
if(key=='1') {} 假設鍵盤案 "1" 的時候執行


試玩其他人的程式:

開啟 "https://www.openprocessing.org/"  


將  "processing"  和手機做連結可以使用: