# Please advise me on my cannon simulation code!

**URL:** <https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 22, 2019, 1:54pm UTC](https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717 "2019-11-22T13:54:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![O-O](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/o-o/32/6947_2.png) [@O-O](https://discourse.processing.org/u/O-O)\
**Post date:** [November 22, 2019, 1:54pm UTC](https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717/1 "2019-11-22T13:54:54Z")

</div>

```auto
int angle=0,a=1;

void setup(){
size(1500,750);

fill(26,185,53);
rectMode(CORNER);
rect(0,600,1500,150);
fill(75,78,75);
rect(0,610,1500,20);
fill(233,243,255);
rect(0,0,1500,600);
stroke(247,251,0);
line(0,620,100,620);
line(120,620,220,620);
line(240,620,340,620);
line(360,620,460,620);
line(480,620,580,620);
line(600,620,700,620);
line(720,620,820,620);
line(840,620,940,620);  
line(960,620,1060,620);
line(1080,620,1180,620);
line(1200,620,1300,620);
line(1320,620,1420,620);
line(1440,620,1540,620);
line(1560,620,1660,620);
line(1680,620,1780,620);
noStroke();
ellipseMode(CENTER);
fill(0,0,0);
ellipse(250,620,30,30);

}

void draw(){
while(a==1){keyPressed();}
}
 
void keyPressed(){
if (keyCode == UP)angle++;
else if(keyCode == DOWN)angle--;
else if(key == 'w'){fire();}
}
void fire(){
  
}

```

* * *

I’ve worked it out here, but…

According to my code, is the value of the angle variable increased/decreased when the arrow key was pressed?

Also, how do cannons vary the angle of launch depending on the value of the angle variable?

---

<div class="post-metadata">

**Author:** ![O-O](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/o-o/32/6947_2.png) [@O-O](https://discourse.processing.org/u/O-O)\
**Post date:** [November 22, 2019, 1:58pm UTC](https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717/2 "2019-11-22T13:58:24Z")

</div>

the first velocity of a cannonball : Entered by the user

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 22, 2019, 2:03pm UTC](https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717/3 "2019-11-22T14:03:36Z")

</div>

please delete this in draw():

while (a==1) {  
keyPressed();  
}

a while loop would block your entire draw()

keyPressed() gets called automatically.

Do all the drawing in draw, not in setup

Start draw() with background(0);

post the entire code again, formatted as code.

Chrisir

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 22, 2019, 2:18pm UTC](https://discourse.processing.org/t/please-advise-me-on-my-cannon-simulation-code/15717/4 "2019-11-22T14:18:51Z")

</div>

Read the first three textual tutorials

Read the examples about animation and motion

You can’t ask for every little step here please

Do some research and learning on your own please
