10 print chr$(205.5+rnd(1)); : goto 10

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)
}

Radial10PRINTing_20191117122055 Radial10PRINTing_20191117122055

6 Likes

Very nice indeed.

This movie shows the original code and a Commodore 64 display:

If you were to thicken the lines and use some of those C64 colours (just saying):

#FFFFFF, #744335, #7CACBA,
#7B4890, #64974F, #403285, #BFCD7A,
#7B5B2F, #4f4500, #a37265, #505050,
#787878, #a4d78e, #786abd, #9f9f9f

4 Likes

Great!

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).

2 Likes

Sure, if that’s your jam:

void setup() {
  size(400, 400);
  background(60, 60, 120);
  strokeWeight(3);
  strokeCap(ROUND);
  stroke(124, 124, 228);
  r = 2*rs;
}

Radial10PRINTing_20191117131026

7 Likes

Now that, sir, is a work of art!

1 Like

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).

Pac-Man

What do you think? Can we do it?

1 Like

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.

1 Like

Excellent! @noel

void setup() {
  size(400,400);
  background(0);
  pacMan();
}

void pacMan() {
  noStroke();
  fill(255,255,0);
  arc(200,200,200,200,PI/4,(2*PI)-PI/4);
}

Woke up, a lot of stuff to do, but couldn’t resist. Had to walk.

int i;
float j;
boolean closed;

void setup() {
  size(600, 400);
  background(0);
  noStroke();
}

void draw() {
  fill (0);
  ellipse (i-1, 200, 210, 210);
  fill(255, 255, 0);
  arc(i, 200, 200, 200, j, 6);
  i += 4;
  if (j > 0.6) closed = true;
  if (!closed ) j += 0.05; 
  else j -= 0.05;
  if (j < 0) closed = false;
  if (i > 700) i = 0;
}
4 Likes

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…

Love this design glv!

2 Likes

This is one of the coolest things you can try with processing

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.

https://codeguppy.com/code.html?t=commodore_patterns&list=pixelart

5 Likes

A bit leaner than my last version.

size(529,529);for(int x=1,y=0,n=23;x<n*n;x++){int r=int(random(2))*n,t=x%n*n;line(t+r,y,t+n-r,y+n);if(t==0)y+=n;}
size(529, 529);
for(int x=1, y=0, n=23; x<n*n; x++)
  {
  int r=int(random(2))*n, t=x%n*n;
  line(t+r, y, t+n-r, y+n);
  if (t==0) y+=n;
  }

:)

4 Likes

Wow! Is that the leanest? Ever?

2 Likes

That is some code golf right there.

You can still shave off the size and set n=10 to take advantage of the default size=100x100.

for(int x=1,y=0,n=10;x<n*n;x++){int r=int(random(2))*n,t=x%n*n;line(t+r,y,t+n-r,y+n);if(t==0)y+=n;}

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.

2 Likes

y=0 …. wondering won‘t 0 be the default anyway so skip
=0

1 Like

That would work in Python, but Java is “belt and braces” and requires int initialization. Java is a pretty tough language for a good code golf score. :wink:

You are correct

thank you!

1 Like

People!

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

2 Likes

3 posts were merged into an existing topic: Is there an elegant way to generate the permutations of all the members of a set?