2019年1月12日 星期六
Week16-04160453
今天寫除了飛機可以社子彈並允實落下,但是無法解決子但碰到允實讓允實消失,希望可以在廉假時解決這個問題
PImage imgplane, imgbg, imgs, imgS, imgfire;
float planeX=250, planeY=600;
float enemyX, enemyY, enemyVX, enemyVY;
float[] stoneX = new float[10000];
float[] stoneY = new float[10000];
float[] stone1X = new float[10000];
float[] stone1Y = new float[10000];
boolean[] stoneDie = new boolean[10000];
boolean[] stone1Die = new boolean[100];
/*
void reborn(int i){
fireX[i]=mouseX-16;
fireY[i]=mouseY-100;
fireVY[i]=-20;
}
*/
void setup() {
size(600, 800);
imgplane = loadImage("plane.png");
imgbg = loadImage("bg.jpg");
imgs = loadImage("stone1.png");
imgfire = loadImage("fire.png");
for(int i=0;i<100;i++){
stoneX[i] = random(0,500);
stoneY[i] =-random(2000);
stoneDie[i] = false;
stone1X[i] = random(0,500);
stone1Y[i] =-random(2000);
stone1Die[i] = false;
}
}
void draw() {
image(imgbg, 0, 0, width, height);
image(imgplane, mouseX-40, mouseY-60, 80, 120);
for(int i=0;i<fireN;i++){
if(stoneDie[i])continue;
image(imgs,stoneX[i],stoneY[i],70,70);
stoneY[i]+=9;
if(stoneY[i]>650) stoneY[i]=-2000+800;
image(imgfire,fireX[i],fireY[i], 30, 60);
fireY[i]+=fireVY[i];
fireVY[i]-= 0.98;
//if(dist(fireX-50,fireY-50,stoneX[i],stoneY[i])<30)
//stoneDie[i]=true;
}
}
float []fireX=new float[10000];
float []fireY=new float[10000];
float []fireVY=new float[10000];
boolean []fireFlying = new boolean[10000];
int fireN=0;
void mousePressed(){
fireFlying[fireN]=true;
fireX[fireN]=mouseX-16;
fireY[fireN]=mouseY-100;
fireVY[fireN]=-20;
fireN++;
}
Week14-04160453
Arduino LED燈 閃爍
到此GitHub網址下載Bounce之程式:
void setup()
{
pinMode(13,OUTPUT); //設定Led為output
}
void loop()
{
int value=analogRead(A0);
digitalWrite(13,HIGH); //LED 閃爍
delay(value);
digitalWrite(13,LOW);
delay(value);
}
---------
程式如下:
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
2018年12月23日 星期日
Week13-04160453
期末作品
青蛙過馬路,五個按鈕,前後左右和重新開始
今日流程: 去蝦皮尋找材料
讓maker uno可以被電腦讀到
1.去 https://makeruno.com.my/getting-started/?fbclid=IwAR1Pchx-Z_Y5zZ64K8YsT5zxEPbLvAmo7Kf3A4CCxYCMnJS85KOO6kWpmew 下載 CH341 Driver for Windows here
2.打開CH341SER
3.執行
4.出現這個就代表成功
2018年11月22日 星期四
Week11-04160453
1.MyLED
讓MAKER UNO LED 可以依次亮起
void setup() {
// put your setup code here, to run once:
for(int i=2;i<=13;i++){
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int i=2;i<=13;i++){
digitalWrite(i,HIGH);
delay(300);
}
for(int i=2;i<=13;i++){
digitalWrite(i,LOW);
}
}
2.
MAKER UNO 音樂
3.LED+音樂 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2018年11月1日 星期四
Week08-04160453
1.成果展示
青蛙過馬路
玩法:
目標讓青蛙到馬路對面來回過馬路3次,方向件上下左右控制青蛙,車速會在青蛙每次成功過馬路後加快
玩法:
目標讓青蛙到馬路對面來回過馬路3次,方向件上下左右控制青蛙,車速會在青蛙每次成功過馬路後加快
Youtube連結:
youtube: https://youtu.be/kg0zpv7lvd0
2018年10月18日 星期四
Week06-04160453
1.水果忍者
float fruitX,fruitY,fruitVX,fruitVY;
void setup(){
size(800,600);
fruitX=30; fruitVX=3;
fruitY=700; fruitVY=-35;
}
void draw(){
background(0);
ellipse(fruitX,fruitY,100,100);
fruitX+=fruitVX;
fruitY+=fruitVY;
fruitVY+=0.98;
}
float[] fruitX=new float[20];
float[] fruitY=new float[20];
float[] fruitVX=new float[20];
float[] fruitVY=new float[20];
void setup(){
size(800,600);
for(int i=0;i<20;i++){
fruitX[i]=random(800)//800個亂數; fruitVX[i]=3;
fruitY[i]=700; fruitVY[i]=-35;
}
}
void draw(){
background(0);
for(int i=0;i<20;i++){
ellipse(fruitX[i],fruitY[i],100,100);
fruitX[i]+=fruitVX[i];
fruitY[i]+=fruitVY[i];
fruitVY[i]+=0.98;
}
}
float[] fruitX=new float[20];
float[] fruitY=new float[20];
float[] fruitVX=new float[20];
float[] fruitVY=new float[20];
void reborn(int i){
fruitX[i]=random(800); fruitVX[i]=random(6)-3;
fruitY[i]=700; fruitVY[i]=-35;
}
void setup(){
size(800,600);
for(int i=0;i<20;i++){
reborn(i);
}
}
void draw(){
background(0);
for(int i=0;i<20;i++){
if(dist(mouseX,mouseY,fruitX[i],fruitY[i])<=50){
reborn(i); continue;
}
ellipse(fruitX[i],fruitY[i],100,100);
fruitX[i]+=fruitVX[i];
fruitY[i]+=fruitVY[i];
fruitVY[i]+=0.98;
if(fruitY[i]>700) reborn(i);
}
}
2018年10月11日 星期四
Week05-04160453
接雞蛋
float[] eggX = new float[100];float[] eggY = new float[100];
void setup(){
size(600,800);
for(int i=0;i<100;i++){
eggX[i] = random(100,700);
eggY[i] =-random(2000);
}
}
void draw(){
background(255);
for(int i=0;i<100;i++){
ellipse(eggX[i],eggY[i],80,100);
eggY[i]+=5;
}
}
float[] eggX = new float[100];
float[] eggY = new float[100];
boolean[] eggDie = new boolean[100];
void setup(){
size(600,800);
for(int i=0;i<100;i++){
eggX[i] = random(100,700);
eggY[i] =-random(2000);
eggDie[i] = false;
}
}
void draw(){
background(255);
rect(mouseX-50,mouseY-25,100,50);
for(int i=0;i<100;i++){
if(eggDie[i])continue;
ellipse(eggX[i],eggY[i],80,100);
eggY[i]+=5;
if(eggY[i]>700) eggY[i]=-2000+800;
if(dist(mouseX-50,mouseY-25,eggX[i],eggY[i])<50)
eggDie[i]=true;
}
}
2018年10月4日 星期四
Week04-04160453
1.字
void setup(){size(800,600);
}
void draw(){
fill(255,255,255); //設定正方形的顏色為白色
rect(100,100,100,100); //畫正方形
textSize(80); //設定字的大小
fill(0,0,0); //設定字的顏色
text("Star!",100,100); // 設定字
}
2.子彈
void setup(){
size(800,600);
}
void draw(){
background(255); //設定背景
fill(255,0,0);
rect(100,100,100,100);
textSize(80);
if(bulletFlying){ //如果子彈在飛
fill(255,0,0); //子彈顏色
ellipse(bulletX,bulletY,50,50); //子彈(子彈X座標,子彈Y座 標,子彈大小,子彈大小)
bulletY+=3; //子彈Y座標的加速度
}
}
float bulletX=100 ,bulletY=100; //宣告子彈的XY座標
boolean bulletFlying=false; //宣告bulletFlying一開始試 false
void keyPressed(){ //如果有按鍵盤
bulletFlying=true; //bulletFlying是true
3.有限制的子彈
void setup(){
size(800,600);
}
void draw(){
background(255);
fill(255,0,0);
rect(100,100,100,100);
textSize(80);
for(int i=0;i<=bulletN;i++){
if(bulletFlying[i]){
fill(255,0,0);
ellipse(bulletX[i],bulletY[i],50,50);
bulletX[i]+=3;
}
}
}
float []bulletX = new float[100];
float []bulletY = new float[100];
int bulletN=0;
boolean []bulletFlying = new boolean[100];
void keyPressed(){
bulletFlying[bulletN] = true;
bulletX[bulletN]=100; //子彈的X座標
bulletY[bulletN]=100; //子彈的Y座標
bulletN++;
}
4.比較簡單的子彈
PImage imgBullet,imgBG;
void setup(){
size(800,600);
imgBG = loadImage("BG.jpg");
imgBullet = loadImage("bullet.png");
imageMode(CENTER); //圖片從中心出現
}
void draw(){
image(imgBG,width/2,width/2,width,width);
image(imgBullet, mouseX,mouseY,100,100);
for(int i=0;i<bulletN;i++){
if(bulletFlying[i]){
image(imgBullet,bulletX[i],bulletY[i],100,100);
bulletX[i]+=3;
}
}
}
float []bulletX = new float[100];
float []bulletY = new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void keyPressed(){
bulletFlying[bulletN]=true;
bulletX[bulletN]=mouseX;
bulletY[bulletN]=mouseY;
bulletN++;
}
5.重力球
PImage imgBullet,imgBG,imgBall;void setup(){
size(800,600);
imgBG = loadImage("BG.jpg");
imgBullet = loadImage("bullet.png");
imgBall = loadImage("ball.png");
imageMode(CENTER);
}
void draw(){
image(imgBG,width/2,width/2,width,width);
image(imgBall, mouseX,mouseY,100,100);
for(int i=0;i<bulletN;i++){
if(bulletFlying[i]){
image(imgBall,bulletX[i],bulletY[i],100,100);
bulletY[i]+=bulletVY[i];
bulletVY[i] +=0.98;
}
}
}
float []bulletX = new float[100];
float []bulletY = new float[100];
float []bulletVY = new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void keyPressed(){
bulletFlying[bulletN]=true;
bulletX[bulletN]=mouseX;
bulletY[bulletN]=mouseY;
bulletVY[bulletN]=-20;
bulletN++;
}
期中作品
青蛙過馬路青蛙一開始在最底層,中間會有車子跑過, 青蛙成功過馬路就算成功
2018年9月27日 星期四
Week03-04160453
1.畫圖
在圓中間畫三角形
void setup(){
size(500,500);
}
void draw(){
ellipse(250,250,480,480);
for(float angle=0;angle<PI*2///360;angle+=PI/3///180){ ///用for迴圈設定角度
triangle(250,250,
250+240*cos(angle), 250+240*sin(angle),
250+240*cos(angle+PI/3),250+240*sin(angle+PI/3));
///畫三角形(圓心,圓心,三角形1的邊,三角形1的邊,
三角形2的邊,三角形2的邊);
}
}
void setup(){
size(500,500);
}
void draw(){
ellipse(250,250,480,480);
for(float angle=0;angle<PI*2;angle+=PI/3){
for(int R=0;R<=240;R+=10){ ///用for設定三角型邊的長
noFill();
triangle(250,250,
250+R*cos(angle), 250+R*sin(angle),
250+R*cos(angle+PI/3),250+R*sin(angle+PI/3));
}
}
}
void setup(){
size(800,400);
}
void myTriangle(int cx, int cy){
float a= -PI/2;
for(int R=15;R>0;R-=5){
triangle(cx+R*cos(a),cy+R*sin(a),
cx+R*cos(a+2*PI/3),cy+R*sin(a+2*PI/3),
cx+R*cos(a-2*PI/3),cy+R*sin(a-2*PI/3) );
}
}
void draw(){
background(255);
for(int cx=20;cx<800;cx+=40){
for(int cy=20;cy<400;cy+=40) ///設定三角形的中心{
myTriangle(cx,cy);
}
}
}
2.小遊戲
鍵盤可以控制的mario
PImage imgMario;float marioX=0, marioY=0;
void setup(){
size(400,600);
imgMario = loadImage("mario.png");
}
void draw(){
background(255);
image(imgMario,marioX,marioY,100,150);
}
void keyPressed(){ //鍵盤設定
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
有重力的mario
PImage imgMario;
float marioX=0, marioY=0,marioVX=2,marioVY=0,marioAX=0,marioAY=0.1;
//mario的加速度設定
void setup(){
size(400,600);
imgMario = loadImage("mario.png");
}
void draw(){
//background(255);
image(imgMario,marioX,marioY,100,150);
marioX += marioVX; marioY += marioVY;
marioVX+= marioAX; marioVY+= marioAY;
}
void keyPressed(){
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
有邊界
PImage imgMario;
float marioX=0, marioY=0,marioVX=5,marioVY=0,marioAX=0,marioAY=0.1;
void setup(){
size(400,600);
imgMario = loadImage("mario.png");
}
void draw(){
//background(255);
image(imgMario,marioX,marioY,100,150);
marioX += marioVX; marioY += 0;
marioY += marioVY; marioVY+= 0.98;
if(marioY>500){
marioVY = -marioVX *0.8;
marioY=500;
}
if(marioX>300)marioVX = -marioVX;
if(marioX<0) marioVX = -marioVX;
}
void keyPressed(){
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
訂閱:
文章 (Atom)


























