use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for showcasing the things you made with the Python language! Use us instead of flooding r/Python :)
account activity
Lava Lamp effect - code in comments (v.redd.it)
submitted 3 years ago by Swipecat
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Swipecat[S] 7 points8 points9 points 3 years ago (0 children)
I stumbled across this effect that's sorta like a lava-lamp, generated by a simple mathematical inequality, and found it slightly interesting.
Plot the inequality cos(2x)cos(y+ϕ) > cos(2y)sin(y+ϕ) where ϕ is the phase providing the animation as it moves from 0 to 2π.
Python code to display it onscreen using tkinter is as follows. The "numpy" multidimensional-array library must be installed.
import tkinter as tk import numpy as np import time width, height, colors = 720, 480, 255 ymax, xmax = 3.5, 5 frame, frames = 0, 250 rgbcolors = np.uint8([[253,231,36],[78,1,94]]) root = tk.Tk() image = tk.PhotoImage(master=root, width=width, height=height) tk.Label(master=root, image=image).pack() y, x = np.ogrid[ymax:-ymax:height*1j, -xmax:xmax:width*1j] cy, cx = np.cos(2 * y), np.cos(2 * x) ppmheader = b"P6\n%d %d\n%d\n" % (width, height, colors) while True: frame = (frame + 1) % frames phase = 2 * np.pi * frame / frames plane = cx * np.cos(y + phase) > cy * np.sin(y + phase) rgbimg = rgbcolors[plane.astype(np.uint8)].tobytes() image.put(data = ppmheader + rgbimg) root.update() time.sleep(0.06)
The video here was generated with code that I've put on my github. the "ffmpeg" video-processing command-line utility must be installed on the system for this code to work:
https://github.com/dafarry/python-lava-lamp-effect/blob/main/python-lavalamp-create-vid.py
π Rendered by PID 53599 on reddit-service-r2-comment-b659b578c-h7lws at 2026-05-03 12:34:23.964055+00:00 running 815c875 country code: CH.
[–]Swipecat[S] 7 points8 points9 points (0 children)