Last active
January 2, 2023 12:05
-
-
Save dylnmc/3e37f9af5be4e88121a2 to your computer and use it in GitHub Desktop.
Revisions
-
dylnmc revised this gist
Mar 20, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #! /usr/bin/env python2 """ This is a very bubbly yet simple animation in python's Tkinter. -
dylnmc revised this gist
Jul 22, 2017 . 1 changed file with 20 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,20 @@ #! /usr/bin/env python """ This is a very bubbly yet simple animation in python's Tkinter. A lot of turquoise circles start positioned at the bottom of the Tkinter panel when it opens. Then, on a blue background, The bubbles float fall upwards. Depending on their size, the rise at different speeds: the bigger the faster. When they reach the top, they apparently disappear and start back below the bottom of the screen and float back into view. It's really fun to watch it for a minute or so. The circles are animated entirely randomly; they move left and right to a certain velocity and can move only upwards. The upward velocity depends on the size of the bubble, its x- velocity and a randomly generated acceleration. Similarly, the x-acceleration is generated and then added to a class-wide x-velocity that, like the y-velocity, has a minimum and maximum. As mentioned, the velocities are restricted to a minimum and maximum to direct the circles so as to give the appearance of bubbles rising through water. To run: * be sure that you have python-tk installed (search google for your operating system's version of this) @@ -38,6 +38,7 @@ __author__="dylnmc" from commands import getoutput as getoutp from math import log from random import randint, uniform from signal import signal, SIGINT from sys import exit, stdout @@ -52,32 +53,32 @@ class BubbleMachine(): def __init__(self): # handle ctrl+c from terminal signal(SIGINT, self.signal_handler) # create Tk panel self.root = Tk() self.root.wm_title("bubbles! bubbles! bubbles!") try: self.root.attributes("-zoomed", True) except: self.root.attributes("-fullscreen", True) width = self.root.winfo_screenwidth() height = self.root.winfo_screenheight() # create drawing canvas self.canv = Canvas(self.root, width=width, height=height) self.canv.pack() self.canv.configure(bg="#002b36") # make bubble self.bubbles = [] for i in range(500): self.bubbles.append(bubble(self.canv, randint(0, width), randint(0, height), length=uniform(6, 44))) def play(self): self.root.after(50, self.run) self.root.mainloop() def run(self): for bubble in self.bubbles: bubble.next() @@ -88,7 +89,7 @@ def signal_handler(self, signal, frame): stdout.write("\x1B[2D") # moves cursor back 2 so that when user enter ^c to quit, these characters don't appear self.root.quit() # close tkinter frame/panel class bubble(): def __init__(self, canvas, x, y, **kwargs): @@ -102,7 +103,7 @@ def __init__(self, canvas, x, y, **kwargs): self.len = kwargs.get("length", 3) self.circ = self.canv.create_oval(self.x, self.y, self.x + self.len, self.y + self.len, outline="#2aa198", fill="#2aa198") def nextAccelerations(self): self.ax = uniform(-.4, .4) @@ -112,27 +113,27 @@ def nextVelocities(self): self.nextAccelerations() self.vx = max(-1, min(1, self.vx + self.ax)) self.vy = max(-2 * log(self.len) * .75 + self.vx, min(-1, self.vy + self.ay)) def nextPositions(self): width = self.canv.winfo_width() - 15 height = self.canv.winfo_height() + 3 self.nextVelocities() self.x += self.vx self.y += self.vy if self.x + self.vx + self.len < 0 and self.vx < 0: self.x = width + self.len if self.x + self.vx > width and self.vx > 0: self.x = -self.len if self.y + self.vy < 0: self.y = height self.x = randint(0, width) def next(self): v = self.nextPositions() -
dylnmc revised this gist
Dec 5, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ #! /usr/bin/env python """ This is a very bubbly yet simple animation in python's Tkinter. -
dylnmc revised this gist
Nov 21, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ * enjoy """ __author__="dylnmc" from commands import getoutput as getoutp from random import randint, uniform -
dylnmc revised this gist
Nov 16, 2014 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,12 +3,11 @@ """ This is a very bubbly yet simple animation in python's Tkinter. A lot of turquoise circles start positioned at the bottom of the Tkinter panel when it opens. Then, on a blue background, The bubbles float fall upwards. Depending on their size, the rise at different speeds: the bigger the faster. When they reach the top, they apparently disappear and start back below the bottom of the screen and float back into view. It's really fun to watch it for a minute or so. The circles are animated entirely randomly; they move left and right to a certain velocity and can move only upwards. The upward velocity depends on the size of the bubble, its x- -
dylnmc revised this gist
Nov 16, 2014 . 1 changed file with 15 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,21 @@ #! /usr/bin/env python """ This is a very bubbly yet simple animation in python's Tkinter. A bunch of turquoise circles start positioned at the bottom of the Tkinter panel when it opens. Then, on a blue background, The bubbles float fall upwards. Depending on their size, the rise at different speeds: the bigger the faster. They also slow down when they move sideways as they have to travel further. When they reach the top, they apparently disappear and start back below the bottom of the screen and float back into view. It's really fun to watch it for a minute or so. The circles are animated entirely randomly; they move left and right to a certain velocity and can move only upwards. The upward velocity depends on the size of the bubble, its x- velocity and a randomly generated acceleration. Similarly, the x-acceleration is generated and then added to a class-wide x-velocity that, like the y-velocity, has a minimum and maximum. As mentioned, the velocities are restricted to a minimum and maximum to direct the circles so as to give the appearance of bubbles rising through water. To run: * be sure that you have python-tk installed (search google for your operating system's @@ -30,9 +31,9 @@ see not below) * type "cd Downloads" (or wherever you saved this) * run the script - linux: "python bubbles.py" - mac: "/usr/bin/python2 bubbles.py" - windows: "\python\python.exe bubbles.py" (?) * enjoy """ -
dylnmc revised this gist
Nov 16, 2014 . 1 changed file with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,41 @@ #! /usr/bin/env python """ This is one of the cooler python scripts that uses simple animation in Tkinter. A bunch of white circles start positioned at the top of the Tkinter panel when it opens. Then, on a light grey background, The snowflakes gently fall downwards. When they reach the bottom, they apparently disappear and start back above the top of the screen and fall back into view. This continuous and soothing snow fall was so relaxing that I made it open in the background of my mac terminal, which had a transparent background. The circles are animated entirely randomly; they move left and right to a certain velocity and can move both up and down, although the allowed downward velocity - naturally - is faster than that of the upward velocity, which is very minimal. The circles have a class- wide velocity and randomness is introduced through a random acceleration in a given range. As noted, the velocities are restricted to a minimum and maximum to direct the circles so as to give the appearance of snow. To run: * be sure that you have python-tk installed (search google for your operating system's version of this) - linux: "sudo apt-get install python-tk" in terminal - mac: should come with python - windows: ? (install from internet or maybe comes with python) * download this file (preferably to Downloads) * open terminal - ctrl+alt+t on most linux-based operating systems - cmd+Space + type: "terminal" on mac - windows-key + type "cmd" on windows (you will also need to install python in windows; see not below) * type "cd Downloads" (or wherever you saved this) * run the script - linux: "python snow.py" - mac: "/usr/bin/python2 snow.py" - windows: "\python\python.exe snow.py" (?) * enjoy """ __author__="dmcclure" from commands import getoutput as getoutp -
dylnmc created this gist
Nov 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,108 @@ #! /usr/bin/env python __author__="dmcclure" from commands import getoutput as getoutp from random import randint, uniform from signal import signal, SIGINT from sys import exit, stdout from Tkinter import * def main(): bm = BubbleMachine() bm.play() class BubbleMachine(): def __init__(self): # handle ctrl+c from terminal signal(SIGINT, self.signal_handler) # create Tk panel self.root = Tk() self.root.wm_title("bubbles! bubbles! bubbles!") try: self.root.attributes("-zoomed", True) except: self.root.attributes("-fullscreen", True) width = self.root.winfo_screenwidth() height = self.root.winfo_screenheight() # create drawing canvas self.canv = Canvas(self.root, width=width, height=height) self.canv.pack() self.canv.configure(bg="blue1") # make bubble self.bubbles = [] for i in range(500): self.bubbles.append(bubble(self.canv, randint(0, width), randint(0, height), length=uniform(2, 8))) def play(self): self.root.after(50, self.run) self.root.mainloop() def run(self): for bubble in self.bubbles: bubble.next() self.root.update_idletasks() self.root.after(15, self.run) def signal_handler(self, signal, frame): stdout.write("\x1B[2D") # moves cursor back 2 so that when user enter ^c to quit, these characters don't appear self.root.quit() # close tkinter frame/panel class bubble(): def __init__(self, canvas, x, y, **kwargs): self.canv = canvas self.x = x self.y = y self.vx = kwargs.get("x_velocity", uniform(1, 4)) self.vy = kwargs.get("y_velcity", uniform(-4, 1)) self.ax = None self.ay = None self.len = kwargs.get("length", 3) self.circ = self.canv.create_oval(self.x, self.y, self.x + self.len, self.y + self.len, outline="cyan2", fill="cyan3") def nextAccelerations(self): self.ax = uniform(-.4, .4) self.ay = uniform(-.5, .5) def nextVelocities(self): self.nextAccelerations() self.vx = max(-1, min(1, self.vx + self.ax)) self.vy = max(-self.len * .75 + self.vx, min(-1, self.vy + self.ay)) def nextPositions(self): width = self.canv.winfo_width() - 15 height = self.canv.winfo_height() + 3 self.nextVelocities() self.x += self.vx self.y += self.vy if self.x + self.vx + self.len < 0 and self.vx < 0: self.x = width + self.len if self.x + self.vx > width and self.vx > 0: self.x = -self.len if self.y + self.vy < 0: self.y = height self.x = randint(0, width) def next(self): v = self.nextPositions() self.canv.coords(self.circ, self.x, self.y, self.x + self.len, self.y + self.len) if __name__ == "__main__": main()