pcc-capstone-2024 / capstone2024

0 stars 0 forks source link

PSO swarms flocking algorithms #9

Open Schnittk4 opened 4 months ago

Schnittk4 commented 4 months ago

Make visual reactive max patch for flock?

Schnittk4 commented 4 months ago

More ordered flock when moving, swarm when still?

Schnittk4 commented 3 months ago

@DillonSimeone Hi Dillon. Switched some stuff in the pso code, but it's still not working. I tried adding the repaint function but it broke the code. One thing I noticed in the source code is that it doesn't mention r1 and r2, only c1 and c2 here's the reading I'm working with. The source code is in the directory https://machinelearningmastery.com/a-gentle-introduction-to-particle-swarm-optimization/ https://github.com/pcc-capstone-2024/capstone2024/commits/main/ thanks in advance, and sorry for the sloppy codeT_T

edit: i also dont think that the repaint function is necessary since the draw() loop in p5 does that for us

DillonSimeone commented 3 months ago

@Schnittk4 The directory? Hmm... Ah, this? https://github.com/pcc-capstone-2024/capstone2024 That's a separate branch from the main branch. Hmm, glancing at the code...

I just made those code examples in vanilla javascript for you. It just so happens that I have a bit of experience with goofing around with particles, because I often replace clients' websites with a 404 error; no payments was made notice, with a lot of particle nonsense going on in the background.

Bird behavior, though... That's beyond me. Everyone knows that birds aren't real!

https://dillonsimeone.github.io/Website/MiniProjects/swarmingBehavior/swarm1.html Shapes gets excited when your cursor gets close enough.

https://dillonsimeone.github.io/Website/MiniProjects/swarmingBehavior/swarm3.html Shapes swarms toward your cursor. Try moving your cursor to the edges of the screen.

https://dillonsimeone.github.io/Website/MiniProjects/swarmingBehavior/swarm7.html Swarming toward a point... When 30% of the Shreks have arrived, the point teleports.

Take notice of the names in the URL, there's others. I went from 1 to 7, separating the upgrades I made in each steps toward 7.

Well, anyway. Back to your code...

Tried to change little code as I could to fix it: https://dillonsimeone.github.io/Website/MiniProjects/swarmingBehavior/swarm8.html

I like what you're doing, triggering a set of behavior when enough pixels clusters up closely together. If you want to discard PS5 and go vanilla, check out how my code in Swarm7 detects when shapes gets close enough. On each frame updates, each shape checks how far it's from the target x and y coords.

        update() {
            const dx = target.x - this.x;
            const dy = target.y - this.y;
            const distance = Math.hypot(dx, dy);

            if (distance < 50) {
                this.circleAroundTarget();
            } else {
                this.moveToTarget(dx, dy);
            }

            this.handleCanvasEdges();
        }

        ...

        function animateParticles() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        particles.forEach(particle => {
            particle.update();
            particle.draw();
        });
        ...