Question: Modifying the code provided... it should create this image..... . 2 D Random Walk With the addition of a second dimension, the process can get

Modifying the code provided... it should create this image......2D Random Walk
With the addition of a second dimension, the process can get more interesting. The idea is still the same:
generate a random number (no longer a coin flip, but a random value between 1 and 4), and based on that
number, move in a particular direction. For example, a 1 might be used to represent up, or north, or a decrease
in the y-value of a point, while a 2 might represent right, east, an increase in the x-value of a point, and so on.
2D Random walks, with approximately 70,000 "steps" each
Description
For this assignment, you are going to create a program that looks like the following: 2D Random Walk
With the addition of a second dimension, the process can get more interesting. The idea is still the same:
generate a random number (no longer a coin flip, but a random value between 1 and 4), and based on that
number, move in a particular direction. For example, a 1 might be used to represent up, or north, or a decrease
in the y-value of a point, while a 2 might represent right, east, an increase in the x-value of a point, and so on.
2D Random walks, with approximately 70,000 "steps" each
Description
For this assignment, you are going to create a program that looks like the following: The key features of this program will be: The UI, which consists of a few controls from the ControlP5 library:
A Start button, to clear the previous result and start a new random walk.
2 Toggles:
One to control whether the color ramps up based on the number of iterations.
One to control whether the random walk is executed all at once, or gradually, one frame at a time.
TERMINOLOGY NOTE: A toggle is essentially a checkbox.
2 Sliders:
One to control the maximum number of iterations, with a range of 1000 to 500,000.
One to control the number of steps to be executed at once in the gradual process, with a range of 1
to 1,000.
The rendered data itself, the visual result of the random walk algorithm you implement.
Random Walk Algorithm - Moving
As mentioned earlier, the simplest form of the random walk algorithm is in one-dimensional space and involves
a "coin toss"-generating a random number that is either 0 or 1. Based on the result, move either left or right,
and repeat as many times as you like, or as specified by some variable.
In 2-dimensions, the same concept applies. You can generate a random number between 1 and 4(or 0-3, if
you want to count like a programmer!) and then move accordingly:
// Take a step
Generate a random number from 0-3
if number is 0
move up
else if number is 1
move down
else if number is 2
move left
else if number is 3
move right
/* After you've taken a step, the next thing would be to draw the step. In this
assignment, that will be a simple point, using the point(x, y) function. */ For this assignment, however, you should clamp the values to ensure they always stay within a particular
range. The range in this case would be 0 and the width for the x value, and 0 and height for the y value.
Random Walk Algorithm - Drawing
After you've taken a step, the next thing would be to draw the step. In this assignment, that will be a simple
point, using the point(x,y) function. The color of the point is determined by the last value(s) passed to the
stroke() function.
UI Specifications
Structure your UI so that it matches the image earlier in this document. Small discrepancies such as the
position of a control, text size, etc. are acceptable, but try to match the layout as closely as possible.
Window Size: Create a window of size (800,800)
NOTE: If you have a high-resolution display, 800 might appear quite small! You can call the function
pixelDensity() and pass it a value of 2, AFTER you call the size() function in setup().
Background Color: The background color used in the example is (140,170,210). You may change this to
something else if you wish, but the primary functionality (the random walk) will range from black to white. Any
background color that makes the main functionality difficult/impossible to see may incur a penalty.
Start Button
The start button should do just that: start the execution of your algorithm. Clear the screen of any previous
results, reset any necessary values, and begin. Whether your program is running gradually or all at once, it
should begin with the press of this button.
SpecificatioIndividual controls are then added to this object, and the functions to
Modifying the code provided... it should create

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!