PDA

View Full Version : Help?


Sh0cker_
02-19-2008, 03:26 PM
I hope this is in the correct part of the forum.

I'm trying to teach myself Alice Programming and I came across a book entitled "An introduction to programming using Alice" I of course picked it up and made my way thru till the end here. I've been doing the exercises at the end of each chapter and I find myself to be stuck on this last one.

1. The Bugs folder inside the Animals folder in the Alice Local Gallery contains a Butterfly class of objects. You will use that class to complete this program.
* Create a new Alice world with six butterflies in a list that will make all of the butterflies fly around gently, flapping their wings and moving about gently.
-Position six butterflies (from the Bugs folder inside the Animals folder) into your world.
-This Butterfly class does NOT contain a flap method.

-Create a generic world flap method that uses a parameter (such as who) to specify the butterfly.
- The flap method should only make any one butterfly flap once. It should not contain a loop.
-Do not use any random functions in this method.
-Create a generic world move method that uses a parameter (such as who) to specify the butterfly.
-The move method should make any one butterfly change direction. No loops here either.
-Use a random function to determine the turn or move direction. (Left, Right, Up, Down, Forward, Backward)
-Use a random function to determine the turn or move distance. (Use small values.)
-The When the world starts event should call the Main method.
-This should be the only event used in this program

-The Main method should contain a loop that calls the generic flap and generic move methods.
-Use a For All together control statement that uses a Butterfly list to obtain the butterfly to pass by parameter to the flap and move methods.
-The loop should allow the butterflies to fly smoothly and remain on the screen for at least 20 seconds without user intervention.
-Do not use any random functions in this method.

*Lost*

- Sh0cker_

Any help starting me out in the right direction would be appreciated.

DickBaldwin
02-19-2008, 05:19 PM
I hope ...
Any help starting me out in the right direction would be appreciated.

Don't know if this will help or not, but I have published a world at http://www.dickbaldwin.com/alice/Alice0930.htm#Two-dimensional_projectile_trajectory that has several butterflies flying around and flapping their wings. They are just incidental to the main thrust of the program that has to do with the trajectory of a fish that jumps out of the water and catches one of the butterflies.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Sh0cker_
02-19-2008, 05:21 PM
I looked at that earlier.

I'm just looking for the basics of what I'm suppose to start with that will allow one butterfly to flaps its wings. I know I'm suppose to make a method in order to do so, but I'm not having any luck. Been at this for what seems like forever.

Avant-Gardening
02-19-2008, 06:09 PM
We had this for a class assignment recently. Pretty tough for me, actually.

I'm not sure what you are asking. Are you having trouble with the actual movement of the wings? I believe I did just a roll (for each specific wing) that went left and right about .15 revolutions. All together I had four "do togethers".

The problem I had was with the random movement. Still haven't figured that one out.

DickBaldwin
02-20-2008, 08:43 AM
I looked at that earlier.

I'm just looking for the basics of what I'm suppose to start with that will allow one butterfly to flaps its wings. I know I'm suppose to make a method in order to do so, but I'm not having any luck. Been at this for what seems like forever.

You can often learn as much by dis-assembling an existing program as by starting from scratch and writing a new program, especially when you don't know how to get started on the new program.

Start with my program. Carefully eliminate everything that you don't need. You will end up with a method that causes a butterfly to flit around and flap its wings. Then tune that method to make it match the program specifications exactly.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Sh0cker_
02-20-2008, 07:11 PM
I'm not sure what you are asking. Are you having trouble with the actual movement of the wings?

Yes, thats exactly my problem.

I'm sure I can figure out the rest, if only I could get the wings to flap up and down.

DickBaldwin
02-20-2008, 07:45 PM
Yes, thats exactly my problem.

I'm sure I can figure out the rest, if only I could get the wings to flap up and down.

Here is the code from my program that causes a bug to flap its wings:

doInOrder { doTogether { mainBug.leftWing .roll( LEFT , 0.25 revolutions ); ( Random.nextDouble() minimum = 0.5 maximum = 0.6 ) style = BEGIN_AND_END_ABRUPTLY mainBug.rightWing .roll( RIGHT , 0.25 revolutions ); ( Random.nextDouble() minimum = 0.5 maximum = 0.6 ) style = BEGIN_AND_END_ABRUPTLY } doTogether { mainBug.leftWing .roll( RIGHT , 0.25 revolutions ); ( Random.nextDouble() minimum = 0.5 maximum = 0.6 ) style = BEGIN_AND_END_ABRUPTLY mainBug.rightWing .roll( LEFT , 0.25 revolutions ); ( Random.nextDouble() minimum = 0.5 maximum = 0.6 ) style = BEGIN_AND_END_ABRUPTLY } }
Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Sh0cker_
02-20-2008, 07:57 PM
-Create a generic world flap method that uses a parameter (such as who) to specify the butterfly.
- The flap method should only make any one butterfly flap once. It should not contain a loop.
-Do not use any random functions in this method.

This is what I dont understand. I'm lost when it comes to making the method - I guess.

-Create a generic world flap method that uses a parameter (such as who) to specify the butterfly.

How do I make a parameter "such as who"?

Sorry, I appreciate the help.

Is there a place where I can copy that code sample into alice, so that I may see it?

DickBaldwin
02-21-2008, 05:50 AM
This is what I dont understand. I'm lost when it comes to making the method - I guess.

How do I make a parameter "such as who"?

Sorry, I appreciate the help.

Is there a place where I can copy that code sample into alice, so that I may see it?

You will find the program in print in Listing 6 at
http://www.dickbaldwin.com/alice/Alice0930.htm

You can download a zip file containing the program at
http://www.dickbaldwin.com/alice/Alice0930.htm#Resources

No offense intended, but it really sounds to me like you need to step back and learn a little more about programming fundamentals before you worry too much about how to make a butterfly flap its wings.

You wrote in your original posting "I'm trying to teach myself Alice Programming and I came across a book entitled "An introduction to programming using Alice" I of course picked it up and made my way thru till the end here. I've been doing the exercises at the end of each chapter and I find myself to be stuck on this last one."

If you are at the end of the book and you still don't know how to write a method with a parameter, you certainly didn't learn very much in your first pass through the book.

I recommend that you go to http://www.dickbaldwin.com/tocalice.htm, start with the first lesson, and carefully work your way through each lesson in sequence, doing the lab projects and paying very careful attention to what you are reading.


Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm