void setup(){
size(300,300);
}
float x=200,y=150;
void draw(){
background(#002966);
stroke(#b7efff);
line(100,150,x,y);
fill(#be7fff);
noStroke();
ellipse(100,150,13,13);
ellipse(x,y,13,13);
if( !mousePressed){ 不管怎摸拉放掉後都會回到100的位子
float dx=x-100, dy=y-150;
float len=sqrt(dx*dx+dy*dy);
x -=dx*(len-100)/len;
y -=dy*(len-100)/len;
}
}
void mouseDragged(){
x=mouseX; y=mouseY;
}
2020年6月18日 星期四
2020年5月21日 星期四
2020年5月7日 星期四
week -11 泡泡
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++){
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);
}
}
y+=50;
showArray(y);
}
學到了泡泡排序法的規則,但是我覺得泡泡很沒有效率
//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++){
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);
}
}
y+=50;
showArray(y);
}
學到了泡泡排序法的規則,但是我覺得泡泡很沒有效率
2020年4月30日 星期四
week10 08160953 王霆皓
知道了怎摸剝皮,有學很多很開心
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int n1=n;
int ans=0;
while(n>0)
{
ans*=10;
int now=n%10;
n/=10;
ans+=now;
}
int n2=ans;
printf("%d+%d=%d\n",n1,n2,n1+n2);
}
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int n1=n;
int ans=0;
while(n>0)
{
ans*=10;
int now=n%10;
n/=10;
ans+=now;
}
int n2=ans;
printf("%d+%d=%d\n",n1,n2,n1+n2);
}
2020年4月23日 星期四
2020年4月9日 星期四
week07 可以動的上下左右
PImage img1;
PImage img2;
PImage img3;
PImage img;
float x=100,y=100,vx=0;
void setup(){
size(800,800);
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;
}else if(keyCode==RIGHT){
img=img1; vx=+1;
}
}
void keyReleased(){
img=img3; vx=0;
}
2020年3月26日 星期四
2020年3月19日 星期四
2020年3月12日 星期四
訂閱:
文章 (Atom)











