I just need to make this code working on p5.js as my code isn't really functioning

Viewed 39
  1. just need to edit this code to make it working

  2. I think I placed the coords in the wrong section so please assist if possible.

    let loadTSP;
    let loadSol;
    let City = new Array();
    citySize = 12;
    let minX, maxX, minY, maxY;
    let mulX,mulY;

    var myData = [{id: [0]},{xCords: [1]},{yCords: [2]}];
    function preload() {
      loadTSP = loadStrings("TSP_EUC_Problems/berlin52.tsp");
      // loadTSP = loadStrings("TSP_EUC_Problems/a280.tsp"); 
      // loadTSP = loadStrings("TSP_EUC_Problems/ch150.tsp"); 
      // loadSol = loadSol(solutionFileName);
      // loadSol = loadStrings(solutionFileName);
    }

    function setup() {
      createCanvas(windowWidth, windowHeight);
      background(255, 200, 200);


      coords = new Array(myData.length);
      showLoadedTSP();
      showSolution();
      coords[i].x = map(coords[i].x,minX,maxX,0,width);
      coords[i].y = map(coords[i].y,minY,maxY,0,height);
    //   minX = myData[i][1], myData[i][2];
    //   maxX = myData[i][1], myData[i][2];
    //   minY = myData[i][1], myData[i][2];
    //   maxY = myData[i][1], myData[i][2];



    //   if (coords[i].x > maxX) {
    //     maxX = coords[i].x
    //   }
    //   if (coords[i].x < minX) {
    //     minX = coords[i].x
    //   }
    //   if (coords[i].y > maxY) {
    //     maxY = coords[i].y
    //   }
    //   if (coords[i].y < minY) {
    //     minY = coords[i].y
    //   }
    // }
     
    // let coords = map(maxX, 0,maxY) 


    function showLoadedTSP() {
      loadTSP.splice(0, 6); // removes first 6 lines of file 
      loadTSP.splice(loadTSP.length - 1, 1)
      for (let i = 0; i < loadTSP.length; i++) { // loops through the length of the tsp file 
        myData[i] = split(loadTSP[i], ' ');  //
       
        if (myData[i].length > 3) { // if more than 3 parameters in file it removes excess 
          let voidSpaces = myData[i].length - 3;
          myData[i].splice(0, voidSpaces);
        
        }
        for(let i= 0; i < myData.length; i++){
          stroke(255);
          strokeWeight(2);
          fill("blue");
            ellipse(myData[i][1], myData[i][2], citySize); // draws the ellipse from the x, y coordinate
        } 
       // use map function to scale 


      }
      console.log(myData);
    }

    function showSolution() {

    }

    function draw() {

      // berlin52
      text("berlin52", 100,80);
      text("Berlin", 100,100);
      text("52 cities", 100,120);
    //ludwig a280
      // text("a280", 100,80);
      // text("Ludwig", 100,100);
      // text("280 cities", 100,120);

      // ch150
    // text("ch150", 100,80);
    //   text("churritz", 100,100);
    //   text("150 cities", 100,120);
    }
    }
0 Answers
Related