Circle Maze

edited April 2016 in Questions about Code
    // inspirated from: 
    // http://codegolf.stackexchange.com/questions/25967/maze-generation
    // Mathematica

    size(400,400);
    float x = width/2;
    float y = height/2;
    float r = 20;
    float w1= 2*PI / 100 * 1;    // 1 % hole
    float w2= 2*PI;

    background(255);
    stroke(128);
    noFill();
    // Step 1
    arc(x, y, r, r, w1, w2); 

    // Step 2
    for (r=20;r<width;r+=20) {
      w1 += 10;
      w2 += 10;
      arc(x, y, r, r, w1, w2); 
      }

make it better! :)

Tagged:

Answers

  • size(400, 400);
    background(255);
    translate(width>>1, height>>1);
    stroke(128);
    noFill();
    float r = 0;
    while (r<width) {
      arc(0, 0, r, r, 0, TWO_PI-15/r);
      rotate(r += 20);
    }
    
  • realy good! :) ... and the holes are constantly wide!

  • there is a point that i not understand:

    r = 0;
    TWO_PI-15 / r
    

    no exception of division by 0! why?

  • Fractional types don't raise ArithmeticException due to "/ by zero."!
    Instead, it's evaluated as infinity value! @-)

  • yes...

    my trouble with this solution is that we can't really play it.

    It's drawn but not really stored...

    that makes it hard to work with...

    PVector pos = new PVector(10, 10);
    PImage img1;
    
    void setup() {
      size(400, 400);
    
      background(255);
    
      translate(width>>1, height>>1);
      // 
      noFill();
      // Maze 
      stroke(128);
      float r = 0;
      while (r<width) {
        arc(0, 0, r, r, 0, TWO_PI-15/r);
        rotate(r += 20);
      }
    
      img1 = get();
    }
    
    void draw() {
    
      background(255);
    
      //drawMaze() ;
      image(img1, 0, 0);
      // the red ball
      fill(255, 2, 2);
      noStroke();
      ellipse(pos.x, pos.y, 6, 6);
    }
    
    void mouseDragged() {
      PVector addMe = new PVector (mouseX-pmouseX, mouseY-pmouseY);
    
      // make sure both are 1,-1 or 0 only 
      if (addMe.x<0)
        addMe.x=-1;
      else if (addMe.x>0)
        addMe.x=1;
    
      if (addMe.y<0)
        addMe.y=-1;
      else if (addMe.y>0)
        addMe.y=1;
    
    
      PVector pos1 = new PVector();
      pos1.x =   pos.x + addMe.x;
      pos1.y =   pos.y + addMe.y;
    
      if (img1.get(int(pos1.x), int(pos1.y))  ==  color (255)) {
        pos.x =   pos1.x;
        pos.y =   pos1.y;
      }
      else 
        println ("wall");
    }
    
    void drawMaze() {
      // draw maze 
      pushMatrix();
      translate(width>>1, height>>1);
      // green target
      noFill();
      stroke(0, 255, 0);
      ellipse(0, 0, 9, 9);
      // Maze 
      stroke(128);
      float r = 0;
      while (r<width) {
        arc(0, 0, r, r, 0, TWO_PI-15/r);
        rotate(r += 20);
      }
      popMatrix();
    }
    //
    
  • Your code is not running on my system. "Pixeloperation are not supported on your device."

    Separate LOGIC from GUI !

    Recognitation of wall-collision e.g. should be independant from examination of pixel-colors.

    You have at first: Data and the pure logic what to do with this data. The second is the representation for a human for example as a plot on the screen.

  • edited April 2014

    yes...

    That's why I wrote about the solution first given (quote)

    my trouble with this solution is that we can't really play it.

    It's drawn but not really stored...

    My sketch was to illustrate that

  • Fine! ^^

    There is another point that make me amaze: all sketches posted here are made for only one frame - the main frame. It's a bit of challange to integrate this sketches into my framework. e.g. I wanted to add a clock allready given as an example into my project "zion control". Well it's easer to write it new.

  • my sketch is for multiple frames.

  • ok, not all sketches except yours! ^^

    where can i find your sketches?

  • You see mine above

  • a frame is for me a region on the screen or canvas. the "drawMaze" methode uses the full-screen parameteres "width" and "height".

  • I see. I thought you meant sketches without setup() and draw() (sketches that have only one time they run(one frame to display))

    I misunderstood you

  • helpful formula to find the collission between circle and line (or a point)

    http://mathworld.wolfram.com/Circle-LineIntersection.html

Sign In or Register to comment.