MCB 419 - HW01 - simple movement
due Tue Jan 22, 2019, 9:00 PM
email p5js project link to mcb419@gmail.com
Introduction
In this assignment you will use p5js to create a single bot that moves around the arena in a circular path. The resulting simulation will look something like this:
Specifications
The arena is 400 x 400 pixels.
The bot is drawn as a yellow circle with a radius of 20 pixels.
The bot has a solid line indicating its heading direction.
The bot’s initial conditions:
x: 50 pixels from the right edge of the arena
y: half way down the arena
heading: facing the bottom of the arena
The bot’s movement:
speed: the bot moves at a constant speed of 3 pixels/tick
heading: on each tick, the heading should be incremented by a fixed amount,
then the bot should be moved by 3 units in that direction. The resulting change in x and y position are given by:
dx = speed * cos(heading)
dy = speed * sin(heading)
trajectory: the bot should move along a circular path with a diameter of 300 pixels. This will be accomplished by incrementing the bot’s heading direction by a fixed amount on each tick. You will need to compute the value for the amount to increment the heading. To do so, consider the following:
- what is the circumference of a cirlce with a diameter of 300 pixels?
- if the bot moves a 3 pixels per tick, how many ticks are required to move along the full circumference of the circle?
- when the bot completes the circle it’s heading will have gone through a change of 2π radians. Knowing the number of ticks required to complete the circle should let you calculate the change in heading per tick.
Instructions
- Open the HW01 template file (right-click to open in a new tab or window)
- Login to the p5js editor (so you can save changes)
- Duplicate the template (you now have a copy that you can edit and save)
- Edit Bot.js you will need to provide code for reset(), update() and draw()
- Edit sketch.js you will need to create the bot and call the reset, update and draw methods at appropriate locations in the code
- Save your changes
- Repeat editing, debugging, saving until things are working properly
- Click “Check implementation” button to test your code
- When you are finished,
SAVE YOUR PROJECT in the p5js editor (this step is important)!
then copy the url of your project from the address bar and paste the url it into an email message
(the url should look something like: editor.p5js.org/YOUR_USERNAME/sketches/RanDoM-cHArS)
send the email to mcb419@gmail.com with the subject line HW01
– End of assignment –