diff --git a/other/Graph_Theory/Graph_Theory.pyde b/other/Graph_Theory/Graph_Theory.pyde new file mode 100644 index 0000000..4ceffc2 --- /dev/null +++ b/other/Graph_Theory/Graph_Theory.pyde @@ -0,0 +1,63 @@ +import random + +class MovingPoint: + def __init__(self, x, y): + self.x, self.y = x, y + self.xSpeed, self.ySpeed = random.randint(-5, 5), random.randint(-5, 5) + self.rotation = random.randint(0, 360) + + def tick(self): + def rnd(): + lower, upper, minimum, maximum = -5, 5, -5, 5 + self.xSpeed = self.xSpeed + random.choice([_ for _ in range(lower, upper)]) + self.ySpeed = self.ySpeed + random.choice([_ for _ in range(lower, upper)]) + self.xSpeed = max(min(self.xSpeed, maximum), minimum) + self.ySpeed = max(min(self.ySpeed, maximum), minimum) + if self.x >= width: + rnd() + self.x = 0 + elif self.x <= 0: + self.x = width + rnd() + if self.y >= height: + self.y = 0 + rnd() + elif self.y <= 0: + self.y = height + rnd() + self.x, self.y = self.x + self.xSpeed, self.y + self.ySpeed + + def render(self): + def lowest(mpoint, points): + dists = [] + for point in points: + dists.append((dist(self.x, self.y, point[0], point[1]))) + tupled = zip(points, dists) + tupled.sort(key=lambda x: x[1]) + return [x[0] for x in tupled[1:3]] + + def dist(x1, y1, x2, y2): + return sqrt((abs(x1 - x2) ** 2) + (abs(y1 - y2) ** 2)) + ellipse(self.x, self.y, 5, 5) + + global MovingPoints + for point in lowest((self.x, self.y), [(MV.x, MV.y) for MV in MovingPoints]): + line(self.x, self.y, point[0], point[1]) + resetMatrix() + +def setup(): + size(500, 500) + frameRate(15) + + global MovingPoints + MovingPoints = [] + for _ in range(70): + MovingPoints.append(MovingPoint(random.randint(0, width), random.randint(0, height))) + +def draw(): + global MovingPoints + background(204) + + for MP in MovingPoints: + MP.tick() + MP.render() diff --git a/other/Graph_Theory/sketch.properties b/other/Graph_Theory/sketch.properties new file mode 100644 index 0000000..2456b0a --- /dev/null +++ b/other/Graph_Theory/sketch.properties @@ -0,0 +1,2 @@ +mode=Python +mode.id=jycessing.mode.PythonMode diff --git a/other/README.md b/other/README.md index 4b3496b..94f467f 100644 --- a/other/README.md +++ b/other/README.md @@ -14,4 +14,6 @@ Other sketches without any specific purpose. If enough fit into a specific categ - **DynamicLines** - A very simple line drawing application. -- **FlipFlopChain** - A simple project displaying how one would count in binary. \ No newline at end of file +- **FlipFlopChain** - A simple project displaying how one would count in binary. + +- **Graph-Theory** - A simple project closely mimicing the particle.js library. \ No newline at end of file