我想先回家內
-
PImage imgBird;
void setup(){
size(500,400);
imgBird=loadImage("bird.png");//圖檔如果沒有放好,會當掉 pointer
imageMode(CENTER);//以正中心,當座標
}
float birdX=100, birdY=300, oldX, oldY, vx=0, vy=0;//之前的鳥在哪裡
boolean bMoving=false;//if(判斷) ex. if(bMoving)...
void draw(){
background(255);//清背景
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( dist(mouseX,mouseY, birdX,birdY)<50){
oldX=birdX; oldY=birdY;
bMoving=true;///按下去時,如果有按到,才能動它
}
}
void mouseDragged(){//按下去,才會開始動
if(bMoving) {//有按到,才能動它
birdX=mouseX; birdY=mouseY;
}
}
-
這個檔案是抓出來的
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup()
{
minim = new Minim(this);
player = minim.loadFile("song.mp3");
player.play();
}
void draw()
{
}
-
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup()
{
minim = new Minim(this);
player = minim.loadFile("song.mp3");
player.play();
}
void draw()
{
}
2020年5月28日 星期四
2020年5月21日 星期四
WEEK13欸欸欸欸不要拉我頭髮啦
PImage imgBird;
void setup(){
size(500,400);
imgBird=loadImage("bird.png");//圖檔如果沒有放好會當掉
imageMode(CENTER);//正中心當作標
}
float birdX=100,birdY=300,oldX,oldY;//之前的鳥在哪
void draw()
{
background(255);//清背景
image(imgBird, mouseX,mouseY,100,100);
if(mousePressed)
{
line(birdX,birdY,oldX,oldY);
}
}
void mousePressed()
{
oldX=birdX;
oldY=birdY;
}
void mouseDragged()
{
birdX=mouseX;
birdY=mouseY;
}
2020年5月7日 星期四
關於泡泡排序法的一些看法
今天老師上課講了泡泡排序法
內容大概是這樣:
-------------------------------------------------------------
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++){
a[i]=int(random(10));
//亂數(random)決定數字
}
/// Java是用 int(3.14)會轉成3, C/C++ int b=3.14變3
textSize(32);
textAlign(LEFT,TOP);
//文字改用左上角
showArray(y);
}
int y=0;
void showArray(int y){
//左上角
for(int i=0;i<10;i++){
//rect(x,y, w,h)四邊形
fill(255); rect(i*50, y, 50,50);
fill(0); text(a[i], i*50, y);
}
///秀文字(字, x, y) 放哪裡 (左下角)
}
void draw(){
}
void mousePressed(){
for(int i=0; i<10-1;i++){
//i從左到右0~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);
}
-----------------------------------------------------------------
到老師講完我還是不懂這和泡泡有甚麼關係。
內容大概是這樣:
-------------------------------------------------------------
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++){
a[i]=int(random(10));
//亂數(random)決定數字
}
/// Java是用 int(3.14)會轉成3, C/C++ int b=3.14變3
textSize(32);
textAlign(LEFT,TOP);
//文字改用左上角
showArray(y);
}
int y=0;
void showArray(int y){
//左上角
for(int i=0;i<10;i++){
//rect(x,y, w,h)四邊形
fill(255); rect(i*50, y, 50,50);
fill(0); text(a[i], i*50, y);
}
///秀文字(字, x, y) 放哪裡 (左下角)
}
void draw(){
}
void mousePressed(){
for(int i=0; i<10-1;i++){
//i從左到右0~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);
}
-----------------------------------------------------------------
到老師講完我還是不懂這和泡泡有甚麼關係。
2020年4月30日 星期四
一半的程式碼但是我要先走了那先這樣好了
void setup()
{
size(300,500);
}
int r=0,x,y;
void draw()
{
background(123);
3X3的球球
/*
for(x=0;x<3;x++)
{
for(y=0;y<3;y++)
{
ellipse(50+x*100,200+50+y*100,r,r);
}
}
*/
縮放
/*
if(r<100)
{
r+=2;
}
else
{
r=0;
}
}
*/
2020年4月23日 星期四
樹梅派吃樹梅
void setup(){
size(600,300);
}
int x=50,y=50,a=45,da=1;//da->the change of angle a,set as 1
int i,j;
int[][]bean={
{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},
};
void draw(){//60 times per second
background(#AEE5AE);
fill(#C17373);
for(i=0;i<6;i++){
for(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;//decrease or enlarge
if(a>60)
{
da=-1;//too big-> decrease
}
if(a<=0)
{
da=+1;//too small-> enlarge
}
}
size(600,300);
}
int x=50,y=50,a=45,da=1;//da->the change of angle a,set as 1
int i,j;
int[][]bean={
{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},
};
void draw(){//60 times per second
background(#AEE5AE);
fill(#C17373);
for(i=0;i<6;i++){
for(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;//decrease or enlarge
if(a>60)
{
da=-1;//too big-> decrease
}
if(a<=0)
{
da=+1;//too small-> enlarge
}
}
2020年4月16日 星期四
神情大變的小精靈
void setup(){
size(300,200);
}
int angle=45;
void draw(){
background(114,67,85);
//circle(100,100,100);
//elispse(100,100,100,100);
angle = (frameCount*2)%120;//frameCount==>6(times/sec)
if(angle>60)
{
fill(HSB);//colourful
color(frameCount%255,255,255);
fill(frameCount%255,255,255);
angle=120-angle;
}
arc(100,100,100,100,radians(angle+360),radians(360-angle+360),PIE);//45'=>360-45
}
size(300,200);
}
int angle=45;
void draw(){
background(114,67,85);
//circle(100,100,100);
//elispse(100,100,100,100);
angle = (frameCount*2)%120;//frameCount==>6(times/sec)
if(angle>60)
{
fill(HSB);//colourful
color(frameCount%255,255,255);
fill(frameCount%255,255,255);
angle=120-angle;
}
arc(100,100,100,100,radians(angle+360),radians(360-angle+360),PIE);//45'=>360-45
}
2020年4月9日 星期四
寵物的分離焦慮症
老黃是一隻狗,他很猶豫
一下子往左走,一下子往右走
一點都不專心
其實老黃很善良又忠心
只是不知道要往哪邊走去
PImage img1,img2,img3;//放入三張老黃
PImage img;
float x=100,y=100,vx=0;
void setup(){
size(1000,1000);
img1=loadImage("img1.png");
img2=loadImage("img2.png");
img3=loadImage("img3.png");
img=img3;
}
void draw (){
background(255);
image(img, x, y);
x += vx;
}
void keyPressed(){
if(keyCode==LEFT){ //按往左就往左
img=img2;
vx=-1;
}
if(keyCode==RIGHT){//按往右就往右
img=img1;
vx=+1;
}
}
你發現了嗎
你就是害老黃不知所措的小壞壞
void keyReleased(){//沒按就朝中間
img=img3;
vx=0;
}
老黃不是不專心
他是身不由己
可愛的老黃
貼心的老黃
"老黃老黃,你真的開心嗎"
"嗷~嗷~嗷~"
2020年3月26日 星期四
想睡的心與肥胖跟球球一起無限膨脹
Bubble [] b=new Bubble[1000];//set-->int []x=new int[1000]
int n=0;
void setup(){
size(400,400);
}
void draw(){
int i;
background(255);
for(i=0;i<n;i++)
{
b[i].drawAndUpdate();
}
if(mousePressed)
{
b[n-1].r++;
}
}
void mousePressed(){
b[n]= new Bubble(mouseX,mouseY,10);
n++;
}
上面是主程式啦
下面結構放到New Tab
class Bubble{//Struct(C)-->in JAVA turn into class
int x,y,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--;
}
}
然後你就可以得到球球
跟我沒救的體重和絕望的心一直膨脹嗷嗷嗷嗷
int n=0;
void setup(){
size(400,400);
}
void draw(){
int i;
background(255);
for(i=0;i<n;i++)
{
b[i].drawAndUpdate();
}
if(mousePressed)
{
b[n-1].r++;
}
}
void mousePressed(){
b[n]= new Bubble(mouseX,mouseY,10);
n++;
}
上面是主程式啦
下面結構放到New Tab
class Bubble{//Struct(C)-->in JAVA turn into class
int x,y,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--;
}
}
然後你就可以得到球球
跟我沒救的體重和絕望的心一直膨脹嗷嗷嗷嗷
2020年3月19日 星期四
移動的情緒化豬豬
他是豬豬
他很情緒化
PImage img0, img1 ,img2;//u can post 3 pics
void setup(){
size(1000,1000);
img0 = loadImage("user0.png");
img1 = loadImage("user1.png");
img2 = loadImage("user2.png");
//記得要把三張圖都拉進程式碼裡唷
int userX=250,userY=250;
void draw(){
background(128);
if(keyPressed && keyCode==LEFT){
image(img0, userX, userY);
userX--;
}
//按下LEFT,變成img0(問號豬豬)執行X--(左移)
else if(keyPressed && keyCode==RIGHT){
userX++;
}
//按下RIGHT,變成img1(害羞豬豬)執行X++(右移)
else image(img2, userX, userY);
//沒動的話就是img2(發抖豬豬)
恭喜你得到會移動的豬豬囉
豬豬容易森氣氣
要好好對待他。
2020年3月12日 星期四
week2會往下掉的球球
\
int x=0, y=0;//設定球球座標
void setup(){//準備行動
size(300, 300);//設定背景大小
}
void draw(){
background(150,210,110);//設定背景顏色
circle(x,y, 100);//畫一顆球球,數字為球球大小,變超級大球球了~
y++;//球球掉落速度
右邊是y+4可以比較一下
if(mousePressed)//如果你點擊滑鼠
{
x = mouseX;//球球位置會在滑鼠點的地方
y = mouseY;
}
}
這樣就得到一顆會一直往下掉的球球囉 ~~~~~~
訂閱:
文章 (Atom)




