Package wolf.util

Examples of wolf.util.Turtle


        }*/
        break;
      }
      Coordinate startPoint = new Coordinate(x,y);
      double angle = Math.toDegrees(Angle.angle(startPoint, new Coordinate(0,0)));
      Turtle t = new Turtle(startPoint, angle);
      //t.turn(45);
      t.move(32);
      roadQueue.add(new Road(new Intersection(startPoint), new Intersection(t.pos), RoadType.HIGHWAY, basicRule));
    }
    int highwayCount = Math.max((city.sizeX*2+city.sizeY*2)/(3*1024),1);
    for(int i=0; i<highwayCount; i++){
      //highway from random side
      int direction = Math.abs(city.random.nextInt()%4);
      float length = 128;
      switch(direction){
      case 0:{ //North
        log.log("Highway from the north");
        float x = (float) ((this.city.random.nextFloat()-.5)*city.sizeX); //can place in center half of city
        Coordinate startPoint = new Coordinate(x, city.sizeY/2);
        Turtle t = new Turtle(startPoint, ((city.random.nextDouble()*180)%seedHighwayAngleSize)+270);
        t.move(length);
        roadQueue.add(new Road(new Intersection(startPoint), new Intersection(t.pos), RoadType.HIGHWAY, basicRule));
        break;
      }
      case 1:{ //South
        log.log("Highway from the south");
        float x = (float) ((this.city.random.nextFloat()-.5)*city.sizeX); //can place in center half of city
        Coordinate startPoint = new Coordinate(x, -city.sizeY/2);
        Turtle t = new Turtle(startPoint, ((city.random.nextDouble()*180)%seedHighwayAngleSize)+90);
        t.move(length);
        roadQueue.add(new Road(new Intersection(startPoint), new Intersection(t.pos), RoadType.HIGHWAY, basicRule));
        break;
      }
      case 2:{ //East
        log.log("Highway from the east");
        float y = (float) ((this.city.random.nextFloat()-.5)*city.sizeY);
        Coordinate startPoint = new Coordinate(-city.sizeX/2, y);
        Turtle t = new Turtle(startPoint, ((city.random.nextDouble()*180)%seedHighwayAngleSize)+0);
        t.move(length);
        roadQueue.add(new Road(new Intersection(startPoint), new Intersection(t.pos), RoadType.HIGHWAY, basicRule));
        break;
      }
      case 3:{ //West
        log.log("Highway from the west");
        float y = (float) ((this.city.random.nextFloat()-.5)*city.sizeY);
        Coordinate startPoint = new Coordinate(city.sizeX/2, y);
        Turtle t = new Turtle(startPoint, ((city.random.nextDouble()*180)%seedHighwayAngleSize)+180);
        t.move(length);
        roadQueue.add(new Road(new Intersection(startPoint), new Intersection(t.pos), RoadType.HIGHWAY, basicRule));
        break;
      }
      default:{
        System.out.println("You done goofed. Check the seedRoadMap function's direction variable");
View Full Code Here


          double radius = r.width/2;
          if(radius>maxRadius){
            maxRadius = radius;
          }
          //calculate intersection lines
          Turtle t0;
          if(r.a.pos.equals(is.pos)){
            t0 = new Turtle(is.pos, Math.toDegrees(Angle.angle(is.pos, r.b.pos)));
          }else{
            t0 = new Turtle(is.pos, Math.toDegrees(Angle.angle(is.pos, r.a.pos)));
          }
          Turtle t1 = new Turtle(t0.pos, t0.angle);
          //move out to sides of roads
          t0.turn(90);
          t1.turn(-90);
          t0.move(radius);
          t1.move(radius);
          Coordinate t0Start = new Coordinate(t0.pos);
          Coordinate t1Start = new Coordinate(t1.pos);
          //return to first orientation
          t0.turn(-90);
          t1.turn(90);
          t0.move(r.width*6);
          t1.move(r.width*6);
         
          LineSegment ls0 = new LineSegment(t0Start, t0.pos);
          LineSegment ls1 = new LineSegment(t1Start, t1.pos);
          segments0.add(ls0);
          segments1.add(ls1);
        }
        //compute intersections of roads extruded from center of intersection.
        double[] extrusion = new double[is.connecting.size()];
        //double maxDistance = -1;
        for(int j=0; j<is.connecting.size(); j++){
          for(int k=0; k<is.connecting.size(); k++){
            if(j != k){
              Coordinate c0 = segments0.get(j).intersection(segments1.get(k));
              Coordinate c1 = segments1.get(j).intersection(segments0.get(k));
              if(c0 != null){
                double dist = c0.distance(is.pos);
               
                if(dist>extrusion[j]){
                  extrusion[j] = dist;
                  log.log("dist: "+dist+" other");
                }
              }
             
              if(c1 != null){
                double dist = c1.distance(is.pos);
               
                if(dist>extrusion[j]){
                  extrusion[j] = dist;
                }
              }
             
            }
          }
          if(extrusion[j] < maxRadius) extrusion[j] = maxRadius;
          for(int k=0; k<is.connecting.size(); k++){
            if(is.connecting.get(k).a == is){
              is.connecting.get(k).roadExtrusionA = extrusion[k];
            }else{
              is.connecting.get(k).roadExtrusionB = extrusion[k];
            }
          }
        }
        //create final road extrusion
       
        LineSegment[] segments = new LineSegment[is.connecting.size()];
        for(int j=0; j<is.connecting.size(); j++){
          Road r = is.connecting.get(j);
          double radius = r.width/2; //maybe a tad faster to load into variable?
          Turtle t0;
          if(r.a.pos.equals(is.pos)){
            t0 = new Turtle(is.pos, Math.toDegrees(Angle.angle(is.pos, r.b.pos)));
          }else{
            t0 = new Turtle(is.pos, Math.toDegrees(Angle.angle(is.pos, r.a.pos)));
          }
         
          //move out from intersection and split into road width
          t0.move(extrusion[j]);
          t0.turn(90);
          Turtle t1 = new Turtle(t0.pos, t0.angle-180);
          t0.move(radius);
          t1.move(radius);
         
          segments[j] = new LineSegment(t0.pos, t1.pos);
        }
        //need to sort segments by angle order, then use that to generate shape. Convex hull will not work.
       
View Full Code Here

   
    Coordinate[] coords = new Coordinate[7];
   
    double ang = Math.toDegrees(Angle.angle(a.pos, b.pos));
   
    Turtle ta = new Turtle(a.pos, ang);
    ta.move(minimumRoadLength*.9);
    coords[0] = new Coordinate(ta.pos); //start point
    coords[6] = coords[0]; //first element is also last
    ta.turn(collisionGeometryAngle);
    ta.move(length);
    coords[1] = new Coordinate(ta.pos);
    ta.angle = ang - 90;
    ta.move(collisionGeometryWidth);
    coords[5] = new Coordinate(ta.pos);
   
    Turtle tb = new Turtle(b.pos, ang+180);
    tb.move(minimumRoadLength*.9);
    coords[3] = new Coordinate(tb.pos); //end point
    tb.turn(collisionGeometryAngle);
    tb.move(length);
    coords[4] = new Coordinate(tb.pos);
    tb.angle = ang - 90;
    tb.move(collisionGeometryWidth);
    coords[2] = new Coordinate(tb.pos);
   
    Polygon p = gf.createPolygon(gf.createLinearRing(coords), null);
   
    return p;
View Full Code Here

    float previousAngle = (float)Math.toDegrees(Angle.angle(road.a.pos, road.b.pos));
    double nextRoadLength = 64;
    //System.out.println(nextRoadLength);
    if(road.getType() == RoadType.HIGHWAY || road.getType() == RoadType.BRIDGE){
      RoadType nextRoadType = RoadType.STREET;
      Turtle t = new Turtle(road.b.pos, 0);
      float angle = 0;

      t = new Turtle(road.b.pos, 0);
      double roadLength = nextRoadLength;
      switch(d){
      case LEFT: //left
        angle = 90+previousAngle;//RandomHelper.random(city.random.nextFloat(), 50, 20);
        roadLength = nextRoadLength;
        break;
      case FORWARD: //forward
        angle = previousAngle;
        roadLength = nextRoadLength;
        break;
      case RIGHT: //right
        angle = 270+previousAngle;//RandomHelper.random(city.random.nextFloat(), -20, -50);
        roadLength = nextRoadLength;
        break;
      case BACKWARD: //backward
        angle = 180+previousAngle;
        roadLength = nextRoadLength;
        break;
      default:
        //invalid direction
        break;
      }

      t.angle = angle;
      t.move((float)roadLength);
     
      returnRoad = new Road(road.b, new Intersection(new Coordinate(t.pos)), nextRoadType, new Basic(c), road);
    }
    return returnRoad;
  }
View Full Code Here


    //ramp forward
    //left 50 to 20, forward 20 to -20, right -20 to -50
    RoadType nextRoadType = RoadType.DEFAULT;
    Turtle t = new Turtle(road.b.pos, 0);
    float angle = 0;
    float bestPopulation = 0;
    Coordinate bestPosition = null;
    for(int i = 0;i<numberTests ;i++){
      t = new Turtle(road.b.pos, 0);
      double roadLength = nextRoadLength;
      switch(d){
      case LEFT: //left
        angle = RandomHelper.random(city.random.nextFloat(), turnRateLeftRight, -turnRateLeftRight)+previousAngle+90;
        nextRoadType = RoadType.MAIN;
        roadLength = nextRoadLengthStreet;
        break;
      case FORWARD: //forward
        angle = RandomHelper.random(city.random.nextFloat(), turnRateForward, -turnRateForward)+previousAngle;
        nextRoadType = RoadType.HIGHWAY;
        roadLength = nextRoadLength;//Math.abs(Math.cos(Math.toRadians((previousAngle-angle)%360))*nextRoadLength); //sin approximates how long next road should be
        break;
      case RIGHT: //right
        angle = RandomHelper.random(city.random.nextFloat(), turnRateLeftRight, -turnRateLeftRight)+previousAngle+270;
        nextRoadType = RoadType.MAIN;
        roadLength = nextRoadLengthStreet;
        break;
      case BACKWARD: //backward
        angle = -RandomHelper.random(city.random.nextFloat(), turnRateForward, -turnRateForward)+previousAngle;
        nextRoadType = RoadType.HIGHWAY;
        roadLength = nextRoadLength;
        break;
      default:
        //invalid direction
        break;
      }

      t.angle = angle;
      t.move((float)roadLength);
      float population = city.pop.get((int)t.pos.x, (int)t.pos.y);
      if(population>=bestPopulation ){ //&& water < .7
        bestPopulation = population;
        bestPosition = new Coordinate(t.pos);
      }
    }
    if(bestPosition == null){
      //same as forward
      t = new Turtle(road.b.pos, 0);
      angle = RandomHelper.random(city.random.nextFloat(), 20, -20);
      nextRoadType = RoadType.HIGHWAY;
      double roadLength = Math.abs(Math.sin(Math.toRadians((previousAngle-angle)%360))*nextRoadLength); //sin approximates how long next road should be
      t.angle = angle;
      t.move((float)roadLength);
      returnRoad = new Road(road.b, new Intersection(new Coordinate(t.pos)), nextRoadType, this, road); //roads set to default should die.
    }else{
      returnRoad = new Road(road.b, new Intersection(bestPosition), nextRoadType, this, road); //roads set to default should die.
    }
    return returnRoad;
View Full Code Here

  }
  @Override
  public Road globalGoals(City city, Road road, Direction d) {
    double previousAngle = Math.toDegrees(Angle.angle(road.a.pos, road.b.pos));
    Road r = new Road(road.b, new Intersection(road.b.pos), RoadType.STREET, this, road);
    Turtle t;
    if(road.getType() == RoadType.HIGHWAY){// || road.type == RoadType.MAIN){
      t = new Turtle(r.a.pos, previousAngle);
    }else{
      double angle = (Math.floor((previousAngle+45)/90)*90+direction);
      t = new Turtle(r.a.pos, angle);//+((city.random.nextDouble()-.5)*20));
    }
    switch(d){
    case FORWARD:{
      t.move(roadLength(t.angle));
      r.b.pos = t.pos;
      return r;
    }
    case BACKWARD:{
      t.move(-roadLength(t.angle));
      r.b.pos = t.pos;
      return r;
    }
    case LEFT:{
      t.turn(90);
      t.move(-roadLength(t.angle));
      r.b.pos = t.pos;
      return r;
    }
    case RIGHT:{
      t.turn(90);
      t.move(roadLength(t.angle));
      r.b.pos = t.pos;
      return r;
    }
    default:{
      return null;
View Full Code Here

TOP

Related Classes of wolf.util.Turtle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.