Using It with Python

pyvisualfx is visualfx for Pyctures scenes. It has every effect and every look of the JavaScript library, spelled Python's way.

In Circuitry there is nothing to install: a scene that starts with from pyvisualfx import * has the effects, and runs in the preview beside your code. On your own computer, with Pyctures and a copy of the pyvisualfx repository installed (pip install -e . in its folder), save a scene as scene.py and run pyctures run scene.py.

For effects that move to music, the file needs the sound library as well: from synths import *. Without it there is no sound for the effects to hear, and bass(), pulse() and react have nothing to follow until the scene calls listen_to(...).

from pyctures import *
from pyvisualfx import *

glow(1)                 # bright things shine
trails(1.5)             # and leave a trail that takes a second and a half to fade

def draw():
    background("black")
    circle(mouse.x, mouse.y, 40, "gold")

There is nothing to call in draw: an effect that is on is applied to every frame, after your drawing.

What is different from JavaScript

JavaScriptPython
zoomBlur, rgbSplit, colourCycle, matrixRainzoom_blur, rgb_split, colour_cycle, matrix_rain: a capital becomes an underscore
glow(0.8, { radius: 40 })glow(0.8, radius=40): settings by name
clearEffects(), effectsQuality(0.5)clear_effects(), effects_quality(0.5)
effectNames(), lookNames(), paletteNames()effect_names(), look_names(), palette_names()
react(shine, "strength", "bass", { from: 0.4, to: 1.5 })react(shine, "strength", "bass", 0.4, 1.5)
The effects listen to all the sound by themselveslisten_to(sound_output()) says what to listen to
pattern.segments = () => … (a function, asked every frame)Set the setting in update(dt)
look("vhs").glitch.strength = 1 (a look's parts by name)A look has amount, off(), on() and remove() for the lot
recordVideo, renderFrames, saveVideoNot in Python

help(trails) lists a function's settings and where they start.

Settings

pattern = kaleidoscope(8, zoom=1.5)

def update(dt):
    pattern.angle += 20 * dt        # turn it, twenty degrees a second
    pattern.x = mouse.x             # its middle follows the mouse
    pattern.y = mouse.y

An effect's settings are plain attributes. Each effect has off(), on(), remove() and amount (0 to 1).

A backdrop

A backdrop is behind what you draw, so wipe the picture clear and do not paint it: background() with no colour.

from pyctures import *
from pyvisualfx import *

metaballs("lava")
glow(0.6)

def draw():
    background()

Music

With from synths import * in the scene:

from pyctures import *
from synths import *
from pyvisualfx import *

play_notes("C2 - C2 C2 - C2 G1 -", 0.25, repeat=True)

shine = glow(0.5)
listen_to(sound_output())
react(shine, "strength", "bass", 0.4, 1.5)      # the glow follows the bass

def draw():
    background("black")
    circle(width / 2, height / 2, 20 + 60 * bass(), "tomato")

react is done in the page, on the beat, with no trip through Python. bass(), mids(), highs(), loudness() and pulse() are what the page last told Python, so they are a frame late: fine for the size of a circle. See Moving to the music.

Mistakes

A mistake is said on the line that made it:

ValueError: mirror's side is one of "left", "right", "top", "bottom", "four", not 'sideways'
TypeError: kaleidoscope has no setting called 'zom'. Its settings are segments, angle, zoom, x, y, amount

How it works

Python never touches the page: it may be in a worker, or on another computer. Each function sends one command that turns the effect on in the page, and setting an attribute is one command more. The effects are run once for each frame Python sends, straight after its drawing, and their clock is the dt your update(dt) is given. So however slow Python is, the picture and its effects stay together.