๐Ÿ“ Programming Basics#

โ€œPrinting โ€˜hello worldโ€™ is cute, but letโ€™s get realโ€”programming is your secret weapon to control the digital realm. ๐ŸŒ๐Ÿ’ปโ€

๐Ÿ‘ฉโ€๐Ÿ’ป Computer Programs in a Nutshell#

  1. ๐Ÿ› ๏ธ Takes some input from the user (or a nosy robot).

  2. ๐Ÿง  Processes it with computations (the brainy part).

  3. ๐ŸŽ Spits out something useful (or at least tries to).

๐Ÿ”‘ TL;DR: A program is just an obedient machine that does whatever you tell itโ€”literally, whatever. So choose your words wisely. ๐Ÿ˜

๐Ÿ™Œ The First Programmer (Respect, Ada)#

Ada Lovelace, 1815

She wasnโ€™t just writing code; she was predicting the future! One of her brilliant feats was sketching out how to calculate Bernoulli numbersโ€”before computers were even a thing. Mind = Blown. ๐Ÿคฏ

Ada Lovelace

Also: Charles Babbageโ€™s Analytical Engine

It was like the prehistoric ancestor of your laptop. Check out this beauty:

Analytical Engine

๐Ÿง  Computational Thinking#

Humans vs. Machines

  • ๐Ÿง  Humans: Flexible, creative, and occasionally a little messy.

  • ๐Ÿค– Computers: Literal, logical, and absolutely unforgiving.

Takeaway: When programming, channel your inner robot and get comfy with giving painfully specific instructions. Precision is the name of the game. ๐ŸŽฏ

โœ๏ธ Exampleโ€”Drawing a Square#

You: Pick up a pen, doodle a square, done. Easy, right? โœ๏ธ

Computer: โ€œWhatโ€™s a square?โ€ ๐Ÿ˜ต

To make a computer draw one, you have to:

  1. Start at a specific point.

  2. Draw a straight line of fixed length.

  3. Turn exactly 90ยฐ.

  4. Repeat the process until you close the shape.

Pro Tip: Computers are brilliant at following orders but terrible at improvising. ๐Ÿ™„

import turtle

# Set up the screen
screen = turtle.Screen()
screen.setup(width=600, height=600)
screen.bgcolor("white")

# Create the turtle
pen = turtle.Turtle()
pen.speed(1)

# Draw a square
for _ in range(4):
    pen.forward(100)  # Move forward 100 units
    pen.right(90)  # Turn 90 degrees

# Finish up
turtle.done()

More Advanced Example#

turtle.setup(width=600, height=500)
turtle.reset()
turtle.hideturtle()
turtle.speed(0)

turtle.bgcolor("black")

c = 0
x = 0

colors = [
    # reddish colors
    (1.00, 0.00, 0.00),
    (1.00, 0.03, 0.00),
    (1.00, 0.05, 0.00),
    (1.00, 0.07, 0.00),
    (1.00, 0.10, 0.00),
    (1.00, 0.12, 0.00),
    (1.00, 0.15, 0.00),
    (1.00, 0.17, 0.00),
    (1.00, 0.20, 0.00),
    (1.00, 0.23, 0.00),
    (1.00, 0.25, 0.00),
    (1.00, 0.28, 0.00),
    (1.00, 0.30, 0.00),
    (1.00, 0.33, 0.00),
    (1.00, 0.35, 0.00),
    (1.00, 0.38, 0.00),
    (1.00, 0.40, 0.00),
    (1.00, 0.42, 0.00),
    (1.00, 0.45, 0.00),
    (1.00, 0.47, 0.00),
    # orangey colors
    (1.00, 0.50, 0.00),
    (1.00, 0.53, 0.00),
    (1.00, 0.55, 0.00),
    (1.00, 0.57, 0.00),
    (1.00, 0.60, 0.00),
    (1.00, 0.62, 0.00),
    (1.00, 0.65, 0.00),
    (1.00, 0.68, 0.00),
    (1.00, 0.70, 0.00),
    (1.00, 0.72, 0.00),
    (1.00, 0.75, 0.00),
    (1.00, 0.78, 0.00),
    (1.00, 0.80, 0.00),
    (1.00, 0.82, 0.00),
    (1.00, 0.85, 0.00),
    (1.00, 0.88, 0.00),
    (1.00, 0.90, 0.00),
    (1.00, 0.93, 0.00),
    (1.00, 0.95, 0.00),
    (1.00, 0.97, 0.00),
    # yellowy colors
    (1.00, 1.00, 0.00),
    (0.95, 1.00, 0.00),
    (0.90, 1.00, 0.00),
    (0.85, 1.00, 0.00),
    (0.80, 1.00, 0.00),
    (0.75, 1.00, 0.00),
    (0.70, 1.00, 0.00),
    (0.65, 1.00, 0.00),
    (0.60, 1.00, 0.00),
    (0.55, 1.00, 0.00),
    (0.50, 1.00, 0.00),
    (0.45, 1.00, 0.00),
    (0.40, 1.00, 0.00),
    (0.35, 1.00, 0.00),
    (0.30, 1.00, 0.00),
    (0.25, 1.00, 0.00),
    (0.20, 1.00, 0.00),
    (0.15, 1.00, 0.00),
    (0.10, 1.00, 0.00),
    (0.05, 1.00, 0.00),
    # greenish colors
    (0.00, 1.00, 0.00),
    (0.00, 0.95, 0.05),
    (0.00, 0.90, 0.10),
    (0.00, 0.85, 0.15),
    (0.00, 0.80, 0.20),
    (0.00, 0.75, 0.25),
    (0.00, 0.70, 0.30),
    (0.00, 0.65, 0.35),
    (0.00, 0.60, 0.40),
    (0.00, 0.55, 0.45),
    (0.00, 0.50, 0.50),
    (0.00, 0.45, 0.55),
    (0.00, 0.40, 0.60),
    (0.00, 0.35, 0.65),
    (0.00, 0.30, 0.70),
    (0.00, 0.25, 0.75),
    (0.00, 0.20, 0.80),
    (0.00, 0.15, 0.85),
    (0.00, 0.10, 0.90),
    (0.00, 0.05, 0.95),
    # blueish colors
    (0.00, 0.00, 1.00),
    (0.05, 0.00, 1.00),
    (0.10, 0.00, 1.00),
    (0.15, 0.00, 1.00),
    (0.20, 0.00, 1.00),
    (0.25, 0.00, 1.00),
    (0.30, 0.00, 1.00),
    (0.35, 0.00, 1.00),
    (0.40, 0.00, 1.00),
    (0.45, 0.00, 1.00),
    (0.50, 0.00, 1.00),
    (0.55, 0.00, 1.00),
    (0.60, 0.00, 1.00),
    (0.65, 0.00, 1.00),
    (0.70, 0.00, 1.00),
    (0.75, 0.00, 1.00),
    (0.80, 0.00, 1.00),
    (0.85, 0.00, 1.00),
    (0.90, 0.00, 1.00),
    (0.95, 0.00, 1.00),
]

while x < 1000:
    idx = int(c)
    color = colors[idx]
    turtle.color(color)
    turtle.forward(x)
    turtle.right(98)
    x = x + 1
    c = c + 0.1

turtle.exitonclick()