Skip to content

arnstein/nuclearGraphics

 
 

Repository files navigation

NuclearGraphics

funni logo

This is some live graphics software I made in tkinter. It started from trying to replicate the Looking At Your Pager visuals in Python, it went well so I made more, then a way to switch between them. I also plageurized imitated effects from live Aphex Twin graphics by Weirdcore, and I've used it in a live performance before. So here the code is for people to use if they are deranged that they'd try and use this so inclined.

Premise

Essentially it takes a webcam image, then turns it from OpenCV to Pillow, combines it with a GIF if you want, passes it through a filter, then puts it on a Tkinter window.

More detailed flow of the program

It figures out what webcam you want. If it finds multiple, it should ask you but idrk tbh. If it finds none, you've not plugged one in or not started a virtual one. If you already have, the port number is higher than 0, so fix it or cope.

Then it creates a webcam object. This is called fakeCam. This deals with merging GIFs with a photo from your webcam.

blah blah blah empty variable list because this updates every time you change effects, it's pointless to do it here too...

The GIFs are loaded, as well as the number of frames because contrary to popular belief, Image.n_frames barely works if at all, it never worked for me. Put the gifs in /gifs for them to be loaded. Number them, one for each effect you want. Also, count from 0, so the first effect loads 0.gif, the second one does 1.gif, etc. If you don't want a gif, omit gifAmount from the setlist for the effects you don't want it on.

Then a tkinter window is created and it has an image on it. To start, press enter. To switch effects, use the left and right arrows or click on the main bit of the window.

On changing the effect

Gets the current gif, gets the required variables for the effect, changes the window title

On each new frame

Calls callback, which gets the image from the effect, which gets it from fakeCam. It resizes it to fit the window, then puts it there.

I think that just about does it

Programming in a sequence

  1. Open set.json
  2. All the effects are already there. For each effect, it currently looks like this:
[
    {
        "names": [
            "ascii"
        ],
        "gifAmount": 0.5
    }
]
  1. Basically copy this over and over again in the list with different effects and Gif amounts, which are a value from 0 to 1 representing how much of the input video is from the Gif. The included effects are below, but you can use more if you add them. Effects can also be stacked and are executed in the order they appear in the names list.
"ascii"
"blurDart"
"circle"
"colourOffset"
"flipDiff"
"imgFX"
"kaleidoscope"
"maximum"
"mirrorEcho"
"oppDiff"
"pixSort"
"reciprocal"
"RGBSwapper"
"stretch"
  1. If you want to add Gifs to the effect, put them in gifs and name them 0.gif, 1.gif, etc, for as many effects as you need. If an effect doesn't need a Gif, don't add a gif for the effect and you can also remove gifAmount from the sequence.
  2. Done!

Adding custom effects

  1. Add the folder name to the imports at the very top of main.py
  2. In callbacks in main.py, add "[effect name]": [folder name]
  3. Done!

Creating your own effect

  1. Create a folder called live[effect name]
  2. Add __init__.py
  3. In __init__.py, add the following code:
from PIL import (
    Image,
    ImageFilter
)

#constant variables here

def variables(cam):
    return [] #fill this list with the variables you need, although frankly it can be any data type as long as it's only one variable

def callback(img, variables):
    #get your variables here with variables[0] or whatever
    #manipulate img and return it
  1. Add the effect as outlined in the previous section.
  2. Done!

About

Live camera graphics written in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%