Scratch: Notes

Week 0 - Scratch

Week 0 Scratch - CS50x 2023

  • Keywords:Computer Science.

    Computational Thinking.

    Problem Solving: Inputs, Outputs.

    Representation: Unary, Binary, Decimal, ASCII, Unicode, RGB.

    Abstraction.

    Algorithms.

    Running Times.

    Pseudocode.

    Scratch: Functions, Arguments, Return Values; Variables; Boolean Expressions, Conditionals; Loops; Events; Threads.

Overview:

  #include<stdio.h>

  int main(void)
  {
      printf("hello, world\n");
  }

Computational Thinking

https://cs50.harvard.edu/x/2023/notes/0/cs50Week0Slide38.png

Unary: Unary refers to operations or expressions involving a single operand or input. In mathematics and computer programming, unary operators or functions operate on only one variable or value. For example, the unary minus sign (-) changes the sign of a number (e.g., from positive to negative).

Binary: Binary relates to operations or expressions that involve two operands or inputs. In various contexts, binary can refer to binary numbers (base-2 numeral system) or binary operations that combine two values, such as addition, subtraction, multiplication, and division, where each operation involves two numbers.

Bit: A bit is the smallest unit of data in computing. It can represent one of two values, typically 0 or 1, and is the fundamental building block of digital information storage and processing. The term "bit" is a contraction of "binary digit" and is used to describe the basic unit of information in computers and digital systems. Multiple bits are combined to represent more complex data types.

bit is a zero or one. 8 bits = 1 bytes

Text

Expanded map of ASCII values:

https://cs50.harvard.edu/x/2023/notes/0/cs50Week0Slide93.png

ASCII: It is a widely used character encoding standard in computing that assigns numerical values (codes) to represent characters, symbols, and control characters in digital text. Each character, including letters, numbers, punctuation, and special symbols, is assigned a unique ASCII code, which allows computers to understand and display text data. ASCII encoding is the foundation for text communication and data storage in many computer systems.

Emojis 🥳

Since there were not enough digits in binary to represent all the various characters that could be represented by humans, the Unicode standard expanded the number of bits that can be transmitted and understood by computers.

  • Computer scientists faced a challenge when wanting to assign various skin tones to each emoji to allow the communication to be further personalized. In this case, the creators and contributors of emojis decided that the initial bits would be the structure of the emoji itself, followed by skin tone.
  • More and more features are being added to the Unicode standard to represent further characters and emojis.

RGB

RGB stands for "Red, Green, Blue." It is a color model used in digital imaging and displays to represent colors as combinations of these three primary colors. In the RGB model, colors are created by varying the intensity of red, green, and blue light. By adjusting the intensity levels of these three primary colors, a wide range of colors can be generated. RGB is commonly used in computer monitors, television screens, digital cameras, and graphics software to create and display a full spectrum of colors.

Images, Video and Sound

  • Images are simply collections of RGB values.
  • Videos are sequences of many images that are stored together, just like a flipbook.
  • Music can be represented through MIDI data.

Algorithms

  • Problem-solving is central to computer science and computer programming.
  • Imagine the basic problem of trying to locate a single name in a phone book.
  • How might you go about this?
  • One approach could be to simply read from page one to the next to the next until reaching the last page.
  • Another approach could be to search two pages at a time.
  • A final and perhaps better approach could be to go to the middle of the phone book and ask, “Is the name I am looking for to the left or to the right?” Then, repeat this process, cutting the problem in half and half and half.
  • Each of these approaches could be called algorithms. The speed of each of these algorithms can be pictured as follows in what is called big-O notation:

https://cs50.harvard.edu/x/2023/notes/0/cs50Week0Slide141.png

Notice that the first algorithm, highlighted in red, has a big-O of n because if there are 100 names in the phone book, it could take up to 100 tries to find the correct name. The second algorithm, where two pages were searched at a time, has a big-O of ‘n/2’ because we searched twice as fast through the pages. The final algorithm has a big-O of log2n as doubling the problem would only result in one more step to solve the problem.

Pseudocode and the Basic Building Blocks of Programming

Pseudocode is a human-readable version of your code. For example, considering the third algorithm above, we could compose pseudocode as follows:

  1  Pick up phone book
  2  Open to middle of phone book
  3  Look at page
  4  If person is on page
  5      Call person
  6  Else if person is earlier in book
  7      Open to middle of left half of book
  8      Go back to line 3
  9  Else if person is later in book
  10     Open to middle of right half of book
  11     Go back to line 3
  12 Else
  13     Quit

Functions - pick up, open, look at.

Conditionals - if or else if

Boolean Expressions - true or false

Loops - “go back to line 3.”

Scratch

Scratch IDE (integrated development environment)

Scratch - Imagine, Program, Share

Scratch Coordinate System:

https://cs50.harvard.edu/x/2023/notes/0/cs50Week0Slide167.png

Abstraction

  • Along with pseudocoding, abstraction is an essential skill and concept within computer programming.
  • Abstraction is the act of simplifying a problem into smaller and smaller problems.

sprite – a general term used in game programming for an object or character on the screen with which the player will interact.

costume – background image.

Author photo
Publication date:
Author: Brianna