# Flowchart

:::{card} Learning goals
- translate a process into a flowchart
:::

## Mission: Safe landing

:::{figure} https://gymnasium.farama.org/_images/lunar_lander.gif
Lunar lander trying to land
:::

Problems:
- limited fuel 🌡️
- crash if high speed 💥

How do we control ❓

(flowchart)=
## Flowchart

We can use flowcharts to represent the process of safe landing.

:::{wpd} flowchart
a type of diagram that represents a workflow or process
:::

:::{mermaid}
flowchart LR
    A(Start) --> B[Look at the clock]
    B --> C{
        is time >= 12:00 
        and time < 12:30?}
    C -->|No| D{
        is time >= 19:00 
        and time < 20:00?}
    D -->|Yes| E
    C -->|Yes| E[🍽️ Eat]
    D -->|No| F[🖥️ Work for 25 minutes]
    F --> G(End)
    E --> G
:::

:::{tip}
Draw the flowchart top to bottom, if you prefer.
:::

Main symbols:

:::{list-table} Meanings of shapes
:header-rows: 1
:width: 350px

* - name
  - shape
* - process
  - ▯ (rectangle)
* - decision
  - ◇ (diamond)
* - start or ending
  - ![](https://upload.wikimedia.org/wikipedia/commons/a/ad/Flowchart_Terminal.svg){h=18} (rounded rectangle)
:::

If you heard of [activity diagrams](https://en.wikipedia.org/wiki/Activity_diagram): Flowcharts are a basic form of them.

:::{activity}
Draw a flowchart for the following program
- if the altitude is higher than 100
  - the thruster must be off.
- if the altitude is lower than or equal 100
  - turn on the thruster
- if the altitude lower than or equal 0 (landing)
  - the thruster must be off.

Steps:
1. 8 min work individually.
1. 2 min compare with your partner's.
:::

:::{tip}
Tools for drawing flowcharts:

- Visual: [draw.io](https://app.diagrams.net/). On the tools bar, there is a drop-down for flowchart symbols.
- Declarative: [Mermaid](https://mermaid.live). Select `Flowchart` from the sample diagrams.
:::

## Appendix

- [What do the different flowcharts mean?](https://www.rff.com/flowchart_shapes.php)
- flowchart-based programming environments — compared to only drawing, you can run your flowcharts
  - [Raptor](https://raptor.martincarlisle.com/)
  - [Flowgorithm](http://www.flowgorithm.org)
- [Diagramo](http://diagramo.com/editor/editor.php)
  - another flowchart editor, but does not seem to be maintained since 2014.

