Quadratic Iteration in the TI-84

Quadratic iteration is used to generate the Mandelbrot set and Julia sets. An image of Mandelbrot set is shown below.

Mandelbrot Set

Mandelbrot Set

Consider the following quadratic iteration

z \to z^2+(0.5+0.2i)

Given an initial value of

z_0=0

This can be done in the TI-84 by storing the initial value in the variable Z and storing the constant in the variable C.

Capture 1

New values can be generated by applying the iterative rule shown above. Applying this operation repeatedly generates a sequence of values.

z_1 = 0^2+(0.5+0.2i) = 0.5+0.2i

The second iteration leads to

z_2 = (0.5+0.2i)^2+(0.5+0.2i) = 0.71+0.4i

This is done in the TI-84 by assigning the expression Z²+C to the variable Z.

Capture 4

While the third iteration leads to the following value:

z_3 = (0.71+0.4i)^2+(0.5+0.2i) = 0.8441+0.768i

Capture 5

Completing these calculations by hands is tedious and error prone. The process can be simplified greatly using a program in the TI-84.

Below is a video demonstrating how to write a program for doing quadratic iteration in the TI-84.

 

\displaystyle \begin{array}{l}x_1=x_2+3\\\int{x\hat{\ }2dx=\frac{x\hat{\ }3}{3}+c}\end{array}

Alice Tutorial: Kangaroo hop

In this example we use sequential and parallel programming constructs, together with a simple loop to program a kangaroo hopping across the screen.

If you are new to Alice you may wish to look at the Getting Started and Hello World tutorials first.

Creating the world

Firstly we create a new world and add a kangaroo to the world. Orient the Kangaroo so that it is facing towards the opposite side of the screen.

Setting up the world

Setting up the world

Moving the Kangaroo

To move the Kangaroo we want to make it look like it is hopping across the screen. To do this we need to make the Kangaroo move forward at the send time that it moves up then down.

Before writing any code we will come up with a simple design.


Do Together
   Move the Kangaroo forward
   Move the Kangaroo up and down

We then refine our design by splitting the last line into two instructions, one to move the kangaroo up and the second to move the kangaroo down.


Do Together
   Move the Kangaroo forward
   Do in order
      Move the Kangaroo up
      Move the Kangaroo down

This can now be easily coded in Alice by deciding how far you wish to move the Kangaroo in each of the move commands, noting that it should move the same distance up and down. When you run the resulting program you will most likely notice a slight problem. The Kangaroo will move up and forward at the same time, then move straight down. The issue is with the timing of the each of the move commands. The default time taken to complete a command in Alice is 1 second. To fix the problem we need to complete the move up and down commands in a total of 1 second. This means that we need to change the timing for each of the last two commands to 1/2 second each. This is represented by the following updated design.


Do Together
   Move the Kangaroo forward for 1 second
   Do in order
      Move the Kangaroo up for 0.5 seconds
      Move the Kangaroo down for 0.5 seconds

To code this change we need to select the duration option from the more option list at the end of the move commands and change the time to 0.5 secs for each of the last two commands.

Repeating behaviour

The kangaroo should now take a single hop, run your program to test that is working correctly.

One hop however is not very exciting, we wish to make the kangaroo hop multiple times. Rather than having to copy the code multiple times we will use a simple loop to repeat the behaviour.

Click on the Loop button at the bottom of the screen, drag it into the programming panel (below your existing code) and select 5 times. Then drag your existing code into the loop. Run the program – the kangaroo should now hop five times across the screen.

The Final Code

The final code for the Kangaroo hop program is shown below. Notice that I’ve also added some additional code so that a sound is played as the kangaroo hops. A short delay is also introduced using the wait command.

Methods

world.my first method ( )

No variables

  Loop 5 times times
  Do together
  kangaroo move forward 2 meters
  Do in order
  Wait .1 seconds
  kangaroo play sound world.wHOP (?:??)
  Do in order
  kangaroo move up 1 meter duration = 0.5 seconds
  kangaroo move down 1 meter duration = 0.5 seconds

Alice Tutorial: Hello World

 

The Hello World program has traditionally been the first programming exercise that students are introduced to when they learn a new language, so why should we be any different in Alice.

Check out http://c2.com/cgi/wiki?HelloWorld for further information and a brief history.

Creating a new world

The first step in making a program in Alice is to create a new world. This is the environment in which all of your characters and objects will interact. There are six world templates to choose from. I have selected the grass world.

Select_Template

Adding a character to your world

The next step is to add a character to your world. To do this click on the Add Objects button. Then browse through the Local Gallery until you find the People folder. Open the People folder and select a suitable character. For this example I have selected the DJ character.

Select_ObjectWriting your first program

In this step we write our first bit of code. To do this click on the dJ object in the top left hand panel. Then make sure that the method tab under dJ’s details is selected. Click on the dJ say method and drag it across to the my first program panel. Click on the text next to say and change the text to “Hello World”.

ProgramRunning your program

Now it is time to check that your program works. Click on the Play button. This will open a new window and run your program. The result should look like the window below. Note that the text will only show for one second.

Play

Code Listing

Events

When the world starts
Do:
world.my first method

 

Methods

world.my first method ( )

No variables

  dJ say Hello World duration = 10 seconds

Extensions

Ok you’ve created your first program. Now is probably a good time to explore a little further. Here’s some ideas:

  • Extend the time that the speech bubble is showing by setting the duration attribute.
  • Introduce a second character who can say something in response
  • Create a short play/story that involves interaction between the two characters.

 

 

 

Alice Tutorial: Indefinite Loops

The learning objectives for this tutorial are:

  • Students can design and implement programs using indefinite loops
  • Students can use the random number function in their programs
  • Students can design and use class level methods

In this activity you will design and develop a cat and mouse game. The cat chases the mouse at the same time the mouse moves in a random direction trying to evade the cat. When the cat finally catches the mouse it will enjoy a tasty meal. To assist in the development of the program we provide a number of suggested development steps.

Step 1: creating the world

Create a new world that includes a Cat object (Animals) and a Mouse object (Animals). Ensure that the mouse is initially a reasonable distance away from the cat and that it is facing away from the cat. You may wish to add some additional scenery to make the chase a little more interesting.

Cat and mouse game

Cat and mouse game

Step 2: creating Chase method

Create a new class method for the Cat class called chase. In this method the cat should turn to face the mouse, then move forward 1 metre. You may wish to add some animation to the cat’s movement, but you should do this after you have completed the other steps.

Step 3: creating run away method

Create a new class method for the Cat class called runAway. In this method the mouse should turn left or right a random amount (up to a maximum of ¼ of a revolution in either direction). You will need to use the random number function to determine the amount to turn. The mouse should then move forward 1 metre.

Step 4: Introducing a loop

In my first methodcreate a while loop. In the body of the while loop you must call the methods chase and runAway. You will need to design a test for the while loop, such that the loop continues until the cat is within a certain distance of the mouse (use an appropriate function to determine the distance between the cat and mouse).

STEP 5: catching the mouse

Create a new class method for the Cat class called eatMouse. The method should perform an appropriate action once the cat catches the mouse. Call the eatMouse method in my first method after the while loop.

Alice Tutorial: Collision Detection

Introduction

Collision detection is a common feature of many animation tools, so a question that sometimes is asked when students first start using Alice is “where is built-in support for collision detection?”. The short answer is that there isn’t any. Remember that Alice is a programming environment in which students can develop animations, as opposed to a purpose built animation tool.  However, because it is a programming environment, Alice gives programmers the ability to readily develop their own support for collision detection. This tutorial provides a description of how such collision detection support can be implemented.

The Alice World

The world for this tutorial consists of a Humvee van and a number of obstacles. Event handling methods and event handlers have already been implemented that allow the user to move the car around the world. For example the code for driving the Humvee forward is as follows. A “Do together” block is used to drive the move the car forward and at the same time rotate the wheel.


humvee.driveforward()
  No variables
  Do together
    humvee move forward 5 meters
    humvee.frontRightWheel turn forward 1 revolutions
    humvee.backLeftWheel turn forward 1 revolutions
    humvee.backRightWheel turn forward 1 revolutions
    humvee.frontLeftWheel turn forward 1 revolutions

 

Setting up collision detection

To set up collision detection and collision avoidance we begin by adding a method, called collision, to the world object  that detects and reacts to collisions. We begin by setting this up for a single obstacle, in this case a building and then extend the code so that we can handle multiple obstacles.  To detect a collision we use the “is within threshold of” function from the humvee object. This is used as the conditional of an if-then-else statement. If the condition is true, then the humvee reacts to the collision by moving backwards a short distance.

When using the “is within threshold of” function, we need to bear in mind that the function is measuring the distance between the centre of the Humvee and the centre of the obstacle. A collision with the side of the obstacle will therefore occur when the distance between the centres is half of the obstacle width + half of the Humvee depth. This distance will when the Humvee is approaching from a different direction, e.g. from the front of the building (in which case we might use the half of the obstacle depth). For this tutorial we just use the above calculation, but we could include a more sophisticated check by determining which direction the Humvee is approaching the obstacle from using the “is in front of” and similar functions.

After developing the collision method, we create a “while world is running” event handler. This event handler will call the collision method, such that whenever a collision is detected the Humvee will react and move backwards.

Dealing with multiple obstacles

So far we can only handle a single obstacle. We could of course develop similar methods to handle the other obstacles, but the DRY (don’t repeat yourself) principle suggests we should find a better way of doing this. Rather than repeating the code for the other obstacles, what we will do is generalise the existing code to handle many obstacles. To do this we use an list variable to represent the collection of all obstacles and then use the “for all do together” construct to implement collision detection and avoidance within a single method.

Collision Detection

Video Tutorial

The following video tutorial provides a step-by-step description of the development of the collision detection capabilities.

Alice Mini Task: Simple Programming

The learning objectives of this tutorial are:

  • Students can design a simple scenario using a combination of sequential and parallel actions, as well as simple loops
  • Students can implement their design using an appropriate combination of constructs.

Exercise 1


Create a new world using the space theme with a jump jet. In this exercise you will use “do in order” (sequential) and “do together” (parallel) constructs to move the jump jet.

  1. In my first method, use the move method from the JumpJet object to move the jump jet up 5 metres, then forward 40 metres.
  2. Modify your code so that the left and right jet engines are turned backwards ¼ of a revolution before the jet moves upwards. You should use a “do together” block to ensure that the two engines are turned at the same time.
  3. Modify your code so that the jet engines are turned to their starting positions before the jet moves forwards.

alice_space_scene

Exercise 2

Create a new world with a dinosaur (or other large animal that has a moveable jaw) and a second animal, such as a chicken. In this exercise you will get the dinosaur to turn to face the chicken, then say “Hello” to the chicken while moving its mouth at the same time.

  1. Write down a pseudo code design for the above scenario.
  2. Use the “Do together” and “Do in order” constructs to implement the above scenario.

Now modify your code, using a simple loop, so that the dinosaur opens and closes its mouth 2 times each time the dinosaur says something. You will need to change the duration for the jaw movement commands.

Alice Tutorial: Getting Started

Before attempting the steps shown below you may wish to complete the tutorials that come packaged with Alice. Click on the Tutorial tab in the Welcome to Alice screen. You may not understand all the concepts in the tutorials – do not worry we will explain these later in the course.

Step 1


Run the Alice program and create a new world by clicking on the Templates tab on the Welcome to Alice screen.  Then select the grass Template.

Selecting a background

Selecting a background

Select the Add Objects button that appears next to the world view. The world view will be expanded and the Local Gallery will appear at the bottom of the screen.

From the Local Gallery, select the Medieval folder, then select the Horse object and Princess object and drag them to the world view.

Inserting objects

Inserting objects

At the moment the two objects are most likely not facing each other.  In the Object Tree, right click on the Horse object, select methods from the menu and then select “horse turn to face”. Select Princess as the target. Do the same for the Princess object.


Finally make the Princess bow, by selecting the UpperBody part of the Princess and then selecting the turn method, turning the upper body forward ¼ of a revolution.

At this stage you should experiment with other methods on the princess and horse to move various body parts. At any stage you can press undo to cancel a particular move.

Step 2

Add a Knight object from the Medieval folder.  This will give you practise in positioning objects in the 3D world. Our aim is to sit the Knight on the Horse. The easiest way to position objects relative to other objects in the world is to use the quad view.You will need to use the different movement controls shown under the quad view button. This will take a bit of experimentation to get right, so don’t panic if you don’t get it right first try.

alice_intro_position

You will notice that the legs of the rider merge into the horse, which doesn’t look great. What you need to do is reposition the legs so that they look more natural. You should experiment with the turn methods on the different parts of the rider’s legs. This will again take a few tries, but remember you can always use undo if you make a mistake.

Programming Assignment

AliceSpashScreen

The learning objectives for this project are:

  • Students can design and implement programs using the Alice programming environment
  • Students can present their completed designs and implementations and reflect on lessons learnt.

For this assignment you will design and program a story or simple game using the Alice 3D programming environment. The aim of this assignment is for students to learn the basic and core concepts of computer programming, and to learn how to document and describe your work.

The assignment contains a number of separate tasks (or milestones) that must be completed at various stages over the course of the unit on  programming.

The assignment is worth 50% of the total marks for the Application Programming unit.

Tasks

Story/Game outline [5%]

For this task you are required to write a story or an outline of a simple game involving some of the characters and objects from the Alice 3D world.

Initial Design [5%]

For this task you are required to write a design (using pseudo-code) for your Alice story/game. The design should include

  • sequencing (actions that occur in order);
  • concurrency (actions that occur at the same time);
  • conditionals (actions that only occur if a certain condition is met);
  • and loops (repeating actions).

The design should address a large portion of your story/game, but does not have to address all aspects yet.

Feedback on your design will be provided.

Portfolio [30%]

At the end of the Application Programming unit, each student will be required to complete a portfolio that includes:

  • The final story/game outline
  • The final design
  • A report on your development process and lessons learned (this should include the items discussed in your presentation)
  • The final code

The final code must be submitted to the teacher Dropbox.