### Introduction to Object Oriented Programming in Scratch

The Scratch Stage is a coordinate grid with an x-axis and a y-axis.

Every Sprite has a position on the stage. Sprites can be considered Objects on the stage. Every position is represented by a coordinate point with an x- and y coordinate.
As mentioned in the graphic on page one, the stage has limits with the x-coordinates b/t -240 to 240 and the y-coordinates b/t -180 to 180.
There are multiple blocks to travel around the stage.
Feel free to experiment with them!

All sprites have certain object data associated with them:

These can be used like any other regular variables. The idea of direction is new, but it refers to the orientation of the sprite (which way it is facing). All of these data points refer specifically to the current state of the sprite. In order to save states, you need to use a variable.

Rotation: Scratch provides commands to change the current “direction” of the sprite.

This block allows you to point/rotate the sprite to your mouse cursor.
Relative Motion: Many blocks will change the position or direction of the Sprite based on the current position and direction.

This will move ten steps (units) in whatever the current direction is.

This block will create relative linear motion on the edges of the stage (i.e. the bounce. Experiment with it.

There are three ways that the sprite can rotate:
All Around: can face any direction
Left-Right: only either faces 0 degrees or 180 degrees
Don’t Rotate: like it says, direction doesn’t change

Exercises:

Move the sprite to (90,90), then glide it to (-90,90) in one second, then move it to (-90,-90) and lastly glide it to (90,-90) in one second.
Draw a sphere in the costume section and use left arrow key & right array key to control rotational movement. Experiment with the different rotation styles here!
Given two points (both x and y coordinates), glide the sprite from one location to the other before calculating the slope (and printing this value). The formula for a slope is (Y2-Y1)/(X2-X1)
Create an arrow-key game that allows you to move the sprite around the screen. Include a A-D control system that allows you to rotate both left and right with the sprite.
New England is on the boundary between deciduous forest (like oak trees) and coniferous forest (pine trees). Create an imaginary boundary down the y-axis. If your WASD controlled sprite is to the right of this boundary, it will print out “coniferous territory.” Otherwise, it will print out “deciduous” territory. This will simulate the real world. (Hint: You will need to use the x-position data block to determine whether the sprite is to the left or right of the y-axis)

### Conditional Statements in Scratch

Conditional or If-then relationships allow the computer to pick between two options. This kind of selection statement is extremely important.

If-then statements perform an action if the condition is true.  If-then-else statements perform an action if the condition is true and perform a different action if the condition is false

Boolean operators allow us to determine whether a condition is true or false. There are many kinds of boolean operators in Scratch. These diamond-shaped blocks will either return true or false

Comparison Boolean Operators (with Numbers):

These blocks compare two numbers and
Return either true (when you have a valid
statement) or false (non-valid statement).

For example, 1 > 2 would return false and 2 > 1 would return true.

State whether the operator returns true or false:

Conditionals + Comparison Boolean Operators: These two block types can be put together to create if-then relationships with outputs. Please write the printed output (write “nothing” if there is no output) for the code sequences below.

Boolean Logic: Boolean Logic allows us to combine two or more boolean operators to create more complicated conditions. Scratch supports three basic boolean logic blocks.

AND Gate: Both inputs need to be “true” in order to return a “true”

OR Gate: One or both inputs needs to be “true” in order to return a “true”

NOT Gate: Automatically switch the value. True -> False | False -> True

Truth Tables: Boolean Logic can be represented by “truth tables.” These present all possible inputs and provide all possible outputs.
Given: Truth Tables for OR (downward arrow), NOT (double-headed arrow), and AND (upward arrow) (in that respective order).

Comparison Boolean Operators (with Strings): We have a boolean operator that can check for letters in a string.

Keyboard Sensing: You can also create controls based on keyboard booleans which check whether a key is pressed (true result) or not pressed (false result).

What prints when I press “w”:

What prints when I press “a”:

What prints when I press “s”:

What prints when I press “d”:

The “forever” loop: This allows us to keep checking for different conditions and seeing if they are true. Without the forever loop, the flow of control (sequence of code) would run once and be done. This would be very quick, and we wouldn’t be able to press a key in time

Exercises:

Create a variable, set it to a random number 1-3 and use comparison boolean operators and conditionals to print out a color associated with that number (you may select these combinations yourself).

Search the string “I love Scratch” for the letter “s” with an if-then-else statement. Utilize printing to see whether the letter was found.

Write a calculator script, taking in three user inputs (two numbers and the operation denoted by a sign +, -, *, /) and then printing out the solution to the problem based on the given sign.

Initialize (a.k.a. create) a variable to represent a number line. Write a program that continuously (i.e. surrounded by a for loop) allows me to either move up (+1) or down (-1) a number line (represented by the var #).

What is the result of these (try them out!):
(3>2)AND(4<2):
(3>2)OR(4<2):
NOT((3>2)AND(4<2)):
NOT((3>2)OR(4<2)):

Advanced: In chemistry, hydrogen bonds only occur when in elements that contain both hydrogen (H) and nitrogen (N), both hydrogen (H) and oxygen (O), or both hydrogen (H) and fluorine (F). Given two compounds through user input, print whether they will be able to form hydrogen bonds. This can only occur if they both meet the conditions stated before (having both H and N, H and O, or H and F).

### How $\pi$ was almost $3.2$

Yes, you read that right. The numerical constant $\pi \approx 3.14$ could have been equal to $3.2$!

In 1894, physician and amateur mathematician Edward J. Goodwin (c.1825-1902) believed that he had found a way to square the circle. It was proven in 1882 that this can't be done by Ferdinand von Lindemann.

How did he do it then? The way he did it implied various wrong values of $\pi$, most commonly $3.2$. Here is an example. He made this diagram, which is a circle with diameter $10$. He then says the circumference is $32$, not $\sim 31.415...$, which means $\pi = 3.2$! However, at the time, $\pi$ was known to 527 correct digits.

He showed this to Indiana state representative Taylor I. Record, so schools could show this as a way to square the circle without royalties. Record then introduced it to the house under the excruciatingly long title "A Bill for an act introducing a new mathematical truth and offered as a contribution to education to be used only by the State of Indiana free of cost by paying any royalties whatever on the same, provided it is accepted and adopted by the official action of the Legislature of 1897". It was bill #246 of the 1897 sitting of the Indiana General Assembly.

The bill somehow passed the Indiana House of Representatives, and was sent to the Indiana Senate. On the day they were going to vote, Professor Clarence Abiathar Waldo happened to be there. He explained to the Senate that the bill redefined $\pi$, and it actually almost passed, but one senator said that they had no power to define mathematical truth. That is why the Indiana Pi Bill did not pass.