顯示具有 05051106_游竣傑 標籤的文章。 顯示所有文章
顯示具有 05051106_游竣傑 標籤的文章。 顯示所有文章

2020年6月18日 星期四

Programming-week17

strange circle to line

pic:

program:
void setup() {
  size(300, 300);
}
float x=200, y=150;// 要動 要變數
float vx=0, vy=0;
void draw() {
  background(#002966);
  stroke(#b7efff);
  line(100, 150, x, y);

  fill(#b7efff);
  noStroke();
  ellipse(100, 150, 13, 13);
  ellipse(x, y, 13, 13);
  if (!mousePressed) {//沒又按下去...等於放開,讓他做運動
    float dx=x-100, dy=y-150;
    float len=sqrt(dx*dx+dy*dy);
    vx -= dx*(len-100)/len*0.1;//越大,越強
    vy -= dy*(len-100)/len*0.1;
    x += vx;
    y += vy;
  }
}
void mouseDragged() {
  x=mouseX; 
  y=mouseY;
  vx = 0;
  vy = 0;//拉動時,不能有速度
}

mouse control fish or cat

pic:

program:
void setup() {
  size(400, 300);
}
float x=200, y=150;// 要動 要變數
void draw() {
  background(#002966);
  fill(255);
  rect(x, y, 80, 20);//魚, 每次往你的mouse移動1/10
  float dx=x-mouseX, dy=y-mouseY;//float len=sqrt(dx*dx+dy*dy);
  x -= dx*0.1;
  y -= dy*0.1;
}

2020年6月11日 星期四

Programming-week15

review 速度之王



review 10數排序

Programming-week16

little men walk

pic:
down

up

left 
right
program:

PImage img;
void setup(){
    size(500,500);
    img=loadImage("img.jpg");
}
int a=0, b=0;
void draw(){
  background(255);
  image( img.get(141*a, 211*b, 141,211), 0,0);
  if(frameCount%30==0) a = (a+1)%4;
}
void keyPressed(){
  if(keyCode==DOWN) b=0;
  if(keyCode==UP) b=1;
  if(keyCode==LEFT) b=2;
  if(keyCode==RIGHT) b=3;
}

2020年5月28日 星期四

Programming-week14

angry bird sound

照片:


程式碼:

import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioPlayer player2;//TODO2
PImage imgBird, imgPig;//TODO3
void setup(){
  size(500,400);
  minim = new Minim(this); 
  player = minim.loadFile("song.mp3");
  player.play();
  player2 = minim.loadFile("pig.wav");//TODO2
  
  imgBird=loadImage("bird.png");//圖檔如果沒有放好,會當掉 pointer
  imgPig =loadImage("pig.gif");//TODO3 我們的豬
  imageMode(CENTER);//以正中心,當座標
}
float []pigX=new float[20];//TODO3
float []pigY=new float[20];//TODO3
int pigN=0;//有幾隻豬
float birdX=100, birdY=300, oldX, oldY, vx=0, vy=0;//之前的鳥在哪裡
boolean bMoving=false;//if(判斷) ex. if(bMoving)...
void draw(){
  background(255);//清背景
  for(int i=0; i<pigN; i++){//TODO3
    image(imgPig, pigX[i], pigY[i], 100,100);//TODO3
  }
  image(imgBird, birdX,birdY,100,100);//不能一直跟著mouse動,改用birdX,birdY
  if(bMoving) line(birdX,birdY, oldX,oldY);//有按到,才能動它
  birdX+=vx; birdY+=vy;//鳥要照速度去飛!!!
  if(birdX>450 || birdX<50) vx = -vx*0.95;//撞到邊界,會改變方向,相反的方向
  if(birdY>350 || birdY<50) vy = -vy*0.95;//撞到邊界,會改變方向,相反的方向
}
void mouseReleased(){
  if(bMoving){
    bMoving=false;//放開時,就不能動了
    vx=(oldX-mouseX)/10; vy=(oldY-mouseY)/10;// 0.1倍
  }
}
void mousePressed(){//按下去,才會開始動
  if(mouseButton==RIGHT){//TODO2
    player2.rewind();//倒到最前面
    player2.play();//再播!!!
    pigX[pigN]=mouseX;//TODO3
    pigY[pigN]=mouseY;//TODO3
    pigN++;//TODO3
  }
  if( dist(mouseX,mouseY, birdX,birdY)<50){
    oldX=birdX; oldY=birdY;
    bMoving=true;///按下去時,如果有按到,才能動它
  }
}
void mouseDragged(){//按下去,才會開始動
  if(bMoving) {//有按到,才能動它
    birdX=mouseX; birdY=mouseY;
  }
}

2020年5月21日 星期四

Programming-week13

angry bird advance 彈射

照片:


主程式:
PImage imgBird;
void setup() {
  size(500, 400);
  imgBird=loadImage("bird.png");
  imageMode(CENTER);
}
float birdX=100, birdY=300, oldX, oldY, vx=0, vy=0;
boolean bMoving=false;
void draw() {
  background(255);
  image(imgBird, birdX, birdY, 100, 100);
  if (bMoving) line(birdX, birdY, oldX, oldY);
  birdX+=vx; 
  birdY+=vy;
  if (birdX>450 || birdX<50) vx = -vx*0.95;
  if (birdY>350 || birdY<50) vy = -vy*0.95;
}
void mouseReleased() {
  if (bMoving) {
    bMoving=false;
    vx=(oldX-mouseX)/10; 
    vy=(oldY-mouseY)/10;
  }
}
void mousePressed() {
  if (dist(mouseX, mouseY, birdX, birdY)<50) {
    oldX=birdX; 
    oldY=birdY;
    bMoving=true;
  }
}
void mouseDragged() {
  if (bMoving) {
    birdX=mouseX; 
    birdY=mouseY;
  }
}

2020年5月14日 星期四

Programming-week12

angry bird

照片:


程式碼:
PImage imgBird, imgPig;
float birdX=200, birdY=200, oldX, oldY, vx=0, vy=0;
void setup(){
  size(400,400);
  imgBird=loadImage("bird.png");
  imgPig =loadImage("pig.gif");
  imageMode(CENTER);
}
void draw(){
  background(255);
  image(imgBird, birdX, birdY, 100, 100);
  birdX+=vx; birdY+=vy;
}
void mousePressed(){
  oldX=birdX; oldY=birdY;
}
void mouseDragged(){
  birdX=mouseX; birdY=mouseY;
}
void mouseReleased(){
  vx = (oldX-birdX)/10;
  vy = (oldY-birdY)/10;
}

2020年5月7日 星期四

Programming-week11

BUBBLE

泡泡位置
照片:

程式碼:

int []a=new int[10];//Java's Array
//int []a={6,3,5,9,1,0,4,2,7,8};
//int []a={1,2,3,5,0,4,6,7,8,9};
//int []a={9,8,7,6,5,4,3,2,1,0};
void setup() {
  size(500, 800);
  for (int i=0; i<10; i++) {//random choose number
    a[i]=int(random(10));//亂數決定數字
  }
  textSize(36);
  textAlign(LEFT, TOP);
  showArray(y);
}
int y=0;
void showArray(int y) {
  for (int i=0; i<10; i++) {
    fill(255); 
    rect(i*50, y, 50, 50);
    fill(0);       
    text(a[i], i*50, y);
  }//秀文字
}
void draw() {
}
void mousePressed() {
  for (int i=0; i<10-1; i++) {//i從左到右 0 1 2 3 ... 8
    if (a[i] > a[i+1]) {
      int temp=a[i];
      a[i]=a[i+1];
      a[i+1]=temp;
      fill(255, 0, 0, 128);
      rect(i*50, y, 100, 50);
    }//R紅G綠B藍A半透明Alpha
  }
  y+=50;
  showArray(y);
}
-----------------------------------------------------------------------
Bubble位置及顏色變化
照片:


程式碼:

void setup() {//Lyto Different Color

  size(300, 500);//下面300x300
  colorMode(HSB);
  
}//300x300 分成 2x2, 每個圓 300/2
int ansX=2, ansY=3;
int N=5;//單邊有幾個大圓?
int H=255, S=255, B=255;//Hus色相/色調, Sat飽, Bright高度
void draw() {
  background(0);///300x300 分成 2x2, 每個圓 300/2
  int R=300/N, w=R/2;
  for (int x=0; x<N; x++) {
    for (int y=0; y<N; y++) {
      if(x==ansX && y==ansY) fill(H+10, S-35, B-45);
      else fill(H, S, B);
      ellipse(0+w+x*R, 200+w+y*R, R, R);
    }
  }
}
void mousePressed(){
  ansX = int(random(N)); ansY = int(random(N));
  H+=16;
  if(H>255)H=0;
}

2020年4月30日 星期四

Programming-week10

week10

教圓變化
照片:

程式碼:
void setup(){
  size(300,500);
}
int r=0;
void draw(){
  background(0);
  ellipse(50, 200+50, r, r);
  ellipse(50, 200+50+100, r, r);
  ellipse(50, 200+50+100+100, r, r);
  
  ellipse(50+100, 200+50, r, r);
  ellipse(50+100, 200+50+100, r, r);
  ellipse(50+100, 200+50+100+100, r, r);
  
  ellipse(50+100+100, 200+50, r, r);
  ellipse(50+100+100, 200+50+100, r, r);
  ellipse(50+100+100, 200+50+100+100, r, r);
  
  if(r<100) r+=2;
  else r=0;
}
-------------------------
Lyto Different Color Game  FB Game
照片:

程式碼:
void setup() {
  size(300, 500);
  ansX= 3;
  ansY= 2;
}
int r=0;
int ansX, ansY, win=0;
void draw() {
  if (win==1) background(255, 255, 0);
  else background(0);
  int n=5;
  int w=300/(2*n);
  for (int x=0; x<n; x++) {
    for (int y=0; y<n; y++) {
      if (x==ansX && y==ansY)fill(150);
      else fill(255);
      int cx=w+x*2*w, cy=200+w+y*2*w;
      ellipse(cx, cy, r, r);
      if (mousePressed && dist(mouseX, mouseY, cx, cy)<w) {
        if (ansX==x && ansY==y) {
          win=1; 
          r=0;
          ansX= int(random(n));
          ansY= int(random(n));
        }
      }
    }
    if (r< 2*w) r+=2;
  }
}

2020年4月23日 星期四

Programming-week09

小精靈

小精靈一直動
照片:


程式碼:
void setup(){
    size(600,300);
}

int x=50, y=50, a=45, da=1; //da是角度a的改變量,先放1
void draw(){
  background(0);
  fill(#F5ED02);//顏色
  arc(x,y,100,100, radians(a),radians(360-a),PIE);
  x++;
  a+= da;//張大或縮小
  if(a>60) da=-1;//太大?縮小
  if(a<=0) da=+1;//太小?放大
}

---------------------------------------------
在小精靈前放點點豆子
照片:


程式碼:
void setup(){
    size(800,600);
}
int [][]bean={ ///這是 Java語言的陣列
  {1,1,1,1,1,1,1,1},
  {1,1,1,1,1,1,1,1},
  {1,0,1,1,1,1,1,1},
  {1,1,1,1,1,1,1,1},
  {1,1,1,1,1,1,1,1},
  {1,1,1,1,1,1,1,1}};
int x=50, y=50, a=45, da=1; //da是角度a的改變量,先放1
void draw(){//1秒會叫draw()叫60次
  background(0);
  fill(#F5ED02);//顏色
  for(int i=0;i<6;i++){
    for(int j=0;j<8;j++){
      if(bean[i][j]==1)ellipse( j*100+50, i*100+50, 6, 6);
      if( dist(x, y, j*100+50, i*100+50)<50 )bean[i][j]=0;
    }
  }
  arc(x,y,100,100, radians(a),radians(360-a),PIE);
  x++;
  a+= da;//張大或縮小
  if(a>60) da=-1;//太大?縮小
  if(a<=0) da=+1;//太小?放大
}
----------------------------------------------------------------------------

2020年4月16日 星期四

Programming-week08

WEEK08

小精靈:

程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  //circle(100,100,100);
  //ellipse(100,100,100,100);
  angle=mouseX;
  arc(100,100,100,100,radians(angle),radians(360-angle),PIE);///45' => 360'-45'
}//橢圓 座標   寬 高

----------------------------------------------------------------------------------------------------
小精靈一直開口閉口:


程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  ///0123...60 61...120...180.. 一直增加的數字
  //0...............120  => %120 0..120的數字
  //       >60 (120-x)
  /// 0度...60度...0度...60度 angle = mouseX;
  angle = (frameCount*2) %120;//更快了...
  if(angle>60) angle=120-angle;
  arc(100,100,100,100,
  radians(angle),radians(360-angle),PIE);
  ///45' => 360'-45'
}
-----------------------------------------------------------------------------------------------------------
改顏色:


程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  angle = (frameCount*2) %120;//更快了...
  if(angle>60) angle=120-angle;
  
  //fill(#FCD50D);//要填充的色彩(可以Tool-Color Selector)
  fill(0,64,128);//小畫家也可以滴管Color Select,在編輯色彩
  arc(100,100,100,100,
  radians(angle),radians(360-angle),PIE);
}


------------------------------------------------------------
改彩色:


程式碼:
void setup(){
  size(300,200);
}
int angle=45;
void draw(){
  background(255);
  angle = (frameCount*2) %120;//更快了...
  if(angle>60) angle=120-angle;
 
  //fill(#FCD50D);//要填充的色彩(可以Tool-Color Selector)
  colorMode(HSB);//彩色
  fill(frameCount%255,255,255);//小畫家也可以滴管Color Select,在編輯色彩
  arc(100,100,100,100,
  radians(angle),radians(360-angle),PIE);
}


2020年4月9日 星期四

Programming-week07

week07
加入teams 疫情時可使用
--------------------------------------------------------------------------------------------------------------------------
今天教指標
指標進階-1
///重點: Pointer指標
/// /////   ->
#include <stdio.h>
int main(){

    int a=100;
    int b=200;
    int c=300;
    int *p;///(1)指標宣告: p是一個指標, 要指到一個整數
    p = &a;///(2)指標的設值: &符號(and)叫 address住址
    printf(" %d \n", *p);///(3)指標指到的東西,拿來用
 
    p = &b;///(2)指標的設值: &符號(and)叫 address住址
    printf(" %d \n", *p);///(3)指標指到的東西,拿來用

    p = &c;///(2)指標的設值: &符號(and)叫 address住址
    printf(" %d \n", *p);///(3)指標指到的東西,拿來用

}

指標進階-2
///重點: Pointer指標
/// /////   ->
#include <stdio.h>
char s1[30]="hello world I love you";
char s2[30]="I am a book and he is not";
int main(){
    char *p;///(1)指標宣告: p是一個指標, 要指到一個整數
    char a[10];
    p = s1;///(2)指標的設值: &符號(and)叫 address住址
    printf(" %s \n", p);///(3)指標指到的東西,拿來用

    p = s2;
    printf(" %s \n", p);
}

-----------------------------------------------------------
今天遊戲程式碼:
PImage img1;//有圖,向右
PImage img2;//有圖,向左
PImage img3;//有圖,向正
PImage img;//最後用這張圖來秀
void setup(){
  size(300,300);//記得把圖,放進程式碼裡喔!
  img1=loadImage("img1.png");
  img2=loadImage("img2.png");
  img3=loadImage("img3.png");
  img=img3;//先立正

}
void draw(){
  background(255);//背景清白色
  image(img, 100, 100);//畫圖
}
void keyPressed(){
  if(keyCode==LEFT) img=img2;
  if(keyCode==RIGHT) img=img1;
}
void keyReleased(){
  img=img3;//放開,就立正站好

}
--------------------------------------------------------------------------------------------------------------------------圖片:



--------------------------------------------------------------------------------------------------------------------------程式碼:
PImage img1, img2, img3;//有圖,向右,向左,向正
PImage img;//最後用這張圖來秀
float x=100, y=100, vx=0;//TODO: 用變數,讓程式有變化
void setup(){
  size(300,300);//記得把圖,放進程式碼裡喔!
  //fullScreen() ;
  img1=loadImage("right.png");
  img2=loadImage("left.png");
  img3=loadImage("up.png");
  img=img3;//先立正

}
void draw(){
  background(255);//背景清白色
  image(img, 100, 100);//畫圖
  x += vx;//TODO: Q: 為什麼會走?因為x被改!
}
void keyPressed(){
  if(keyCode==LEFT){
    img=img2; vx= -1;
  }else if(keyCode==RIGHT){
    img=img1; vx= +1;
  }
}
void keyReleased(){
  img=img3; vx=0;//放開,就立正站好
}
--------------------------------------------------------------------------------------------------------------------------
圖片:
---------------------------------------------------------------------------------
程式碼:
PImage img;
float x=100, y=100, vx=3, vy=0;
void setup(){
  size(500,500);
  img=loadImage("trump.png");
}
void draw(){
  background(255);
  image(img, x, y, 100, 100);
  x +=vx;
  y +=vy;
  vy += 0.98;
  if(x>400) vx = -3;
  if(x<0) vx = +3;
  if(y>400) vy = -vy*0.8;

}
---------------------------------------------------------------------------------圖片:

2020年3月26日 星期四

Programming-week04

彩色小球掉落
彩色 控制大小飛起
程式碼:
int []x = new int[1000];
int []y = new int[1000];
int []r = new int[1000];
color [] c = new color[1000];
int n =0;
void setup(){
    size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    fill(c[i]);
    circle(x[i],y[i],r[i]);
    y[i]--;
  }
  if(mousePressed)r[n-1]++;
}
void mousePressed(){
  x[n] = mouseX;
  y[n] = mouseY;
  r[n]=10;
  c[n] = color(random(255), random(255), random(255));
  n++;
}

------------------------------------------------------
class Bubble{
  int x;
  int y;
  int r;
  color c;
  Bubble(int _x, int _y, int _r){
    x=_x; y=_y; r=_r;
    c = color(random(255),random(255),random(255) );
}
void drawAndUpdate(){
  fill(c);
  circle(x,y,r);
  y--;
}
}
Bubble [] b=new Bubble[1000];
int n =0;
void setup(){
    size(400,400);
}
void draw(){
  background(255);
  for(int i=0;i<n;i++){
    b[i].drawAndUpdate();
  }
  if(mousePressed) b[n-1].r++;
}
void mousePressed(){
  b[n] = new Bubble(mouseX,mouseY,10);
  n++;
}
--------------------------------------------------
設計迷宮
程式碼:
size(300,300);

int [][]table={ {0,0,0,0,0},
                 {1,1,1,0,1},
                 {0,0,1,1,0},
                 {0,0,1,1,0} };
               
  for(int i=0;i<4;i++){
   for(int j=0;j<5;j++){
      if(table[i][j]==1)fill(255,0,0);
      else fill(128);
      rect( j*50, i*50, 50, 50);
  }
}


自走迷宮
程式碼:
int [][]table=new int[6][6];

void setup(){
    size(300,300);
}
void draw(){
  background(128);
  for(int i=0;i<6;i++){//vs.y
   for(int j=0;j<6;j++){//vs.y
      if(table[i][j]==1)fill(255,0,0);
      else fill(128);
      rect( j*50, i*50, 50, 50);
   }
  }
 }
void mousePressed(){
  int x = (mouseX)/50;
  int y = (mouseY)/50;
  table[y][x]=1;
}


2020年3月19日 星期四

Programming-week03

今天教怎麼插入圖片,進行遊戲
先設計三個圖


再加入程式中並寫程式

PImage img0, img1, img2;
void setup(){
  size(1200,1200);
  img0 = loadImage("front.png");
  img1 = loadImage("back.png");
  img2 = loadImage("middle.png");
}
int userX=250, userY=250;
void draw(){
  background(128);
  if(keyPressed && keyCode==LEFT){
    image(img0, userX,userY);
    userX--;
  }else if(keyPressed && keyCode==RIGHT){
    image(img1, userX,userY);
    userX++;
  }else image(img2, userX,userY);
}



 加入背景
30*30球球可以移動
程式碼:

PImage img;
void setup(){
  size(768,384);
  img = loadImage("map.jpg");
}
int userX=198,userY=328;
int []bulletX={0,0,0,0,0,0,0,0,0,0};
int []bulletY={0,0,0,0,0,0,0,0,0,0};
int []bulletFlying={0,0,0,0,0,0,0,0,0,0};
int n=0;
void draw(){
  background(img);
  ellipse(userX,userY,30,30);
  if(keyPressed&&keyCode==UP)  userY--;
  if(keyPressed&&keyCode==DOWN)  userY++;
  if(keyPressed&&keyCode==RIGHT)  userX++;
  if(keyPressed&&keyCode==LEFT)  userX--;
  for(int i=0;i<n;i++){
    if(bulletFlying[i]==1){
     ellipse(bulletX[i],bulletY[i],5,5);
     bulletY[i]-=2;
    }
  }
}
void mousePressed(){
  bulletX[n]=userX;
  bulletY[n]=userY;
  bulletFlying[n]=1;
  n++;
}