Skip to content
This repository was archived by the owner on Mar 28, 2024. It is now read-only.

Latest commit

 

History

History
106 lines (62 loc) · 2.01 KB

File metadata and controls

106 lines (62 loc) · 2.01 KB
title Fractals
subtitle Functions and Recursion in Scratch and Python
revealjs-url ./lib/reveal
theme fractals
transition slide

Welcome

::: incremental

  • Welcome to CoderDojoDC
  • Welcome to the Maryland STEM Festival

:::

What are Fractals?

Fractals are shapes with some special characteristics:

::: incremental

  • Fine Structure
  • Self-Similarity
  • Scaled Symmetry
  • Recursion

:::

Building a Fractal (1)

To make a fractal, start with a basic shape or line

Building a Fractal (2)

You then repeat the same line in each of the parts of the original

Building a Fractal (3)

As you continue to repeat, or recurse downward, the shape becomes more intricate

Programming Fractals

In order to draw fractals with computers we use two things:

::: incremental

  • Functions: Functions are like little recipes
  • Recursion: Recursion is when a function "calls" itself

:::

A Fractal in Scratch

To draw a fractal in Scratch, we can use the following:

::: incremental

  • Pen Tool
  • Custom Blocks (functions)
  • Recursion (putting a custom block inside itself)

:::

Let's Try it Out!

A Fractal Project on the Scratch Website

A Fractal in Python

import turtle        # imports the turtle module
t = turtle.Turtle()  # creates a turtle
t.forward(100)       # draws 100 pixels forward
t.left(60)           # turns left 60°
t.forward(100)       # draws 100 pixels forward
t.right(120)         # turns right 120°
t.forward(100)       # draws 100 pixels forward
t.left(60)           # turns left 60°
t.forward(100)       # draws 100 pixels forward
turtle.done()        # keeps the window open

The Best Way to Learn is By Doing

  • See if you can change the Scratch project to draw your own shapes
  • If you want to try Python, have a look at the examples