Wednesday, October 27, 2010
Control structures
This is a control structure that I made.
When I press the space bar it will rotate 15 degrees and if I press it continuously it will move around itself continuously. If it touches the colour, then it will switch to a different costume or different image.
Moving a character
To basically make a character move youy need to create 4 different algorithms. Each for the separate directions that you need to go(right left, up and down)
Firstly you put the "when ___key is presses"[The basic keys that are widley used are the left arrow, right arrow, up arrow and down arrow] . This is so that the person has a choice of where to go and this certain key will instigate the algorithm associated with it.
Then we need the "point in direction___". This is to change the direction of the sprite so that it will go to a specific direction.
Then we need to put the "move__steps". this makes the sprite move__steps in the direction they were turned to in the previous command.
That is basically how you make your cahrater move.
Firstly you put the "when ___key is presses"[The basic keys that are widley used are the left arrow, right arrow, up arrow and down arrow] . This is so that the person has a choice of where to go and this certain key will instigate the algorithm associated with it.
Then we need the "point in direction___". This is to change the direction of the sprite so that it will go to a specific direction.
Then we need to put the "move__steps". this makes the sprite move__steps in the direction they were turned to in the previous command.
That is basically how you make your cahrater move.
Scratch challenge 4 - Animation
* Using the flying bat you created in challenge 3, now have your bat fly towards you, by using the “change size” function.
- This is the script that I can possibly use to make moving animation. This works by firstly adding the "when (green flag) clicked" block. This will help the animation to be organised and start at a certain time rather than just randomly starting.
- Then we need to put the "forever" block. What this does is makes the instructions inside the block loop forever. That means the bat, which is the animal in this script, will keep flying forever.
- The purpose of the instructions inside the forever block is to make the bat appear to be flying. How we do this is cahnge between two pictures/ costumes- one of the bat's wings up in the air and the other with the wings down. The 'switch to costume "bat-a"'. I put this at the beginning because the costume needed to be changed from the orignal sprite which was a cat. So basically the bat has its wings up, waits for 0.3seconds, then moves 5 steps forward to make it look like its flyign forward. Then it switches costumes which makes it look loke the wings go down, waits for 0.3 seconds and moves 5 steps forward.
- At the end i put the "if on edge bounce" block. I f i don't put this then the bat will fly away from the screen. To make the bat stay in the screen, we need to make it turn from teh edges and that is what this block does.
- Also we need to look at the options at the top of the programme and click on this(the highlighted part which says (only left-right)
- Usually the bat will go upside down after it bounces off the edge but if you click on this the bat will stay upright.
Wednesday, October 20, 2010
Flowcharts
This flowchart is the algorithm for how long the LED light is turned on. After one second it turns off.
This flowchart simply is the algorithm to tell us if the"sunstance" is above freezing or below freezing.
1. Convert one of the algorithms you have created in the previous task into a flowchart, e.g. opening a door, moving through a traffic light.
This is my flowchart for the traffic lights:) click on it for a better view.
Tuesday, October 19, 2010
Algorithms
“Computers never do what you want them to do,
they only do what you tell them to!”
Using the web, find definitions for the following terms and post them on your blog. Make sure the definitions relate to computers and programming.
1. Algorithms: Step by step instructions required to complete a task
2. Pseudocode: Pseudocode is kind of structured English for describing algorithms. It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax.
3. Machine Language: Sometimes referred to as machine code or object code, machine language is a collection of binary digits or bits that the computer reads and interprets. Machine language is the only language a computer is capable of understanding.
4. High Level Computer Language: A programming language that enables a programmer to write programs that is more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages.
5. Flowchart: It is a type of diagram that represents the algorithm/processes in step by step boxes.
6. Sequence: A boot sequence is the initial set of operations that the computer performs when power is switched on.
7. Selection: Is a type of control stucture when programming and the computer makes a "selection" if the requires criteria is available
8. Repetition: Is a type of control structure in programming where the action is repeated again until a specified time or forever.
Then with the aid of class discussions, write an algorithm for the following processes;
ALGORITHMS
In your algorithm write each step of the process on a new line. Remember not to assume the computer knows anything.
1. opening a door and entering a room.
- move 90 degrees to your right,
- take 5 medium steps forward,
- lift your hand so that it is in level with the door knob,
- grab the knob,
- turn it 180 degrees, and
- push out the door so that it is fully open
- end
2. Negotiating traffic lights as you drive down a street.
- Approach lights
- if you see a green light, continue
- if you see a red light, stop
- if you see a yellow light, slow down
- end
Subscribe to:
Posts (Atom)