C SC 100 Lecture Notes
Spring 2008
Pete Sanderson
[
previous
|
schedule
|
next
]
major resource: Tomorrow's Technology and You (Complete), Eighth Edition, Beekman and Quinn,
Pearson Prentice Hall, 2008
Scratch and overview of Chapter 15, Artificial Intelligence
Scratch
What is Scratch?
To quote from scratch.mit.edu:
"Scratch is a new programming language that makes it easy to create your own interactive stories,
animations, games, music, and art -- and share your creations on the web.
Scratch is designed to help young people (ages 8 and up) develop 21st century learning skills.
As they create Scratch projects, young people learn important mathematical and computational
ideas, while also gaining a deeper understanding of the process of design."
The subtitle of Scratch is "imagine * program * share". We will focus on the first two. You
are free to share your results with the Scratch online community, but we will not spend much
time on this part. You can easily figure it out on your own if you wish to participate.
Scratch was developed by the Media Lab at the Massachusetts Institute of Technology
(MIT).
How can I get Scratch?
Scratch is installed in the Towers 107B computer lab. You can also download it directly
from scratch.mit.edu (30MB download). After the download, look for file
scratch.exe and send a shortcut to your desktop for easy launching.
Where are some Scratch resources?
Can I show my Scratch program to friends and family?
You can run your Scratch program on any computer that has Scratch installed. Another way is
to join the Scratch community and post your program to their web site. Then you or anyone
else can run it from there. Finally, the Scratch FAQ page (available from the Support screen) describes
a technique to run your program from your own web page such as the one you created in
this course. I have not tried it.
One thing you definitely cannot do is save it in any of the standard video formats for
playing through a media player or posting on YouTube. Scratch does not have this capability.
What does a Scratch program consist of?
A Scratch program consists of a number of different components that all work together.
Here are the major kinds of components.
Sprite - The most important component, because it is active.
- The program can have one or more of these
- Each sprite runs in its own "layer", so if they cross paths one will pass behind the other.
- Sprites are obtained in various ways
- There is one default sprite, Scratch herself, displayed when you launch Scratch
- You can create sprites using the built-in paint tool
- You can import sprites from the Scratch library
- You can import sprites from any JPEG file
- See the icons at the bottom of the animation window.
- Sprites are positioned in the animation window, called the stage. Positions are
indicated using an (x, y) coordinate pair. The center of the window is (0,0), the
upper left corner is (-240,180) and the lower right corner is (240,-180). In other
words, the window is 480 pixels wide and 360 pixels high.
- Sprites can move around, change costumes, make sounds (and pretend sounds), hide
themselves, and so forth! Their actions are specified using scripts.
Stage - The backdrop for sprites
- In other words, the background image
- A program can have more than one stage
- A stage can have a script, although it has limited capability.
- A stage can be imported from the Scratch library
- A stage can be imported from a JPEG file
- Note that the ideal size is 480 pixels wide by 360 pixels high. You can manipulate
an image in Paint Shop Pro to obtain these dimensions. Be sure to save it in JPEG format.
- The stage can be swapped as the program runs.
Script - A script is a set of commands followed by a sprite or stage.
- A sprite or stage can have more than one script.
- Multiple scripts can be active at a time
- A script is activated and starts to run upon the occurrence of a specified
event.
- Each command is a color-coded block, and a command sequence forms a stack
- We'll come back to scripts in a bit
Costume - A costume is the visual image of a sprite
- A sprite can have more than one costume
- A sprite can dynamically change costumes
- Each costume is an image either painted, imported from the library, or imported from a JPEG.
See the item above on obtaining sprites.
- You animate sprites through combinations of movements and costume changing.
Blocks - The stuff that scripts are made of!
- Each command has a color- and shape-coded block
- Command blocks are connected into vertical stacks
to represent a time-ordered sequence of actions.
- Blocks fit together like pieces of a jigsaw puzzle - the notch shapes have to match
- There are 8 categories of blocks, as seen in the upper left corner of the Scratch screen:
- Motion - commands for moving a sprite (does not apply to stages)
- Looks - commands for changing the appearance of a sprite or stage. This includes talk and think bubbles.
- Sound - commands that control sounds made by a sprite or stage. You can get sounds from the library, record them
in Scratch, or import them.
- Pen - commands that control a pen that a sprite can use to create drawings
- Control - control structures for decision-making, repetition, activation, and so on.
- Sensing - events and conditions that can be plugged into Control or Number structures
- Numbers - relationships and numeric operations that can be plugged into a Control structure
- Variables - you can create and use identifiers that hold a numeric value (like the use of X in mathematics)
- Note that Sensing and Numbers blocks are
not stand-alone commands that can be stacked. They can only be plugged into
like-shaped (rounded or pointy edged) holes provided in other blocks.
Scratch is a full-blown programming language
Scratch includes all three of the major programming language constructs:
- Sequence - any vertically arranged stack of blocks in a script represents a step-by-step instruction sequence
- Selection - the if, if-else and forever-if blocks in the Control category
are used to perform selection, which is decision-making based on a specified condition
- Iteration (repetition) - the forever, forever-if, repeat, and repeat-until
blocks in the Control category repeatedly carry out the commands on the stack of blocks they enclose.
Enough of this theoretical stuff! How to I write and run a Scratch program?
To write a program, just
- Click the New button at the top, to clear out any current program
- Obtain and select a sprite
- Select the Script tab in the center (should be selected by default)
- Select the Block category; start with Control
- Drag and drop blocks from the block palette into the Script area!
- Repeat for additional scripts and sprites
- An easy way to remove a block is to isolate it and drag it back into the block palette
- Experiment!
Save it periodically!
- Click the Save or Save As button
- Click the Computer folder at the left
- Click the Z: at the bottom of the list
- You are now in your Otterbein home folder
To run a program, just click the Green Flag. To stop it, click the Red Stop Sign.
Scratch and Intelligence
Scratch can do some pretty sophisticated things, including things that we normally associate with
human intelligence. Does this mean Scratch is intelligent
Overview of Artificial Intelligence
- for details, see notes posted for upcoming video
- definition is a moving target
- AI is the study of ideas which enable computers to do the things that make
people seem intelligent (Winston, 1977)
- AI is the study of the computations that make it possible to perceive,
reason, and act (Winston, 2000)
- "the brain is the hardware that the mind, the software, runs on"
- Two approaches to AI summarized by:
- Strong AI : use computers to simulate human mental processes (models brain structure)
- Weak AI : exhibit intelligent behavior independent of human thought process (does not model brain structure)
- Turing test for machine intelligence: human converses via keyboard with remote human or machine. If after a period
the person cannot determine whether the other is human or machine, and it turns out to be a machine, the machine
is considered intelligent.
- computers are structured very differently than our brains are structured (we have billions of simple and slow
processors called neurons that are highly interconnected and work in parallel).
- computers do very well the things that humans do very poorly (e.g. math, remember lots of detailed data)
- computers do very poorly the things that humans do very well (e.g. visual recognition)
- some practical applications of AI
- expert systems: use knowledge base containing facts and rules to
draw inferences in deep but narrow knowledge realm. Originally used for
medical diagnosis and searching for mineral deposits. Many decision-making
applications.
- neural networks: imitate structure of brain. Through training, patterns in the brain's network are formed. Helps machine recognize similar patterns
Common applications include speech recognition and generation, and robotics.
- The CYC (pronounced "psych") project highlighted in the video attempts to make knowledge bases
more widely usable by providing rules and facts about common sense knowledge (e.g. if you are
in the classroom, so is your left leg). See www.cyc.com
[
Pete Sanderson
|
Math Sciences server
|
Math Sciences home page
|
Otterbein
]
Last updated:
Pete Sanderson (PSanderson@otterbein.edu)