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);
}
processing
New contributor
add a comment |
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);
}
processing
New contributor
add a comment |
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);
}
processing
New contributor
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
processing
New contributor
New contributor
edited Nov 5 at 3:59
Kevin Workman
32.6k53967
32.6k53967
New contributor
asked Nov 5 at 3:52
ari
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
ari is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password