The Art of Random Lines in MakeCode Arcade

How to Use Random Lines

We made the program “Random Lines” to explore the art of random lines in MakeCode Arcade — and, to experiment with our first MakeCode Slider. Sliders are convenient little gadgets for picking a value from a range of values. We’ve thought of several uses in Arcade. This demonstrates one.

Using Random Lines

The YouTube video below demonstrates the use of Random Lines.

Button B Changes Background Color

The Random Lines background sprite is in the middle square of the screen. The background color can be switched between black and white by pressing Button B.

The Slider — Left and Right Arrow Keys

Below the background, is a slider with values from 0 to 100, which is the number of displayed lines. The slider is increased or decreased using the right and left arrow buttons, respectively. In programming, sliders are common user-interface elements.

Up/Down Arrow Keys Cycle Through Sold Colors — Button A Changes to Random Colors

The colors used for the lines can be either random or solid. If colors are solid, pressing Button A changes the lines to random colors. The up/down button, advances or reverses cyclically through the 15 available colors. The end points of the lines in the display stay the same as the colors change.

Additional Output Available

If the slider value is zero, Button A causes additional information about the programs actions to be displayed. A second such action turns the feature off. The information displayed is essential during debugging. It is also useful in understanding the program. The additional information includes:

  • The number of rejected duplicate lines — as random lines are generated, a line might be a duplicate of a line that has already been drawn. These lines are rejected and a new line is generated. Duplicate lines happen rarely.
  • The number of rejected same-side lines — as random lines are generated, a line might have its two end points on the same side of the square display area. Such a line is a segment on the edge of the square. We judge such a line to be uninteresting and reject it generating another line to replace it. For the algorithm we used to generate random lines, Same-side rejected lines are common.

Random Lines Code

The code for Random Lines will be explained in another post.

To Use Random Lines and Download the Code, Click the Link Below

https://makecode.com/_06FD2beUAPju