16
Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science www.soe.ucsc.edu/classes/cmps010/Spring11 [email protected] 16 May 2011

Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

  • View
    216

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

Silicon Valley Hacker CultureIntroduction to Scratch (continued)

UC Santa CruzCMPS 10 – Introduction to Computer Sciencewww.soe.ucsc.edu/classes/cmps010/[email protected] May 2011

Page 2: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Homework #4

To be posted online later today Two parts

A skills-building part that builds up capability through a series of assignments

An open-ended creative part Do something interesting using Scratch

Page 3: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Silicon Valley Hacker Culture

Going back to at least 1975 (and drawing inspiration from the 60s counter culture movement) Silicon Valley has hosted a culture of people hacking with technology

Hacking – playing around with technology, in ways that sometimes were, and sometimes were not aligned with its original purpose

Homebrew Computer Club (1975-1986) A club for early personal computer enthusiasts The Apple I computer emerged out of this club

Page 4: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Silicon Valley Hacker Culture Today Hacker Dojo

A community of engineers, artists, scientists, activists, entrepreneurs and other creative people centered around a co-working and social facility in Mountain View, CA.

http://wiki.hackerdojo.com TechShop

A membership-based workshop that provides members with access to tools and equipment, instruction, and a community of creative and supportive people so they can build the things they have always wanted to make.

Computer-controller laser cutters, 3D printers, sewing machines, wood router, etc.

California locations in Menlo Park & San Francisco, San Jose (summer 2011)

http://techshop.ws/

Page 5: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Maker Faire May 21-22, San Mateo Fairgrounds

http://makerfaire.com/ Large show featuring many

people who are creating novel things, many using computer controllers or software

Inspiration to becomea maker, someone whomakes things (as opposedto someone who onlyconsumes things)

Extra credit deal: Go to Maker Faire Submit your ticket stub, along

with a 3-4 paragraph descriptionof what you liked and didn’t likeabout the show

Due end-of-day, day of the final exam. Up to 10 extra credit exam points

Page 6: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Sprites

Sprites are anything visual you see on screen.

Each Sprite has an associated block of program code.

Box of available sprites

On-screen sprite

Page 7: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Scripts

Clicking on a sprite brings up its associated code (middle pane)Script pane (code

pane)

This code controls how this sprite moves

Page 8: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

How to program

Drag and dropcode blocks intocode pane

Can be free floating, or connect to other sequences of code

Can also select and move code from code pane to remove

Double-click on code block to execute – you’ll see results in the upper right window

Page 9: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Different kinds of statements

Different buttons in the upper left window bring up different programming blocks

Click a button here to bring up different code blockshere

Page 10: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Conditionals in Scratch

Scratch supports conditionals if condition then action if condition then action1 else action2 These are found in the Control tab

Notice that the condition is a smooshed hexagon shape

Conditions can be found under the operators tab (green) and the sensing tab (blue) Conditions are dragged and dropped

into the hexagon shaped holes in a conditional

Page 11: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Example of a conditional: Collision detection Collision detection

Use the “touching” condition, found on the Sensing tab Clicking on the black triangle brings up a pull-down menu

Mouse-pointer is the arrow you movewith the mouse

Edge is the edge of the stage (white window inupper right of screen)

Anything below this is the name of another sprite “Puffy” is the same of a sprite

Example After the green flag is pressed, do forever

Move forward 5 steps Turn two degrees If the sprite is touching another sprite

named Puffy Move 20 steps backwards

Page 12: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Example of a conditional: Key input Key input

Use the “Key ___ pressed?” condition, found on the Sensing tab

Clicking on the black triangle brings up a list of keys that can be detected

Example After the green flag is pressed, do forever

Move forward 5 steps Turn two degrees If the space bar is pressed

Move backwards 20 steps

Page 13: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Variables

A variable is a named storage location for data Can use variables to remember things for later…

E.g., remembering a random number … or for counting things

E.g., a score, the number of times something happened, etc.

To create a variable Click on “Make a variable” on the Variables tab

Will ask you: For a name for the variable (pick a descriptive name) Whether the variable is for just one sprite, or for all sprites

Example Variable named “random-number”

Set variable to a specific valueChange variable + or - by a specific change in value

Is the variable visible in the stage window

Page 14: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Variables example: high-low gamePick a random number between 1 and 100Put the random number in the variable named random-numberRepeat until the player’s answer is the same as the random number (the player guessed correctly)

Ask the player to guess a number between 1 and 100

If the guess is less than the random number, say “Too low!”If the guess is greater than the random number, say “Too high!”

If the guess is the same as the random number, then the “repeat until” loop will stop, and the program will reach here (the first statement after the repeat until loop). Say, “You guessed it!”

Page 15: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Coordination between sprites: broadcast Sometimes you want one sprite to cause another sprite

to do something This is accomplished by the first sprite broadcasting a message The second sprite receives the message, and then does

something

Example

When I see the space bar has been pressed…

… I say “Hello!”

hello message

Page 16: Silicon Valley Hacker Culture Introduction to Scratch (continued) UC Santa Cruz CMPS 10 – Introduction to Computer Science

UC SANTA CRUZ

Pop quiz Open-notes, no computers, cellphones, etc. Questions are evenly weighted

1. Which type of switching (circuit or packet) does the Internet use? Packet switching

2. What technology did Tim Berners-Lee invent so that every computer could display internet-hosted documents? HTML Also acceptable: Web browser

3. What technology did Tim Berners-Lee invent so that every internet resource has a human-friendly name? URL

4. PHP is an example of a language that runs inside of what? PHP runs inside a web browser. Also acceptable: HTML (PHP is a

programming language with statements interspersed among HTML elements)

5. What is a web application? A software application that runs inside a web server (and also has

some code running inside a web browser)6. Give an example of a Web 2.0 web site

Many possibilities: Facebook, Google Maps, the Scratch website, YouTube, etc.