use mouse wheel and move to click different areas of the map
xxxxxxxxxx
let weavingDraft;
const w = 700;
const h = 700;
const nbThreads = 64;
const nbOfShafts = 4;
const nbTieups = 4;
const cellSize = w / (nbThreads + nbTieups + 3); // Because 3 gutters
const padding = cellSize;
const gps = [61.235148, 21.481852]; // Onkalo
const lengthDraw = Math.round((h - ((nbTieups + 3) * cellSize)) / cellSize);
function setup() {
const canvas = createCanvas(w, h);
canvas.parent('canvas-container');
weavingDraft = new WeavingDraft(nbThreads, nbTieups, lengthDraw, cellSize);
loadCoordinates(gps);
weavingDraft.draw();
initMap();
describe('An clickable world map on the right and the corresponding weaving pattern on the left. The weaving pattern is calculated at every click of the mouse on the map, using the lattitude and longitude of each coordinate', FALLBACK)
}
function mousePressed() {
weavingDraft.mousePressed(mouseX, mouseY);
weavingDraft.draw();
}
function loadCoordinates(gps) {
const latitude = fixlat(gps[0]);
const longitude = fixlong(gps[1]);
const latWithoutDecimals = removeDecimals(latitude);
const longWithoutDecimals = removeDecimals(longitude);
const latStr = latWithoutDecimals.toString();
const longStr = longWithoutDecimals.toString();
const latBase4 = toBaseN(latWithoutDecimals, nbOfShafts);
const longBase4 = toBaseN(longWithoutDecimals, nbOfShafts);
latitude2Thread(latBase4);
longitude2Tread(longBase4);
straightTieUp();
weavingDraft.updateDrawdown();
}
function latitude2Thread(l) {
const mirror = [l].reverse();
const lat = [l, mirror];
console.log(lat)
for (let i = 0; i < nbOfShafts; i++) {
for (let j = 0; j < nbThreads; j++) {
const baseNDigit = lat[j % lat.length];
weavingDraft.threading.cells[j][i] = (i === baseNDigit);
}
}
}
function longitude2Tread(l) {
const mirror = [l].reverse();
const long = [l, mirror];
console.log(long)
for (let i = 0; i < nbTieups; i++) {
for (let j = 0; j < nbThreads; j++) {
const baseNDigit = long[j % long.length];
weavingDraft.treadling.cells[i][j] = (i === baseNDigit);
}
}
}
function straightTieUp() {
for (let i = 0; i < nbTieups; i++) {
for (let j = 0; j < nbTieups; j++) {
weavingDraft.tieup.cells[i][j] = (i === j);
}
}
}
function initMap() {
// Load the map
const map = L.map('map').setView(gps, 10);
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/{style}/MapServer/tile/{z}/{y}/{x}', {
style: 'World_Street_Map',
}).addTo(map);
// Add a map click function to load the coordinates in p5.js
map.on('click', e => {
const {adjustedLatitude, adjustedLongitude} = adjustCoordinatesPrecision(e.latlng.lat, e.latlng.lng);
console.log('Lat, Lon : ' + adjustedLatitude + ', ' + adjustedLongitude);
const gps = [adjustedLatitude, adjustedLongitude];
loadCoordinates(gps);
weavingDraft.draw();
});
}
function toBaseN(number, base) {
return number.toString(base).split('').map(digit => parseInt(digit, base));
}
function adjustCoordinatesPrecision(latitude, longitude) {
const adjustedLatitude = parseFloat(latitude.toFixed(6));
const adjustedLongitude = parseFloat(longitude.toFixed(6));
return {adjustedLatitude, adjustedLongitude};
}
function fixlat(lat) {
return map(lat, -90, 90, 0, 180);
}
function fixlong(long) {
return map(long, -180, 180, 0, 360);
}
function removeDecimals(coord) {
return round(coord * 10000000);
}