第一個小程式week02_1_GDMS_simulation
今天要做一個小房子能根據地震數值移動來模擬地震
從https://gdms.cwa.gov.tw/map.php獲取上周五地震的資訊包括左右、上下的晃動數值
將左右晃動的資料寫放進串列中,並劃一個方形房子左右移動HLE加入上下移動HLN加入
///week02-1float [] HLE = {-1042, -3479.7, 1003.7, -1669, -1639.6, -14219, -3655.1, -4917, 9363.2, -4271.8, -24, 681}; float [] HLN = {-17090, -13711, -22888, -19631, -23818, -18573, -19636, -15648, -18256, -15721, -17776, -15581}; int N = 12; void setup(){ size(500,500); frameRate(10);//change the speed } void draw(){ background(#FFFFF2); float dx = HLE[frameCount%N]/100;//從第一針開始播 float dy = HLN[frameCount%N]/100; rect(200+dx,300+dy,100,100);//畫方塊 }
第二個小程式week_02_2_PImage_loadImage_Image_chair
在網路上找一張圖在Processing印出來,先存檔後將圖片直接拉到Processing位置
///week02_2PImage img = loadImage("chair.jpg"); size(300,300); image(img,0,0,300,300);
第三個小程式week_02_3_PImage_loadImage_Image_chair
結合前兩個程式印出椅子,他的移動則是根據滑鼠座標
///week02_3PImage img; void setup(){ size(600,600); img= loadImage("chair.jpg"); } void draw(){ image(img,mouseX,mouseY,300,300); }
第四個小程式week_02_4_cinderella
公主走樓梯,用上一個程式的連續特性,如果滑鼠壓下去畫視窗,滑鼠放開畫公主
///week02_4PImage img , imgBox; void setup(){ size(600,600); img= loadImage("c.png"); imgBox= loadImage("b.png"); } void draw(){ imageMode(CENTER); if(mousePressed){ image(imgBox,mouseX,mouseY); }else{ image(img,300,300,220,300); } }
上傳github



沒有留言:
張貼留言