Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms Writing instructions in the order they should execute.

Similar presentations


Presentation on theme: "Algorithms Writing instructions in the order they should execute."— Presentation transcript:

1 algorithms Writing instructions in the order they should execute

2 Creating a method Exercise 1 Move the sprite 25 steps, Have the sprite say your name for 3 seconds Turn the sprite around and move it back where it came from Have the sprite say “I love BYOB!” for 5 seconds Some commands require additional information to execute. pointInDirection(90); 90 is the argument (value) The are where you put arguments is called parameter( );

3 Drawing Exercise 1: Write an algorithm to make your sprite draw a square with 50 step sides. Exercise 2: Once you’ve done that, write an algorithm to draw two squares next to each other The squares should not be connected by a line

4 Sequence Exercise: Rewrite your square drawing algorithm to draw a square whenever the space bar is pressed. Clear the screen before each new square.

5 User Interaction Exercise: Write scripts to allow the user to move a sprite around the stage with the arrow keys.

6 Loops Repeated Instructions Exercise 1: Rewrite the script to draw a square using loops. Try not to repeat any code. Exercise 2: Now rewrite the script to draw two squares next to each other using loops. Again, try not to repeat code. This is tricky!

7 User Input Exercise 1: Write an algorithm to do the following: Ask the user for a number between 1 and 10 Draw that many squares Exercise 2: Write an algorithm to do the following: Ask the user for a number between 1 and 10 Ask the user for a number between 1 and 255 Draw the first number of squares with the pen color set to the second number

8 Color Color has values between 1 and 255 RGB Model for color Color(r,g,b) Color(255,0,0) red Color(0,255,0) green Color(0,0,255) blue

9 Creating Variables Variables store information that can change. Create the variable Must set the variable to some amount Assign the variable new information

10 Color Exercise 2: Write an algorithm to do the following: Ask the user for a number between 1 and 10 Ask the user for a number between 1 and 255 Draw the first number of squares with the pen color set to the second number

11 Arithmetic Operators Exercise: Write an algorithm to do the following: Ask the user for a number between 1 and 5 Draw twice that many squares

12 Boolean expressions evaluate to either true or false Relational Operators They show a relation between 2 things. 6 < 7 5 > 4 25 == 7 72 <= 52 They are used in conditionals to execute either the if or the else part of nothing.

13 Boolean Expressions ANDTF TTF FFF ORTF TTT FTF NOT TF FT Compare two complete conditions Draw a square and a rectangle. --- Must do both AND Draw a square or a rectangle -- Can do either OR Draw a square or a rectangle (NOT)

14 Conditionals – Booleans Random Exercise 1: Write an algorithm to do the following: Generate a random number between 1 and 10 Draw a red square if the number is less than 6 Draw a blue square if the number is 6 or greater Exercise 2: Write an algorithm to do the following: Generate two random numbers between 1 and 10 If both are less than 6, draw a red square If both are 6 or greater, draw a blue square Otherwise, draw a purple square Relational Operators Greater than > Less than < Equal to == >= <=

15 Project: Create an algorithm that will generate a random number and say the number and whether it is even or odd. If the random number is even it will say the random number and I am an even number. If it is odd it will say the random number and I am odd Procedure: 1.Create a variable called random 2.Set the random variable to a random number using the random operator 3.Check to see if it is even or odd by creating if statements and using the modulus operator. 4.Create if statements that You will need to use the modulus operator to see if the number is even or odd. 5.Copy your code into a word document.

16 Create a Guessing Game Create the Algorithm You will need to create two variables. guess randomNumber Use the random number generator from operators group


Download ppt "Algorithms Writing instructions in the order they should execute."

Similar presentations


Ads by Google