顯示具有 99231182廖中遠 標籤的文章。 顯示所有文章
顯示具有 99231182廖中遠 標籤的文章。 顯示所有文章

2013年12月1日 星期日

WEEK13 廖中遠








int buttons[6];

int notes[]={523.25,587.33,659.26,698.46};
void setup(){
  Serial.begin(9600);
  buttons[0]=2;
}
void loop(){
  int keyVal=analogRead(A0);
  Serial.println(keyVal);
  if(keyVal==1023){
    tone(8,notes[0]);
  }
  else if(keyVal>=990&&keyVal<=1010){
    tone(8,notes[1]);
  }
   else if(keyVal>=505&&keyVal<=515){
    tone(8,notes[2]);
  }
   else if(keyVal>=5&&keyVal<=10){
    tone(8,notes[3]);
  }
  else{
    noTone(8);
  }
}






#include <Servo.h>

Servo myServo;

int const potPin=A0;
int potVal;
int angle;
void setup(){
  myServo.attach(9);

  Serial.begin(9600);
}

void loop(){
  potVal=analogRead(potPin);
  Serial.print("potVal:");
  Serial.print(potVal);

  angle=map(potVal,0,1023,0,179);
  Serial.print("angle:");
  Serial.println(angle);

  myServo.write(angle);
  delay(15);
}


2013年11月17日 星期日

\WEEK11 廖中遠 閃閃燈Arduno Blink












 void setup(){
 pinMode(13,OUTPUT);
 pinMode(12,OUTPUT);
 pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
digitalWrite(10,HIGH);
delay(50);
digitalWrite(10,LOW);
delay(50);
}

WEEK10 期中作業 免疫系統



float[]ballX=new float[50], ballY=new float[50];
float[]ballVX=new float[50], ballVY=new float[50];
float[]ball2X=new float[50], ball2Y=new float[50];
float[]ball2VX=new float[50], ball2VY=new float[50];
float imgManX=280, imgManY=300, S=20;
float imgMan2X=310, imgMan2Y=300, S2=20;
int top=0;
PImage imgBall;
PImage imgBall2;
PImage imgMan;
PImage imgMan2;
PImage imgBack;
PImage imgWin;
PImage imgLose;
int total=0;
int total2=0;
int countDown=20*30;
import ddf.minim.*;
Minim m;
AudioPlayer la;
AudioPlayer ha;
AudioPlayer bg;



void setup() {
  size(600, 600);
  m=new Minim(this);
  la=m.loadFile("LASER.wav");
  ha=m.loadFile("hammeronce.wav");
  bg=m.loadFile("01.mp3");
  bg.play();
  imgBack=loadImage("987.jpg");
  imgWin=loadImage("456.jpg");
  imgLose=loadImage("654.jpg");
  imgMan=loadImage("123.png");
  imgMan2=loadImage("321.png");
  imgBall=loadImage("http://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Sida-aids.png/36px-Sida-aids.png");
  for (int i=0;i<50;i++) {
    newBall(i);
  }
  imgBall2=loadImage("http://lt.gameone.com/weapon_images/k53_m1ggnwclzsax.gif");
  for (int i=0;i<50;i++) {
    newBall2(i);
  }
}




void draw() {

  background(0);

  if (countDown>0) {
    background(255);

    image(imgBack, 0, 0, 600, 600);

    countDown--;
    fill(0);
    text("倒數"+countDown/30+"秒START", 260, 400);
    return;
  }

  background(0);

  imageMode(CENTER);

  fill(255, 0, 0);
  rect(0, 0, total*3, 50);
  rect(300, 0, total2*3, 50);

  fill(0);
  text("白血球"+total+"分", 30, 30);
  fill(0);
  text("病毒"+total2+"分", 500, 30);

  image(imgMan, imgManX, imgManY);
  image(imgMan2, imgMan2X, imgMan2Y);


  for (int i=0;i<50;i++) {
    image(imgBall, ballX[i], ballY[i], 20, 20);
    ballX[i]+=ballVX[i];
    ballY[i]+=ballVY[i];
    if (ballX[i]<0||ballX[i]>600||ballY[i]<0||ballY[i]>600)newBall(i);
    if (dist(ballX[i], ballY[i], imgManX, imgManY)<S) {
      ballX[i]=0;
      total+=3;
      la.rewind();
      la.play();
    };
    if (dist(ballX[i], ballY[i], imgMan2X, imgMan2Y)<S2) {
      ballX[i]=0;
      total2-=5;
      ha.rewind();
      ha.play();
    };
  }
  for (int i=0;i<50;i++) {
    image(imgBall2, ball2X[i], ball2Y[i], 20, 20);
    ball2X[i]+=ball2VX[i];
    ball2Y[i]+=ball2VY[i];
    if (ball2X[i]<0||ball2X[i]>600||ball2Y[i]<0||ball2Y[i]>600)newBall2(i);
    if (dist(ball2X[i], ball2Y[i], imgManX, imgManY)<S) {
      ball2X[i]=0;
      total-=5;
      ha.rewind();
      ha.play();
    };
    if (dist(ball2X[i], ball2Y[i], imgMan2X, imgMan2Y)<S2) {
      ball2X[i]=0;
      total2+=3;
      la.rewind();
      la.play();
    };
  }

  if (total<0)
  {
    m.stop();
    background(255);
    image(imgLose, 300, 300, 600, 600);
    S=0;
    S2=0;
  }
  if (total2<0)
  {
    m.stop();
    background(255);
    image(imgWin, 300, 300, 600, 600);
    S=0;
    S2=0;
  }
  if (total>=100)
  {
    m.stop();
    background(255);
    image(imgWin, 300, 300, 600, 600);
    S=0;
    S2=0;
  }
  if (total2>=100)
  {
    m.stop();
    background(0);
    image(imgLose, 300, 300, 600, 600);
    S=0;
    S2=0;
  }
}




void newBall(int i) {
  float angle=random(2*PI);
  ballVX[i]=cos(angle);
  ballVY[i]=sin(angle);
  int dir=int(random(4));
  if (dir==0) {
    ballX[i]=random(600);
    ballY[i]=0;
  }
  else if (dir==1) {
    ballX[i]=random(600);
    ballY[i]=600;
  }
  else if (dir==2) {
    ballX[i]=0;
    ballY[i]=random(600);
  }
  else if (dir==3) {
    ballX[i]=600;
    ballY[i]=random(600);
  }
}
void newBall2(int i) {
  float angle=random(2*PI);
  ball2VX[i]=cos(angle);
  ball2VY[i]=sin(angle);
  int dir=int(random(4));
  if (dir==0) {
    ball2X[i]=random(600);
    ball2Y[i]=0;
  }
  else if (dir==1) {
    ball2X[i]=random(600);
    ball2Y[i]=600;
  }
  else if (dir==2) {
    ball2X[i]=0;
    ball2Y[i]=random(600);
  }
  else if (dir==3) {
    ball2X[i]=600;
    ball2Y[i]=random(600);
  }
}

void keyPressed()
{
  if (key=='8') {
    imgManY-=10;
  }
  if (key=='5') {
    imgManY+=10;
  }
  if (key=='6') {
    imgManX+=10;
  }
  if (key=='4') {
    imgManX-=10;
  }

  if (key=='w') {
    imgMan2Y-=10;
  }
  if (key=='s') {
    imgMan2Y+=10;
  }
  if (key=='d') {
    imgMan2X+=10;
  }
  if (key=='a') {
    imgMan2X-=10;
  }
}

2013年10月21日 星期一

廖中遠HW006

int []sequence=new int[1000];
PImage img;
void setup () {
  size(300, 500);
  img=loadImage("http://hydra-media.cursecdn.com/terraria-zhtw.gamepedia.com/c/c3/Zombie.png");
  for (int i=0;i<1000;i=i+1) {
    sequence[i]= int(random(3));
  }
}
int now=0;
void draw() {
  background(0);
  for (int i=now;i<now+5;i++) {
    image(img, sequence[i]*100, 400-(i-now)*100);
  }
}
void keyPressed(){
 if(key==sequence[now]+'1') now++;

}

2013年10月7日 星期一

廖中遠WHEEK02


廖中遠HW05

滑鼠移動轉動顏色改變



int[]X=new int[100];
int[]Y=new int[100];
int N=0;
void setup() {
  size(640, 480);

  colorMode(RGB, 640);
}
float angle=0;
void draw() {
  angle+=0.005;
  background(#77DEE3);
  for (int i=0;i<N;i++) {
    flower(X[i], Y[i]);
  }
  flower(mouseX, mouseY);
}
void flower(int x, int y) { 
  pushMatrix(); 
  translate(x, y);
  rotate(angle);


  for (int i=0;i<14;i=i+1) {
    if (mousePressed) {
      fill(#38FAD4);
    }
    else {
      fill(640, mouseX, mouseY);
    }
    rotate(PI/7);
    ellipse(00, 50, 30, 100);
  }

  rotate(-angle*2);
  for (int i=0;i<14;i=i+1) {
    if (mousePressed) {
      fill(#3BEDFF);
    }
    else {
      fill(640, mouseY, 640);
    }
    rotate(PI/5);
    ellipse(0, 0, 20, 100); 
    fill(#FCE25C);
    ellipse(0, 0, 50, 50);
  }
  popMatrix();
}
void mousePressed() {
  X[N]=mouseX;
  Y[N]=mouseY;
  N++;
  if (N>=100) N=0;
}


我有可能要做這個遊戲

2013年9月30日 星期一

廖中遠 HW04




PImage imgBird;
void setup() {
  size(400, 400);
  background(255);
  noStroke();
  colorMode(HSB, 100);
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      stroke(i, j, 100);
      point(i, j);
    }
  }  
  //imgBird=loadImage("http://www.uusucai.com/d/file/gif/2013/04/24/14cfda7a5eb86e79690b087366dccd4d.gif");
  imgBird=loadImage("pen1.gif");
  imageMode(CENTER);
  cursor(imgBird);


  stroke(#000000);
  strokeWeight(1);  
  line(330, 20, 380, 20);

  strokeWeight(4);  
  line(330, 40, 380, 40);

  strokeWeight(10);  
  line(330, 70, 380, 70);
}

void draw() {
}
void mousePressed() {
  if (mouseX<100 && mouseY<100) stroke(mouseX, mouseY, 100);
  
  if(mouseX>300 && mouseY<30) strokeWeight(1);
  else if(mouseX>300 && mouseY<50) strokeWeight(4);
  else if(mouseX>300 & mouseY<90) strokeWeight(10);
}
void mouseDragged() {
  line(mouseX, mouseY, pmouseX, pmouseY);
}
void keyPressed() {
    if (key=='s')    save("draw.jpg");
  }



2013年9月23日 星期一

WEEK03 廖中遠作業



int nowColor=1;
int newX, newY;
int[][] array = new int [19][19];
void setup(){
  size(1000,1000);
}
void draw(){
 background(255,226,111);
 noFill();
 strokeWeight(4);
 rect(50,50,900,900);
 strokeWeight(2);
 for (int i=0;i<18;i=i+1){
  line(50,50+i*50,950,50+i*50);
  line(50+i*50,50,50+i*50,950);
}
 fill(#E85E0E);
 ellipse(newX*50+50, newY*50+50,50,50);

 for(int i=0;i<19;i=i+1){
   for(int j=0;j<19;j=j+1){
     if(array[i][j]==1){fill(0); ellipse(i*50+50,j*50+50,50,50);}
     if(array[i][j]==2){fill(255); ellipse(i*50+50,j*50+50,50,50);}
   }
 }
}
void mousePressed(){
  array[newX][newY]=nowColor;
  if(nowColor==1)nowColor=2;
  else if(nowColor==2)nowColor=1;
}
void mouseMoved(){
   newX=(mouseX-25)/50;
   newY=(mouseY-25)/50;
   if(newX > 18) newX=18;
   if(newY > 18) newY=18;
}