Those radial mazes are quite fun! Consider this example as well – it isn’t written to be compact, but to show an (animated) equivalent to how the original 10PRINT is two randomized edges on a 45-degree angle rather than four on a cartesian grid.
/**
* Radial 10PRINTing
* Jeremy Douglass 2019-11-17 Processing 3.4
*
*/
float r; // radius
float rs = 10; // radius step
float a; // angle
float as = PI/16; // angle step
void setup() {
size(400, 400);
background(255);
r = 2*rs;
}
void draw() {
translate(width/2.0, height/2.0); // centered
if (random(1)>0.5) {
line(sin(a)*r, -cos(a)*r, sin(a+as)*(r+rs), -cos(a+as)*(r+rs)); // forward slash
} else {
line(sin(a)*(r+rs), -cos(a)*(r+rs), sin(a+as)*r, -cos(a+as)*r); // backslash
}
a += as; // advance around ring
if (a>TWO_PI) {
a = 0; // marks line *and* clips accumulating floating-point error
r += rs; // expand ring
}
if (r > width*0.71) frameCount = -1; // auto-reset when offscreen (for square screens)
}
Right now your inner and outer slashes / walls are the same length. The key thing is that each line is anchored on the subdivisions of a ring-- 16ths, 24ths, whatever – by a certain number of steps n and n+1 / n-1. One part of the wall is on the inner ring, one is one the outer. If the ring is divided into n steps, then the we know the angle of each location – if we know the angle and the size of the ring, we can find the point. Note that the wall segments are getting longer and longer as the rings grow out (instead of each segment having the same fixed length – then they just get farther and farther apart).
Well people, a maze is incomplete until we have someone to find their way to the goal.
That someone could be a ball-bearing, a puddle of mercury, a genre-defying Pac-Man, one of Schrödinger’s cats in a multiverse of mazes, anything you like. Whatever it is, the object could find its way to the goal by using edge detection, calculating the shortest route by first taking a view of the complete maze, following all possible routes at the same time and then evaporating in a quantum cloud of dust when a cul-de-sac is reached, or the player could guide the ball through the labyrinth by tilting in the vertical or horizontal plane (a simple mouse movement should do it).
Yesterday night I was reading the maze solving algorithms at wikipedia. But I would like to implement my own, by distance measuring. But unfortunately I have a project to complete this week. But definitely I want to try it.
Excellent walking. I am working on adapting this so the Pac-Man walks left or right (and up or down) according to how the maze has been tilted. The maze is tilted by moving the mouse, but could be haptic on a smart device.
Will think about constraining the movement later…
A different way to implement this in processing is to define 2 small images for the characters / and . You have great support in processing for new p5.Images.
Once you do this you can just randomly display the characters (aka Images) on screen as the old Commodore 64 used to do.
This is an example from codeguppy.com - (note that the code to define images is not shown since codeguppy.com has this built in on top of p5.js). Anyway – you can do this outside codeguppy.com with the above mention and a little bit of extra implementation.
That’s 99 characters. Other than that,I can’t figure out how to shave off a character – I tried a couple approaches with while, but it got just a bit longer.
Brevity is the soul of wit, golf, and much code. But many of the solutions here have something extra, and that is elegance. I suppose elegance is a short apparently simple statement (equation, sonnet, code, etc.) that when unpacked is huge and complex. An example would be the most beautiful equation in the world, "pow(e, i*PI) + 1 = 0”, seen in a freeze-frame of Lisa Simpson’s book cover in ‘MoneyBart’ and named after Leonhard Euler.
I have been trying to find an elegant way to generate the permutations of all the members of a set. I can write code that does the job but it is far from elegant and certainly not brief. Perhaps this should be the subject of a new thread.
e = e = 2.71828; // Euler’s number
i = sqrt(-1); // imaginary