Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, im very new to coding. my college beginner's course uses Java script in Processing 3. for my project, i need to make my avatar scale to a different size every time he goes across the screen. the scaling using a while loop is what im having a problem with. we have to put the avatar in a function call. ill post what code i have below. i need help ASAP! thanks!

Java
int Mart_start_x = -100; //x axis start location
int Mart_start_y = 570; //y axis start location
int Mart_speed = 4; //speed which Mart moves
int r_Leg_x = 50; //'foot' location of right leg
int r_Leg_speed = 1; //speed of which right leg moves
int l_Leg_x = -50; //'foot' location of left leg
int l_Leg_speed = -1; //speed of which left leg moves
int Mart_count = 0; //How many Marts there are
float scale_size = .5; //scaling Mart

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


void draw()  
{
   background (255);
   fill(150);

   MartFunction(Mart_start_x, 570, 1);
    
   //while
   {
      scale_size = scale_size + .5;
   } 
    
   scale_size = 0;
    
   Mart_start_x= Mart_start_x + Mart_speed;

   if(Mart_start_x > width+100)
   {
      Mart_start_x = -100; //This moves Mart across screen
   }

   r_Leg_x = r_Leg_x + r_Leg_speed; //this wiggles right leg START

   if((r_Leg_x > 65) || (r_Leg_x < 35))
   {
      r_Leg_speed = r_Leg_speed * -1; //this wiggles right leg END
   }

   l_Leg_x = l_Leg_x + l_Leg_speed; //this wiggles left leg START

   if((l_Leg_x > -35) || (l_Leg_x < -65))
   {
      l_Leg_speed = l_Leg_speed * -1; //this wiggles left leg END
   }
}

/*************************************************************************/                                          
/*   Function name:  MartFunction                                        */
/*   Description:  Draw Mart when the function is called                 */
/*   Parameters:  int x_loc, int y_loc, float scale_size                 */
/*   Return Value:                                                       */
/*************************************************************************/

void MartFunction(int x_loc, int y_loc, float scale_size)
{
   pushMatrix();

   translate(x_loc,y_loc); //Mart's location

   scale(scale_size);
  
   stroke(5);
   line(0,-50,r_Leg_x,125); //right leg

   stroke(5);
   line(0,-50,l_Leg_x,125); //left leg

   noStroke();
   fill(#084B0F);
   ellipse(0,0,75,175); //body

   noStroke();
   fill(#2C8E11);
   ellipse(0,-100,200,100); //head

   noStroke();
   fill(#EBFF17);
   ellipse(-50,-100,25,50); //left eye

   noStroke();
   fill(#EBFF17);
   ellipse(0,-100,25,65); //middle eye

   noStroke();
   fill(#EBFF17);
   ellipse(50,-100,25,50); //right eye

   popMatrix();
}


What I have tried:

my professor hasn't emailed back since my first email sent over a week ago asking for help. no one else knows what to do
Posted
Updated 23-Mar-20 6:51am
v5
Comments
phil.o 23-Mar-20 12:08pm    
What is wrong with this code? Please don't say 'it doesn't work', but rather explain precisely in which way it is incorrect.
We are more than happy to help, but we need you to state precisely where you are stuck.
DragonNinjaBD 23-Mar-20 12:18pm    
as of right now, it does work. i just dont know how to get the while loop to scale my avatar every time he goes across the screen
DragonNinjaBD 23-Mar-20 12:21pm    
i also commented out 'while' so i could test the rest of the code to make sure it works
CPallini 23-Mar-20 12:11pm    
It doesn't look Javascript.
DragonNinjaBD 23-Mar-20 12:19pm    
thats what my prof told us unless i'm just remembering it wrong

1 solution

First, you should not give the same name to a member field and to the parameter of a method (I'm talking about scale_size). You can even get rid of the parameter entirely and use the member field instead.

Second, you are resetting the scale_size value to zero everytime the draw() method is called. Try to comment out this line, and see where it gets you.

As a side question, do you have any debugger with the IDE you are using?
 
Share this answer
 
Comments
DragonNinjaBD 23-Mar-20 13:16pm    
what is 'member field'? sorry im very nooby at coding
phil.o 23-Mar-20 13:21pm    
A member field is a variable declared inside a class. Here, I am refering to the scale_size variable which you define in the line float scale_size = .5; //scaling Mart.
DragonNinjaBD 23-Mar-20 13:37pm    
i got rid of float 'scale_size = .5; //scaling Mart.' but i still need the loop to give him a scale every time he goes thru, and maybe i need to reset it at some point, i dont know

also for your original side question, i have no clue what IDE means.
phil.o 23-Mar-20 14:25pm    
I thought of the contrary: keep the member variable, and remove the parameter from the function.
An IDE is an Integrated Development Environment, like Eclipse for java for example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900