i need help on my assignment with moving an object using parameters in processing











up vote
-2
down vote

favorite












I'm new to coding and I am trying to write a program that shows a car moving. I can't figure out how to move the car back and forth using parameters. Any help would be appreciated.



void setup()
{
size(500,500);
rectMode(CORNER);
ellipseMode(CORNER);

}

void draw()
{
background(50,200,255);
drawCar(80,340);
drawWheel(45,410);
}

void drawCar(int x, int y)
{
noStroke();
fill(255,0,0);
beginShape();
vertex(x,y);
vertex(x+50,y);
vertex(x+80,y+50);
vertex(x+110,y+50);
vertex(x+110,y+80);
vertex(x-60,y+80);
vertex(x-60,y+50);
vertex(x-30,y+50);
endShape(CLOSE);
}

void drawWheel(int wx,int wy)
{
fill(0);
noStroke();
ellipse(wx,wy,40,40);
ellipse(wx+85,wy,40,40);
}









share|improve this question









New contributor




ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    -2
    down vote

    favorite












    I'm new to coding and I am trying to write a program that shows a car moving. I can't figure out how to move the car back and forth using parameters. Any help would be appreciated.



    void setup()
    {
    size(500,500);
    rectMode(CORNER);
    ellipseMode(CORNER);

    }

    void draw()
    {
    background(50,200,255);
    drawCar(80,340);
    drawWheel(45,410);
    }

    void drawCar(int x, int y)
    {
    noStroke();
    fill(255,0,0);
    beginShape();
    vertex(x,y);
    vertex(x+50,y);
    vertex(x+80,y+50);
    vertex(x+110,y+50);
    vertex(x+110,y+80);
    vertex(x-60,y+80);
    vertex(x-60,y+50);
    vertex(x-30,y+50);
    endShape(CLOSE);
    }

    void drawWheel(int wx,int wy)
    {
    fill(0);
    noStroke();
    ellipse(wx,wy,40,40);
    ellipse(wx+85,wy,40,40);
    }









    share|improve this question









    New contributor




    ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I'm new to coding and I am trying to write a program that shows a car moving. I can't figure out how to move the car back and forth using parameters. Any help would be appreciated.



      void setup()
      {
      size(500,500);
      rectMode(CORNER);
      ellipseMode(CORNER);

      }

      void draw()
      {
      background(50,200,255);
      drawCar(80,340);
      drawWheel(45,410);
      }

      void drawCar(int x, int y)
      {
      noStroke();
      fill(255,0,0);
      beginShape();
      vertex(x,y);
      vertex(x+50,y);
      vertex(x+80,y+50);
      vertex(x+110,y+50);
      vertex(x+110,y+80);
      vertex(x-60,y+80);
      vertex(x-60,y+50);
      vertex(x-30,y+50);
      endShape(CLOSE);
      }

      void drawWheel(int wx,int wy)
      {
      fill(0);
      noStroke();
      ellipse(wx,wy,40,40);
      ellipse(wx+85,wy,40,40);
      }









      share|improve this question









      New contributor




      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm new to coding and I am trying to write a program that shows a car moving. I can't figure out how to move the car back and forth using parameters. Any help would be appreciated.



      void setup()
      {
      size(500,500);
      rectMode(CORNER);
      ellipseMode(CORNER);

      }

      void draw()
      {
      background(50,200,255);
      drawCar(80,340);
      drawWheel(45,410);
      }

      void drawCar(int x, int y)
      {
      noStroke();
      fill(255,0,0);
      beginShape();
      vertex(x,y);
      vertex(x+50,y);
      vertex(x+80,y+50);
      vertex(x+110,y+50);
      vertex(x+110,y+80);
      vertex(x-60,y+80);
      vertex(x-60,y+50);
      vertex(x-30,y+50);
      endShape(CLOSE);
      }

      void drawWheel(int wx,int wy)
      {
      fill(0);
      noStroke();
      ellipse(wx,wy,40,40);
      ellipse(wx+85,wy,40,40);
      }






      processing






      share|improve this question









      New contributor




      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 5 at 3:59









      Kevin Workman

      32.6k53967




      32.6k53967






      New contributor




      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 5 at 3:52









      ari

      1




      1




      New contributor




      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      ari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          It's hard to help with broad "how do I do this" type questions, but I'll try to help in a general sense.



          You have the code that draws your car here:



          drawCar(80, 340);
          drawWheel(45, 410);


          Those numbers control where the car shows up. Right now you're always passing in the same values, so the car always shows up in the same place.



          What happens if you pass in different values? Try something like this:



          drawCar(mouseX, mouseY);
          drawWheel(mouseY, mouseX);


          This should show your car wherever your mouse is.



          Now, if you want to show the care moving around on its own, you probably want to store your state in a set of variables, and then change those variables over time.



          Shameless self-promotion: here is a tutorial on animation in Processing.






          share|improve this answer





















          • Would you mind explaining how I would store the state in a set of variables and change it over time?
            – ari
            Nov 5 at 4:07










          • @ari Did you check out the link at the bottom of my answer?
            – Kevin Workman
            Nov 5 at 4:10










          • Yes I did, sorry but I don't understand how I would apply to my code.
            – ari
            Nov 5 at 4:19










          • @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
            – Kevin Workman
            Nov 5 at 5:03











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          ari is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53148086%2fi-need-help-on-my-assignment-with-moving-an-object-using-parameters-in-processin%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          It's hard to help with broad "how do I do this" type questions, but I'll try to help in a general sense.



          You have the code that draws your car here:



          drawCar(80, 340);
          drawWheel(45, 410);


          Those numbers control where the car shows up. Right now you're always passing in the same values, so the car always shows up in the same place.



          What happens if you pass in different values? Try something like this:



          drawCar(mouseX, mouseY);
          drawWheel(mouseY, mouseX);


          This should show your car wherever your mouse is.



          Now, if you want to show the care moving around on its own, you probably want to store your state in a set of variables, and then change those variables over time.



          Shameless self-promotion: here is a tutorial on animation in Processing.






          share|improve this answer





















          • Would you mind explaining how I would store the state in a set of variables and change it over time?
            – ari
            Nov 5 at 4:07










          • @ari Did you check out the link at the bottom of my answer?
            – Kevin Workman
            Nov 5 at 4:10










          • Yes I did, sorry but I don't understand how I would apply to my code.
            – ari
            Nov 5 at 4:19










          • @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
            – Kevin Workman
            Nov 5 at 5:03















          up vote
          0
          down vote













          It's hard to help with broad "how do I do this" type questions, but I'll try to help in a general sense.



          You have the code that draws your car here:



          drawCar(80, 340);
          drawWheel(45, 410);


          Those numbers control where the car shows up. Right now you're always passing in the same values, so the car always shows up in the same place.



          What happens if you pass in different values? Try something like this:



          drawCar(mouseX, mouseY);
          drawWheel(mouseY, mouseX);


          This should show your car wherever your mouse is.



          Now, if you want to show the care moving around on its own, you probably want to store your state in a set of variables, and then change those variables over time.



          Shameless self-promotion: here is a tutorial on animation in Processing.






          share|improve this answer





















          • Would you mind explaining how I would store the state in a set of variables and change it over time?
            – ari
            Nov 5 at 4:07










          • @ari Did you check out the link at the bottom of my answer?
            – Kevin Workman
            Nov 5 at 4:10










          • Yes I did, sorry but I don't understand how I would apply to my code.
            – ari
            Nov 5 at 4:19










          • @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
            – Kevin Workman
            Nov 5 at 5:03













          up vote
          0
          down vote










          up vote
          0
          down vote









          It's hard to help with broad "how do I do this" type questions, but I'll try to help in a general sense.



          You have the code that draws your car here:



          drawCar(80, 340);
          drawWheel(45, 410);


          Those numbers control where the car shows up. Right now you're always passing in the same values, so the car always shows up in the same place.



          What happens if you pass in different values? Try something like this:



          drawCar(mouseX, mouseY);
          drawWheel(mouseY, mouseX);


          This should show your car wherever your mouse is.



          Now, if you want to show the care moving around on its own, you probably want to store your state in a set of variables, and then change those variables over time.



          Shameless self-promotion: here is a tutorial on animation in Processing.






          share|improve this answer












          It's hard to help with broad "how do I do this" type questions, but I'll try to help in a general sense.



          You have the code that draws your car here:



          drawCar(80, 340);
          drawWheel(45, 410);


          Those numbers control where the car shows up. Right now you're always passing in the same values, so the car always shows up in the same place.



          What happens if you pass in different values? Try something like this:



          drawCar(mouseX, mouseY);
          drawWheel(mouseY, mouseX);


          This should show your car wherever your mouse is.



          Now, if you want to show the care moving around on its own, you probably want to store your state in a set of variables, and then change those variables over time.



          Shameless self-promotion: here is a tutorial on animation in Processing.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 5 at 3:59









          Kevin Workman

          32.6k53967




          32.6k53967












          • Would you mind explaining how I would store the state in a set of variables and change it over time?
            – ari
            Nov 5 at 4:07










          • @ari Did you check out the link at the bottom of my answer?
            – Kevin Workman
            Nov 5 at 4:10










          • Yes I did, sorry but I don't understand how I would apply to my code.
            – ari
            Nov 5 at 4:19










          • @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
            – Kevin Workman
            Nov 5 at 5:03


















          • Would you mind explaining how I would store the state in a set of variables and change it over time?
            – ari
            Nov 5 at 4:07










          • @ari Did you check out the link at the bottom of my answer?
            – Kevin Workman
            Nov 5 at 4:10










          • Yes I did, sorry but I don't understand how I would apply to my code.
            – ari
            Nov 5 at 4:19










          • @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
            – Kevin Workman
            Nov 5 at 5:03
















          Would you mind explaining how I would store the state in a set of variables and change it over time?
          – ari
          Nov 5 at 4:07




          Would you mind explaining how I would store the state in a set of variables and change it over time?
          – ari
          Nov 5 at 4:07












          @ari Did you check out the link at the bottom of my answer?
          – Kevin Workman
          Nov 5 at 4:10




          @ari Did you check out the link at the bottom of my answer?
          – Kevin Workman
          Nov 5 at 4:10












          Yes I did, sorry but I don't understand how I would apply to my code.
          – ari
          Nov 5 at 4:19




          Yes I did, sorry but I don't understand how I would apply to my code.
          – ari
          Nov 5 at 4:19












          @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
          – Kevin Workman
          Nov 5 at 5:03




          @ari Start with something simple. The link contains a bouncing ball example. Try to get that working with your car, then go from there.
          – Kevin Workman
          Nov 5 at 5:03










          ari is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          ari is a new contributor. Be nice, and check out our Code of Conduct.













          ari is a new contributor. Be nice, and check out our Code of Conduct.












          ari is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53148086%2fi-need-help-on-my-assignment-with-moving-an-object-using-parameters-in-processin%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()