Alright guys,
I've got a programming assignment due in about 2 hours and some stuff I really can't figure out...
It's an Intro programming course so the material is fairly basic.
Ill just post my code up on here and see if anyone can figure out what to do...
Stickfigure fig = new Stickfigure(100,100);
void setup()
{
size(80,80);
smooth();
}
void draw()
{
background(255);
fig.draw();
}
class Stickfigure
{
//Stickfigure variables
int centerX, centerY;
int w;
int h;
int lefthandy;
int righthandy;
int leftfootx;
int rightfootx;
//Constructor
Stickfigure (int x, int y)
{
x = 40;
y = 40;
centerX = x;
centerY = y;
//Values
w = 30;
h = 35;
lefthandy = centerY-18;
righthandy = centerY-18;
leftfootx = centerX-15;
rightfootx = centerX+15;
}
void draw()
{
//Draw Head
stroke(0);
ellipse(centerX,centerY-25,h-30,h-30);
//Draw Body
line(centerX,centerY-21,centerX,centerY-7.5);
//Draw Arms
line(leftfootx, lefthandy, rightfootx, righthandy);
//Draw Left Leg
line(leftfootx,centerY+5,centerX,centerY-7.5);
//Draw Right Leg
line(rightfootx,centerY+5,centerX,centerY-7.5);
}
}
Basically its just a program of a stick figure. what I have to do now is put in code that does the following:
d. Create a moveLeft() method that takes a single integer argument. This method
should update the StickFigureʼs center x coordinate, as well as the x
coordinates of its feet, by the value of the argument.
e. Create a method named isClicked(). This method takes two integer
arguments (an x and y value), and returns a boolean value. If the x and y values
fall inside the boundaries of the StickFigure (total height and total width),
return true; otherwise, return false.
f. Create a method named changeColor(). This method does not take any
arguments, and it returns void. When this method is called, it should choose a
new random integer between 0 and 256 for each of the StickFigureʼs red,
green, and blue color components.
2. In the rest of your sketch, declare at least four StickFigure variables. In setup(),
create a new StickFigure instance for each variable (give it the starting position of
your choice).
3. Add a draw() method that clears the background and displays each StickFigure
(by calling its draw() method).
4. Finally, add a mouseClicked() method that passes that values of mouseX and
mouseY to each StickFigureʼs isClicked() method. If isClicked() returns true,
call moveLeft() on that StickFigure and then call its changeColor() method.
If anyone can help me I'd greatly appreciate it if you let me know. If you could PM me that'd be perfect.
Thanks for any help you guys can offer..!
I've got a programming assignment due in about 2 hours and some stuff I really can't figure out...
It's an Intro programming course so the material is fairly basic.
Ill just post my code up on here and see if anyone can figure out what to do...
Stickfigure fig = new Stickfigure(100,100);
void setup()
{
size(80,80);
smooth();
}
void draw()
{
background(255);
fig.draw();
}
class Stickfigure
{
//Stickfigure variables
int centerX, centerY;
int w;
int h;
int lefthandy;
int righthandy;
int leftfootx;
int rightfootx;
//Constructor
Stickfigure (int x, int y)
{
x = 40;
y = 40;
centerX = x;
centerY = y;
//Values
w = 30;
h = 35;
lefthandy = centerY-18;
righthandy = centerY-18;
leftfootx = centerX-15;
rightfootx = centerX+15;
}
void draw()
{
//Draw Head
stroke(0);
ellipse(centerX,centerY-25,h-30,h-30);
//Draw Body
line(centerX,centerY-21,centerX,centerY-7.5);
//Draw Arms
line(leftfootx, lefthandy, rightfootx, righthandy);
//Draw Left Leg
line(leftfootx,centerY+5,centerX,centerY-7.5);
//Draw Right Leg
line(rightfootx,centerY+5,centerX,centerY-7.5);
}
}
Basically its just a program of a stick figure. what I have to do now is put in code that does the following:
d. Create a moveLeft() method that takes a single integer argument. This method
should update the StickFigureʼs center x coordinate, as well as the x
coordinates of its feet, by the value of the argument.
e. Create a method named isClicked(). This method takes two integer
arguments (an x and y value), and returns a boolean value. If the x and y values
fall inside the boundaries of the StickFigure (total height and total width),
return true; otherwise, return false.
f. Create a method named changeColor(). This method does not take any
arguments, and it returns void. When this method is called, it should choose a
new random integer between 0 and 256 for each of the StickFigureʼs red,
green, and blue color components.
2. In the rest of your sketch, declare at least four StickFigure variables. In setup(),
create a new StickFigure instance for each variable (give it the starting position of
your choice).
3. Add a draw() method that clears the background and displays each StickFigure
(by calling its draw() method).
4. Finally, add a mouseClicked() method that passes that values of mouseX and
mouseY to each StickFigureʼs isClicked() method. If isClicked() returns true,
call moveLeft() on that StickFigure and then call its changeColor() method.
If anyone can help me I'd greatly appreciate it if you let me know. If you could PM me that'd be perfect.
Thanks for any help you guys can offer..!