Flocking - Autonomous Agents with GitHub Copilot
Autonomous Agents with GitHub Copilot
Last updated
Autonomous Agents with GitHub Copilot
Last updated
Create a simple flocking system using p5.js and GitHub Copilot. You will:
Set up a project in VS Code
Learn to use GitHub Copilot for coding support
Implement the principles of Separation, Cohesion, and Alignment
Iteratively build a simple flocking simulation
Explore advanced creative challenges
Open VS Code
Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
Search for "GitHub Copilot" and install
Sign in with GitHub if prompted
Create a new sketch using the "Single-sketch folder" option in p5.js.
Open sketch.js
and write a comment at the top to describe what should be done.
Add a comment to specify that your task is to draw your favorite ice cream using basic shapes like ellipse, rect, and arc.
Press the Tab key to see the magic happen with GitHub Copilot's suggestions.
Download
and unzip it into your Develop
/ School
/ KP
folder.
Open the flocking
folder in VS Code
Open index.html
in the browser (you can right-click and select "Reveal in File Explorer/Finder")
You should see points moving on screen (but no flocking yet!)
In boid.js
, you will find three empty methods:
Try writing a comment first:
Then press Enter
and wait for Copilot's suggestion.
Accept suggestions with Tab
. Edit them if needed.
You can also try:
// Steer away from nearby boids
// Average position of neighbors
// Limit vector magnitude
// Wrap around edges
Already working! Each Boid is a point.
In align(boids)
, implement logic to steer towards average velocity of nearby boids.
Test the effect in the browser.
In cohesion(boids)
, steer towards average position of nearby boids.
Test with only alignment + cohesion enabled (comment out separation
).
In separation(boids)
, steer away from boids that are too close.
Tune the weights in flock()
:
Use p5.Vector.dist(a, b)
for distances
Use .limit(this.maxForce)
to keep force under control
Use if (d < desiredDistance)
inside separation()
In show()
:
Draw circles around boids to visualize who they see.
Create a second kind of boid that all others avoid.
Use createSlider()
in setup()
and use the values to adjust behavior.
Use stroke(color)
based on velocity magnitude.
Each function align()
, cohesion()
, and separation()
builds understanding of local interaction
Copilot is a tool, not a crutch! Think first, then ask for help.
Experiment and iterate! Each small change can create new emergent behaviors.
Here are example prompts/comments to use in boid.js
above the empty methods:
They can also experiment in sketch.js
with:
Download from: