WEEK07-0
int i;
void setup() {
size(600, 800);
i=int(random(7, 11));
textSize(50);
textAlign(CENTER, CENTER);
}
int [][]num=new int[8][6];
int [][]press=new int[8][6];
int ClickCount=0;
void draw() {
for (int j=0; j<6; j++)
{
for (int k=0; k<8; k++)
{
fill(255);
rect(j*100, k*100, 100, 100);
if (press[k][j]>=1) {
if (ClickCount==1)num[k][j]=0;
while (i!=0) {
int a=int(random(0, 8));
int b=int(random(0, 6));
if (num[a][b]==0) {
for (int c=a-1; c<=a+1; c++) {
for (int d=b-1; d<=b+1; d++) {
if (a==c&&b==d) {
num[a][b]=9;
i--;
}
}
}
}
}
fill(0);
text(""+num[k][j], 50+j*100, 50+k*100);
}
}
}
}
void mouseClicked() {
if (mouseButton==LEFT)
{
int i=mouseY/100, j=mouseX/100;
press[i][j]+=1;
ClickCount+=1;
}
}
未完成的期中作業
WEEK07-1
void setup() {
size(500, 400);
}
float x=250, y=200;
void draw() {
background(215, 184, 200);
fill(167,167,175);
stroke(110,110,113);
strokeWeight(4);
rect(240,155,20,25);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(x, y, 60, 60);
line(x,y,mouseX,mouseY);
}
void setup() {
size(500, 400);
}
float x=250, y=200;
void draw() {
background(215, 184, 200);
float dx = mouseX-x,dy=mouseY-y;
float angle = atan2(dy,dx);
strokeWeight(15);
line(x,y,x+cos(angle)*40,y+sin(angle)*40);
fill(167,167,175);
stroke(110,110,113);
strokeWeight(4);
rect(240,155,20,25);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(x, y, 60, 60);
}
void setup() {
size(500, 400);
}
float x=250, y=200;
void draw() {
background(215, 184, 200);
float dx = mouseX-x,dy=mouseY-y;
float angle = atan2(dy,dx);
myTank(x,y,angle);
}
void myTank(float x,float y,float angle){
translate(x,y);
rotate(angle);
fill(167,167,175);
stroke(110,110,113);
strokeWeight(4);
rect(20,-10,20,20);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(0, 0, 55, 55);
}
void setup() {
size(500, 400);
}
void keyPressed()
{
if (keyCode=='W')y-=5;
if (keyCode=='A')x-=5;
if (keyCode=='S')y+=5;
if (keyCode=='D')x+=5;
}
float x=250, y=200;
void draw() {
background(219);
stroke(210);
strokeWeight(1);
for (int i=0; i<30; i++) {
line(0, i*30, 500, i*30);
line(i*30, 0, i*30, 500);
}
float dx = mouseX-x, dy=mouseY-y;
float angle = atan2(dy, dx);
line(x,y,mouseX,mouseY);
myTank(x, y, angle);
}
void myTank(float x, float y, float angle) {
translate(x, y);
rotate(angle);
fill(167, 167, 175);
stroke(110, 110, 113);
strokeWeight(4);
rect(20, -10, 20, 20);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(0, 0, 55, 55);
}
void setup() {
size(500, 400);
}
void keyPressed(){
if (keyCode=='W')y-=5;
if (keyCode=='A')x-=5;
if (keyCode=='S')y+=5;
if (keyCode=='D')x+=5;
}
float x=250, y=200;
void draw() {
background(219);
translate(-x,-y);
translate(width/2,height/2);
float mx=mouseX+x-width/2,my=mouseY+y-height/2;
ellipse(mx,my,8,8);
stroke(210);
strokeWeight(1);
for (int i=0; i<30; i++) {
line(0, i*30, 500, i*30);
line(i*30, 0, i*30, 500);
}
float dx = mx-x, dy=my-y;
float angle = atan2(dy, dx);
line(x,y,mx,my);
myTank(x, y, angle);
}
void myTank(float x, float y, float angle) {
translate(x, y);
rotate(angle);
fill(167, 167, 175);
stroke(110, 110, 113);
strokeWeight(4);
rect(20, -10, 20, 20);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(0, 0, 55, 55);
}
void setup() {
size(500, 400);
}
void keyPressed(){
if (keyCode==UP)vy=-1;
if (keyCode==LEFT)vx=-1;
if (keyCode==DOWN)vy=1;
if (keyCode==RIGHT)vx=1;
}
void keyReleased(){
if(keyCode==LEFT||keyCode==RIGHT)vx=0;
if(keyCode==UP||keyCode==DOWN)vy=0;
}
float x=250, y=200,vx=0,vy=0;
void draw() {
x+=vx;
y+=vy;
background(219);
translate(-x,-y);
translate(width/2,height/2);
float mx=mouseX+x-width/2,my=mouseY+y-height/2;
ellipse(mx,my,8,8);
stroke(210);
strokeWeight(1);
for (int i=0; i<30; i++) {
line(0, i*30, 500, i*30);
line(i*30, 0, i*30, 500);
}
float dx = mx-x, dy=my-y;
float angle = atan2(dy, dx);
line(x,y,mx,my);
myTank(x, y, angle);
}
void myTank(float x, float y, float angle) {
translate(x, y);
rotate(angle);
fill(167, 167, 175);
stroke(110, 110, 113);
strokeWeight(4);
rect(20, -10, 20, 20);
fill(204, 102, 156);
stroke(125, 84, 105);
strokeWeight(3);
ellipse(0, 0, 55, 55);
}
......
a=angle;
line(x, y, mx, my);
pushMatrix();
myTank(x, y, angle);
popMatrix();
if (bulletVX!=0&&bulletVY!=0) {
bulletX+=bulletVX;
bulletY+=bulletVY;
ellipse(bulletX, bulletY, 20, 20);
}
}
float a, bulletX=0, bulletY=0, bulletVX=0, bulletVY=0;
void mousePressed() {
bulletX=x;
bulletY=y;
bulletVX=cos(a);
bulletVY=sin(a);
}
......
......
for (int i=0;i<bulletN;i++) {
bulletX[i]+=bulletVX[i];
bulletY[i]+=bulletVY[i];
ellipse(bulletX[i], bulletY[i], 20, 20);
}
}
float a;
int bulletN=0;
float [] bulletX=new float[100];
float [] bulletY=new float[100];
float [] bulletVX=new float[100];
float [] bulletVY=new float[100];
void mousePressed() {
int i=bulletN;
bulletX[i]=x;
bulletY[i]=y;
bulletVX[i]=cos(a);
bulletVY[i]=sin(a);
bulletN++;
}
......
......
if (bulletN==100) {
for (int j=0; j<50; j++) {
bulletX[j]=bulletX[j+50];
bulletY[j]=bulletX[j+50];
bulletVX[j]=bulletX[j+50];
bulletVY[j]=bulletX[j+50];
}
bulletN=50;
}
......
......
bulletT[i]--;
if(bulletT[i]==0){
for(int k=i+1;k<bulletN;k++){
bulletX[k-1]=bulletX[k];
bulletY[k-1]=bulletY[k];
bulletVX[k-1]=bulletVX[k];
bulletVY[k-1]=bulletVY[k];
bulletT[k-1]=bulletT[k];
}
bulletN--;
}
}
}
float a;
int bulletN=0;
float [] bulletX=new float[100];
float [] bulletY=new float[100];
float [] bulletVX=new float[100];
float [] bulletVY=new float[100];
float [] bulletT=new float[100];
void mousePressed() {
int i=bulletN;
bulletX[i]=x;
bulletY[i]=y;
bulletVX[i]=cos(a);
bulletVY[i]=sin(a);
bulletT[i]=600;//10秒
bulletN++;
}
......
沒有留言:
張貼留言