Created
August 12, 2026 18:00
-
-
Save sampottinger/eec32327af7e4c692d7917cb91cd7aa3 to your computer and use it in GitHub Desktop.
Art exercise for nature of code oscillation. Runnable at https://editor.sketchingpy.org/. BSD-3-Claude license.
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 characters
| import math | |
| import time | |
| import sketchingpy | |
| COLOR_SPEEDS = { | |
| '#33333330': 0.2, | |
| '#33333370': 0.4, | |
| '#333333A0': 0.6, | |
| '#333333F0': 0.8 | |
| } | |
| class Ball: | |
| def __init__(self, x, center_y, color, multiplier, offset): | |
| self._x = x | |
| self._center_y = center_y | |
| self._color = color | |
| self._multiplier = multiplier | |
| self._offset = offset | |
| def draw(self, sketch): | |
| sketch.push_style() | |
| norm = math.sin(time.time() * self._multiplier + self._offset) | |
| amplitude = norm * 200 | |
| y = self._center_y + amplitude | |
| sketch.set_ellipse_mode('radius') | |
| sketch.clear_stroke() | |
| sketch.set_fill(self._color) | |
| sketch.draw_ellipse(self._x, y, 10, 10) | |
| sketch.pop_style() | |
| def make_balls(): | |
| balls = [] | |
| for x_pos in range(25, 500, 25): | |
| for (color, speed) in COLOR_SPEEDS.items(): | |
| balls.append(Ball(x_pos, 250, color, speed, x_pos / 25)) | |
| return balls | |
| balls = make_balls() | |
| def on_step(sketch): | |
| sketch.clear('#F0F0F0') | |
| for ball in balls: | |
| ball.draw(sketch) | |
| sketch = sketchingpy.Sketch2DWeb(500, 500) | |
| sketch.on_step(on_step) | |
| sketch.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment