# Showing Camera Shutter Effect

Developing the camera shutter effect program with Numpy and Tkinter.

## We'll cover the following

These are the libraries that you will be using.

```
import tkinter as tk
import numpy as np
from PIL import Image, ImageTk
```

## Getting set up

This program will use conic sections to compute the ellipses that will represent the propellers. Here is a very high-level mathematical explanation: the absolute value of a complex plane in the third dimension is a cone. Slicing the cone in planes parallel to the x-y plane results in a circle. Anything from the circle down to the Z = 0 plane is a disk. Adding multiple cones offset from the origin results in a solid ellipse, and moving the location of the ellipse around the origin X amount of times results in X number of blades in a propeller. Conic sections continue to haunt you, and this time, they are *complex*! This program glosses over some difficult topics like representing a two-dimensional array with one variable with `Numpy`

, creating geometric shapes from simple expressions of complex numbers, and using addition and multiplication to translate the geometric shapes.

First, you need to get `Tkinter`

configured. You will create a `Tk`

instance that is the base Tkinter instance, get the “stage” ready that is where the image goes and set the stage height and number of propeller blades.

```
root = tk.Tk()
stage = tk.Label(root)
stage.pack()
height = 300
num_propeller_blades = 4
```

## Spinning the propeller

The next snippet creates a meshgrid that returns a three-dimensional array; this array helps you to create the 3D plane that will create the spinning propeller. You also establish the bent propeller image from the complex plane that will start out blank (`zeros`

) and eventually be filled in when the line overlaps the spinning propeller.

```
x, y = np.ogrid[-height/2: height/2, -height/2: height/2]
plane = x - 1j * y
bentprop = np.zeros_like(plane, dtype=np.bool)
```

You can learn more about `ogrid()`

here [2]. The `- 1 j`

means the propeller will spin clockwise; change it to `+ 1 j`

for counter-clockwise rotation. For each “row” in your frame height (300 pixels), you need to sweep the shutter down one pixel, create the propeller blades, rotate the propeller blades, and “remember” where the shutter line touched the spinning propeller blade.

Get hands-on with 1200+ tech skills courses.