For my recitation, I made a project that is like a football game, that when you click the keyboard, the ball will be moving. When you click the app button, the board will move up and the same as the other button. There is a red barrier on the middle of the window and there is also There is a red barrier in the middle of the window and also I go on the top of the window. When you operate the ball into the goal,” your win!!” will we print on the screen. However, if you touch the red barrier, “You lose” well be printed instead.
I faced a lot of problems when I do this project. At first, I just want to build project where as soon as you press the button the board will keep going for that direction. However, I find it impossible because the function key doesn’t want to give me such an option. So I asked the fat off for help but they still couldn’t help me solve this problem. So I made a little compromise, it is that you press a key a ball will make an action.
Here is a video I shot.
Additional Homework
Here’s my code:
float r=20;
float i=1;
float colorH;
int x=300;
int y=300;
void setup() {
size(600, 600);
}
void draw() {
background(255);
i++;
colorH=180+180*sin(i/100);
colorMode(HSB);
color c=color(colorH,500,500);
stroke(c);
strokeWeight(10);
ellipse(x, y, r, r);
r=200+ 100*sin(i/20);
}
void keyPressed() {
if (keyCode == UP) {
y=y-10;
}
if (keyCode == DOWN) {
y=y+10;
}
if (keyCode==LEFT) {
x=x-10;
}
if (keyCode==RIGHT) {
x=x+10;
}
}
I had some trouble when I was using the sine function. Then I find that even the number of the radius is negative, it will do you translate it into positive.
Also ,I still have some problems with the colorMode. Typing in color c=color(colorH,99,100); , I found the color is very dark. When I typed in color c=color(colorH,500,500); , Things went right. I still don’t know why??
Here is my video:
0FFFEDE4-B905-42D1-9BA3-6E56D70695EF
Code list:
-
- 1.color c=color(colorH,500,500); fill(c);
- stroke(c);
strokeWeight(10); - //up and down code: r=200+ 100*sin(i/20);
- key moving code
void keyPressed() {
if (keyCode == UP) {y=y-10;
}
if (keyCode == DOWN) {
y=y+10;
}
if (keyCode==LEFT) {
x=x-10;
}
if (keyCode==RIGHT) {
x=x+10;
}
}