cleanup
This commit is contained in:
		| @@ -1,11 +1,10 @@ | |||||||
| #!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||||
|  |  | ||||||
| import os |  | ||||||
| import sys |  | ||||||
| import random  |  | ||||||
| import time |  | ||||||
| import random |  | ||||||
| import colorsys | import colorsys | ||||||
|  | import os | ||||||
|  | import random | ||||||
|  | import sys | ||||||
|  | import time | ||||||
|  |  | ||||||
| Nx = int(sys.argv[1]) | Nx = int(sys.argv[1]) | ||||||
| Ny = int(sys.argv[2]) | Ny = int(sys.argv[2]) | ||||||
| @@ -13,40 +12,40 @@ Ny = int(sys.argv[2]) | |||||||
| PixelsPerFrame = 20 | PixelsPerFrame = 20 | ||||||
| NumLines = 7 | NumLines = 7 | ||||||
| LineGenerationRate = 0.2 | LineGenerationRate = 0.2 | ||||||
| time_ms = 20 |  | ||||||
| try: | try: | ||||||
|     time_ms = int(sys.argv[3]) |     time_ms = int(sys.argv[3]) | ||||||
| except: | except: | ||||||
|     pass |     time_ms = 20 | ||||||
| buffer = bytearray(b"\x00" * (3 * Nx * Ny)) | buffer = bytearray(3 * Nx * Ny) | ||||||
|  |  | ||||||
|  |  | ||||||
| def SetPixel(x, y, r, g, b): | def SetPixel(x, y, r, g, b): | ||||||
|     idx = x+Nx*y |     idx = x + Nx * y | ||||||
|     buffer[3*idx+0] = r |     buffer[3 * idx + 0] = r | ||||||
|     buffer[3*idx+1] = g |     buffer[3 * idx + 1] = g | ||||||
|     buffer[3*idx+2] = b |     buffer[3 * idx + 2] = b | ||||||
|  |  | ||||||
|  |  | ||||||
| class Line: | class Line: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.color = random.random()*0.3+0.7 |         self.color = random.random() * 0.3 + 0.7 | ||||||
|         self.dir = random.randint(0, 3) |         self.dir = random.randint(0, 3) | ||||||
|         if self.dir == 0: |         if self.dir == 0: | ||||||
|             self.posx = 0 |             self.posx = 0 | ||||||
|             self.posy = random.randint(0, Ny-1) |             self.posy = random.randint(0, Ny - 1) | ||||||
|         if self.dir == 1: |         if self.dir == 1: | ||||||
|             self.posx = Nx-1 |             self.posx = Nx - 1 | ||||||
|             self.posy = random.randint(0, Ny-1) |             self.posy = random.randint(0, Ny - 1) | ||||||
|         if self.dir == 2: |         if self.dir == 2: | ||||||
|             self.posx = random.randint(0, Nx-1) |             self.posx = random.randint(0, Nx - 1) | ||||||
|             self.posy = 0 |             self.posy = 0 | ||||||
|         if self.dir == 3: |         if self.dir == 3: | ||||||
|             self.posx = random.randint(0, Nx-1) |             self.posx = random.randint(0, Nx - 1) | ||||||
|             self.posy = Ny-1 |             self.posy = Ny - 1 | ||||||
|  |  | ||||||
|     def step(self): |     def step(self): | ||||||
|         self.color *= 0.995 |         self.color *= 0.995 | ||||||
|         pixel = int(self.color*255) |         pixel = int(self.color * 255) | ||||||
|         SetPixel(self.posx, self.posy, pixel, pixel, pixel) |         SetPixel(self.posx, self.posy, pixel, pixel, pixel) | ||||||
|         if self.dir == 0: |         if self.dir == 0: | ||||||
|             self.posx += 1 |             self.posx += 1 | ||||||
| @@ -58,24 +57,29 @@ class Line: | |||||||
|             self.posy -= 1 |             self.posy -= 1 | ||||||
|  |  | ||||||
|     def alive(self): |     def alive(self): | ||||||
|         return self.posx >= 0 and self.posx < Nx and self.posy >= 0 and self.posy < Ny |         return 0 <= self.posx < Nx and 0 <= self.posy < Ny | ||||||
|  |  | ||||||
| lines = [] |  | ||||||
| while True: |  | ||||||
|     for i in range(PixelsPerFrame): |  | ||||||
|         x = random.randint(0, Nx-1) |  | ||||||
|         y = random.randint(0, Ny-1) |  | ||||||
|         r, g, b = colorsys.hsv_to_rgb(random.random(), 0.7, 0.5) |  | ||||||
|         r = int(r*255) |  | ||||||
|         g = int(g*255) |  | ||||||
|         b = int(b*255) |  | ||||||
|         SetPixel(x, y, r, g, b) |  | ||||||
|     for line in lines: |  | ||||||
|         line.step() |  | ||||||
|         if not line.alive(): |  | ||||||
|             lines.remove(line) |  | ||||||
|     if len(lines) < NumLines and random.random() < LineGenerationRate: |  | ||||||
|         lines.append(Line()) |  | ||||||
|     os.write(1, buffer) |  | ||||||
|     time.sleep(time_ms*0.001) |  | ||||||
|  |  | ||||||
|  | def main(): | ||||||
|  |     lines = [] | ||||||
|  |     while True: | ||||||
|  |         for i in range(PixelsPerFrame): | ||||||
|  |             x = random.randint(0, Nx - 1) | ||||||
|  |             y = random.randint(0, Ny - 1) | ||||||
|  |             r, g, b = colorsys.hsv_to_rgb(random.random(), 0.7, 0.5) | ||||||
|  |             r = int(r * 255) | ||||||
|  |             g = int(g * 255) | ||||||
|  |             b = int(b * 255) | ||||||
|  |             SetPixel(x, y, r, g, b) | ||||||
|  |         for line in lines: | ||||||
|  |             line.step() | ||||||
|  |             if not line.alive(): | ||||||
|  |                 lines.remove(line) | ||||||
|  |         if len(lines) < NumLines and random.random() < LineGenerationRate: | ||||||
|  |             lines.append(Line()) | ||||||
|  |         os.write(1, buffer) | ||||||
|  |         time.sleep(time_ms * 0.001) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     main() | ||||||
|   | |||||||
| @@ -77,14 +77,14 @@ | |||||||
| <h1 style="text-align: center;">Andreas <i>production-ready</i> Interface</h1> | <h1 style="text-align: center;">Andreas <i>production-ready</i> Interface</h1> | ||||||
| <div class="main"> | <div class="main"> | ||||||
|     <div class="col"> |     <div class="col"> | ||||||
|         <h2>Kommando:</h2> |         <h2><label for="list">Kommando:</label></h2> | ||||||
|         <form id="in" class="just" onSubmit="return request()"> |         <form id="in" class="" onSubmit="return request()"> | ||||||
|             <select id="list"></select> |             <select id="list"></select> | ||||||
|             <input id="args"/> |             <input id="args"/> | ||||||
|             <button id="execute">Ausführen</button> |             <button id="execute">Ausführen</button> | ||||||
|         </form> |         </form> | ||||||
|  |  | ||||||
|         <h2>Intensität:</h2> |         <h2><label for="brightness">Intensität:</label></h2> | ||||||
|         <form id="brightnessform" class="just" onSubmit="return setbrightness()"> |         <form id="brightnessform" class="just" onSubmit="return setbrightness()"> | ||||||
|             <input id="brightness" value="1.0"><br/> |             <input id="brightness" value="1.0"><br/> | ||||||
|             <button id="sendbrightness">Setzen</button> |             <button id="sendbrightness">Setzen</button> | ||||||
| @@ -107,13 +107,13 @@ | |||||||
|             <button id="sendflip">Setzen</button> |             <button id="sendflip">Setzen</button> | ||||||
|         </form> |         </form> | ||||||
|  |  | ||||||
|         <h2>Filterimage:</h2> |         <h2><label for="filtername">Filterimage:</label></h2> | ||||||
|         <form id="filterform" class="just" onSubmit="return setFilter()"> |         <form id="filterform" class="just" onSubmit="return setFilter()"> | ||||||
|             <input id="filtername" value="test"> |             <input id="filtername" value="test"> | ||||||
|             <button id="filterflip">Setzen</button> |             <button id="filterflip">Setzen</button> | ||||||
|         </form> |         </form> | ||||||
|  |  | ||||||
|         <h2>Filter expression:</h2> |         <h2><label for="filterexpr">Filter expression:</label></h2> | ||||||
|         <form id="filterexprform" class="just" onSubmit="return setFilterExpr()"> |         <form id="filterexprform" class="just" onSubmit="return setFilterExpr()"> | ||||||
|             <input id="filterexpr" value="0.5+0.25*sin(x/3+t)"> |             <input id="filterexpr" value="0.5+0.25*sin(x/3+t)"> | ||||||
|             <button>Setzen</button> |             <button>Setzen</button> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 T
					T