• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Can I make a look go in reverse

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 while loops which sets a shape 'called body' to a certain colour then changes to the other colour and now I want it to go back to the original colour following the same principle to make it look like its spinning.







This code works to go from BLUE to GREEN now I want to go back to BLUE following the same +- 20 to make it look like its shrinking?

change the colour of the shape to green if it is blue, or blue if it is green once it reaches its minimum width
and

complete the second while loop condition to restore the shape to its width at the start of the method

 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want the setColour() calls to be made inside the loops?  Do you want line 19 (the second while loop) to be < 100?  Why did you save the bodyWidth then?
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Uncomment the provided method spinBody() which narrows the body in a loop till it has width 0, centring it on each iteration, before expanding it again to its original size.

Add code to this method to:

• change the colour of the body to green if it is blue, or blue if it is green once it reaches its minimum width

• complete the second while loop condition to restore the stick figure’s body to its width at the start of the method

No I don't necessarily need them inside the loops this what I was originally given




The value of 100 will be the maximum width of my shape
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leigh Edwards wrote:The value of 100 will be the maximum width of my shape


But do you know that the width of your shape will be exactly 100?  Again, why do you save bodyWidth?
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't said what your difficulty is. Is it  not working? If not, what is it doing instead of what yu want?

Note that you should never delay or sleep inside a method that is executed on the EventDispatchTread.
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first part is working when it goes from blue to green but I need it to go from green to blue when the method is called for a second time
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Leigh Edwards wrote:The value of 100 will be the maximum width of my shape


But do you know that the width of your shape will be exactly 100?  Again, why do you save bodyWidth?



The width can be anything I've tried it at 50 and 100 and the code I supplied is what I have been given and need to add to the method accordingly.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leigh Edwards wrote:The first part is working when it goes from blue to green but I need it to go from green to blue when the method is called for a second time


You'll need some kind of if-else statement in between the two while loops.  Is there a method to get the color of the shape?
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leigh Edwards wrote:The width can be anything


Exactly.  What to you use in programming when a value can be anything?

I've tried it at 50 and 100


You don't want a constant.

and the code I supplied is what I have been given and need to add to the method accordingly.


From what I understand you were given code with a line like this for the second while loop:
So you can put whatever you need to in the condition of the while loop.
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The width of the shape is declared in another class, I use the 100 'or 50' to determine when the shape is at the maximum limit so it stops 'spinning'


Yes this is exactly what I was supplied to modify accordingly


and the code I supplied is what I have been given and need to add to the method accordingly.


From what I understand you were given code with a line like this for the second while loop:
So you can put whatever you need to in the condition of the while loop.

I get the colour by using or   like mentioned in op
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:
You'll need some kind of if-else statement in between the two while loops.  Is there a method to get the color of the shape?



How would I start this I have hit a brick wall now?
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leigh Edwards wrote:I get the colour by using or   like mentioned in op


No, that's how you set the colour.  How do you get the colour?
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Leigh Edwards wrote:I get the colour by using or   like mentioned in op


No, that's how you set the colour.  How do you get the colour?




from the main constructor  maybe?


And this is in the triangle class in the project

 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I cannot change the Triangle class

 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Ive tried the code above but when it is executed for a second tine it spins but stays GREEN

I put in at the end of the if block
and it says the colour is still blue when its obviously not on my graphical display. 😐
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Triangle class has a getColour() method.  You can use this to determine what the current color of the shape is and then switch it to the other.  So it would look something like this:
 
Rancher
Posts: 185
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that from a TMA? If yes then OU might treat it as cheating so be careful what you post online...
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the heads-up.
 
Leigh Edwards
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adrian Grabowski wrote:Is that from a TMA? If yes then OU might treat it as cheating so be careful what you post online...



I was only asking for pointers and advice not actually what to write
 
Saloon Keeper
Posts: 8760
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leigh Edwards wrote:


Lines 13-29 in pseudo code:
LOOP { GREEN - DELAY - BLUE - DELAY - GREEN - DELAY - BLUE }
This will rapidly flash the two colors.
Is this the way you want this loop to behave?
 
Carey Brown
Saloon Keeper
Posts: 8760
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make this more obvious by making all delays one second or longer.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic