Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTF #90

Open
King-Oni opened this issue May 11, 2023 · 16 comments
Open

WTF #90

King-Oni opened this issue May 11, 2023 · 16 comments

Comments

@King-Oni
Copy link

I dont know who the hell wrote this hellish unpythonic buggy abomination
THIS is the worst python program I have ever seen
Lucky for you I'll write a better implementation don't ever touch the holy python with your unpythonic hands ever again

@ker2x
Copy link
Contributor

ker2x commented Jul 30, 2023

@King-Oni you think this is an abomination ?
you might want to take a look at the c++ version, i wrote part of it myself.

const float force = distance_squared < radius* radius ? 1.0F / std::sqrtf(distance_squared) : 0.0F;

@ker2x
Copy link
Contributor

ker2x commented Sep 26, 2023

how's your better implementation going ?

@CrookedAlt
Copy link

lol

@King-Oni
Copy link
Author

King-Oni commented Oct 7, 2023

how's your better implementation going ?

I did make a better version that are made for human consumption, then went to work on another project, and like the Idiot I am I did sudo rm -rf particle-engine.py how ironic >:(

@WilliamJPriest
Copy link

Waiting to see the grace of the Pythonic God

@CrookedAlt
Copy link

LOLLLL

@CrookedAlt
Copy link

im actually on the floor rn

@King-Oni
Copy link
Author

King-Oni commented Nov 19, 2023 via email

@Gentle-Ego
Copy link

wait, but I can't even run the C++ program because the ofMain.h; ofxGui.h and ofUtils.h don't even exist...

@ker2x
Copy link
Contributor

ker2x commented Nov 30, 2023

wait, but I can't even run the C++ program because the ofMain.h; ofxGui.h and ofUtils.h don't even exist...

it's a bit annoying how openframeworks work. you need to install the framework and import the project. i think it's described somewhere in the readme.

@Gentle-Ego
Copy link

Gentle-Ego commented Dec 2, 2023

wait, but I can't even run the C++ program because the ofMain.h; ofxGui.h and ofUtils.h don't even exist...

it's a bit annoying how openframeworks work. you need to install the framework and import the project. i think it's described somewhere in the readme.

Thank you
I've done the things written in the README, but the project doesn't work because it continues to get down when I run main.cpp. When it includes ofMain.h it says that doesn't exist

@alanhaertel
Copy link

How is your Python programming going? I can't wait to see some top tier code

@King-Oni
Copy link
Author

King-Oni commented Jan 5, 2024 via email

@CrookedAlt
Copy link

CrookedAlt commented Aug 16, 2024 via email

@hunar4321
Copy link
Owner

hunar4321 commented Aug 29, 2024

Here is a pythonic version, I asked ChatGPT to modify the Python code so that the pythonic community are happy :)

import matplotlib.pyplot as plt
import random
import math

window_size = 200

class Atom:
    def __init__(self, x, y, color):
        self.x = x
        self.y = y
        self.vx = 0
        self.vy = 0
        self.color = color

    def update_position(self):
        self.x = min(max(self.x + self.vx, 0), window_size)
        self.y = min(max(self.y + self.vy, 0), window_size)
        self.vx *= -1 if self.x in {0, window_size} else 1
        self.vy *= -1 if self.y in {0, window_size} else 1

    def apply_force(self, fx, fy):
        self.vx = (self.vx + fx) * 0.5
        self.vy = (self.vy + fy) * 0.5

def draw(ax, atom, size=3):
    ax.plot(atom.x, atom.y, 'o', color=atom.color, markersize=size)

def random_position():
    return random.uniform(1, window_size)

def create_atoms(number, color):
    return [Atom(random_position(), random_position(), color) for _ in range(number)]

def apply_rule(atoms1, atoms2, g):
    for a in atoms1:
        fx, fy = 0, 0
        for b in atoms2:
            dx, dy = a.x - b.x, a.y - b.y
            distance = math.hypot(dx, dy)
            if 0 < distance < 50:
                force = g / distance
                fx += force * dx
                fy += force * dy
        a.apply_force(fx, fy)
        a.update_position()

yellow = create_atoms(50, "yellow")
red = create_atoms(50, "red")
green = create_atoms(50, "green")
all_atoms = yellow + red + green

fig, ax = plt.subplots()
ax.set_xlim(0, window_size)
ax.set_ylim(0, window_size)
ax.set_facecolor('black')

def update():
    ax.clear()
    ax.set_xlim(0, window_size)
    ax.set_ylim(0, window_size)
    ax.set_facecolor('black')

    apply_rule(green, green, -0.32);
    apply_rule(green, red, -0.17);
    apply_rule(green, yellow, 0.34);
    apply_rule(red, red, -0.1);
    apply_rule(red, green, -0.34);
    apply_rule(yellow, yellow, 0.15);
    apply_rule(yellow, green, -0.2);

    for atom in all_atoms:
        draw(ax, atom)

    plt.pause(0.01)

while(True):
    update()
    plt.draw()

plt.close()

@King-Oni
Copy link
Author

King-Oni commented Sep 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants