Solved [Advanced] List of Locations in a square spiral

Discussion in 'Plugin Development' started by Quantum64, Aug 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Quantum64

    So basically I need to get a list of locations in a pattern like this:
    [​IMG]
    And be able to access any of them on demand, which is why I need a method like getLocation(int i), returning the x and z values of the corresponding number, rather than storing them in a list, as theoretically I could need an indefinite number of locations. For reference, the lines shown on the picture can represent a 500 block distance.

    I've tried everything I can think of, but I know there must be a way to dynamically work this out. Any help would be appreciated!
     
  2. Offline

    KingFaris11

    Slikey seems like a Meth guy.
     
  3. Offline

    xTigerRebornx

    KingFaris11 and Quantum64 like this.
  4. Offline

    KraZ__

    NOT TESTED

    idk maybe something like this
    Code:
    public List<Location> getLocPattern(Location centerLoc) {
        List<Location> myLocs = new ArrayList<Location>();
        int x = centerLoc.getBlockX();
        int y = centerLoc.getBlockY();
        int z = centerLoc.getBlockZ();
     
        boolean alt = true;
        for(int i = 0; i < 50; i++) {
            int x2 = x;
            int y2 = y;
            int z2 = z;
            if(alt) {
                int x2 = x + i;
                int z2 = z + (i - 1);
                alt = false;
            } else {
                int x2 = x + (i - 1);
                int z2 = z + i;
                alt = true;
            }
            myLocs.add(new Location(centerLoc.getWorld(), x2, y2, z2, centerLoc.getYaw(), centerLoc.getPitch()));
        }
        return myLocs;
    }
     
    //Okay so I know this doesn't work but I guess you will just have to work it out yourself. You just have to use math to work it out. Something I'm not very good at as you can probably tell :D
    
     
  5. Offline

    bobacadodl

    That's the ulam spiral. Pretty sure you can find tons of resources online for ulam spiral generators...
     
    KraZ__ likes this.
  6. Offline

    Quantum64

    Thanks for the attempt KraZ__ (Also a list of locations is exactly what I didn't want). Still looking for help.
     
  7. Offline

    BaranCODE

  8. Offline

    1Rogue Retired Staff

  9. Offline

    Slikey

  10. Offline

    Quantum64

    Finally figured it out, thanks for all the help everyone :)
     
Thread Status:
Not open for further replies.

Share This Page