• Bhangra discussion is still going strong. Join us in our Facebook group!

    New user registration has been closed (as it was entirely spam). We encourage you to post in our Facebook group, even if it's a followup to an existing thread. BTF will continue to be archived and hosted here - Saleem

Programming help

Sonuu

Member
Messages
189
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..!
 

yraparla

SwizzeeMusic.com
Messages
2,072
What do you need help on specifically? Yes, it's pretty basic stuff but you only told us the assignment and didn't indicate what you were stuck on!


Do you need help conceptualizing how to build the methods, do you know what to do but don't know the specific functions, are the functions not working properly, do you need help with syntax?


Legit once you understand what to do this assignment will take 30 minutes
 

Sonuu

Member
Messages
189
well if u notice the assignment it starts at letter (d). (a) through (c) basically had me make that code from scratch and now is where I'm essentially stuck. I don't really know how to make the code.

I thought maybe this was what would follow for part d.

//Draw Right Leg
line(rightfootx,centerY+5,centerX,centerY-7.5);

}

void moveLeft(int x)
{
centerX = x - 10;
}


}


but i dont know if thats right because I can't actually check it. then after that, I don't know how to use the isClicked method and how to constrain in between the height and the width that it asks for (height being 35 and width being 30)..
 

kinnell

*Account Deactivated*
Messages
2,159
It's quite simple - you just need someone to guide you through the steps and give you the reasoning behind the code. Send me the full assignment. (everything) I suspect you may have erred in the initial steps which may be adding to your confusion/frustration in these later steps. kinnell[at]gmail.com :)
 
Top