diff --git a/SZI1/__pycache__/__init__.cpython-37.pyc b/SZI1/__pycache__/__init__.cpython-37.pyc index 3b07cb9..290e05d 100644 Binary files a/SZI1/__pycache__/__init__.cpython-37.pyc and b/SZI1/__pycache__/__init__.cpython-37.pyc differ diff --git a/SZI1/__pycache__/settings.cpython-37.pyc b/SZI1/__pycache__/settings.cpython-37.pyc index a931efc..19ca5f0 100644 Binary files a/SZI1/__pycache__/settings.cpython-37.pyc and b/SZI1/__pycache__/settings.cpython-37.pyc differ diff --git a/SZI1/__pycache__/urls.cpython-37.pyc b/SZI1/__pycache__/urls.cpython-37.pyc index c9fa243..fcabce6 100644 Binary files a/SZI1/__pycache__/urls.cpython-37.pyc and b/SZI1/__pycache__/urls.cpython-37.pyc differ diff --git a/SZI1/__pycache__/wsgi.cpython-37.pyc b/SZI1/__pycache__/wsgi.cpython-37.pyc index f66d466..07660ed 100644 Binary files a/SZI1/__pycache__/wsgi.cpython-37.pyc and b/SZI1/__pycache__/wsgi.cpython-37.pyc differ diff --git a/magazine/__pycache__/__init__.cpython-37.pyc b/magazine/__pycache__/__init__.cpython-37.pyc index 1352577..9cfab94 100644 Binary files a/magazine/__pycache__/__init__.cpython-37.pyc and b/magazine/__pycache__/__init__.cpython-37.pyc differ diff --git a/magazine/__pycache__/admin.cpython-37.pyc b/magazine/__pycache__/admin.cpython-37.pyc index 5bb16c7..576760e 100644 Binary files a/magazine/__pycache__/admin.cpython-37.pyc and b/magazine/__pycache__/admin.cpython-37.pyc differ diff --git a/magazine/__pycache__/urls.cpython-37.pyc b/magazine/__pycache__/urls.cpython-37.pyc index fd782af..60a76da 100644 Binary files a/magazine/__pycache__/urls.cpython-37.pyc and b/magazine/__pycache__/urls.cpython-37.pyc differ diff --git a/magazine/__pycache__/views.cpython-37.pyc b/magazine/__pycache__/views.cpython-37.pyc index 442ad0b..57eb524 100644 Binary files a/magazine/__pycache__/views.cpython-37.pyc and b/magazine/__pycache__/views.cpython-37.pyc differ diff --git a/magazine/migrations/__pycache__/__init__.cpython-37.pyc b/magazine/migrations/__pycache__/__init__.cpython-37.pyc index dcd28c4..8dff860 100644 Binary files a/magazine/migrations/__pycache__/__init__.cpython-37.pyc and b/magazine/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/magazine/static/magazine/forklift.js b/magazine/static/magazine/forklift.js index 80a7d62..dfe9c57 100644 --- a/magazine/static/magazine/forklift.js +++ b/magazine/static/magazine/forklift.js @@ -39,24 +39,30 @@ class Forklift { } setVelocity() { - p5.Vector.sub( - sections[this.currentTarget], - this.positoin, - this.direction - ); + debugger; + this.direction = this.sub(sections[this.currentTarget], this.positoin); this.velocity = this.direction.setMag(this.speed); } move() { - this.positoin = p5.Vector.add(this.positoin, this.velocity); + this.positoin = this.add(this.positoin, this.velocity); if ( Math.abs(this.positoin.x - sections[this.currentTarget].x) <= this.speed && Math.abs(this.positoin.y - sections[this.currentTarget].y) <= this.speed ) { + this.positoin = sections[this.currentTarget]; this.nextTarget(); this.setVelocity(); } } + + sub(target, pos) { + return createVector(target.x - pos.x, target.y - pos.y); + } + + add(target, pos) { + return createVector(target.x + pos.x, target.y + pos.y); + } } diff --git a/magazine/static/magazine/sketch.js b/magazine/static/magazine/sketch.js index b1f65d1..45ab43c 100644 --- a/magazine/static/magazine/sketch.js +++ b/magazine/static/magazine/sketch.js @@ -8,7 +8,7 @@ let target; // This runs once at start function setup() { - createCanvas(500, 500).parent('canvas'); + createCanvas(600, 600).parent('canvas'); frameRate(30); @@ -44,7 +44,7 @@ function drawMagazine() { sections[road[0]].x, sections[road[0]].y, sections[road[1]].x, - sections[road[1]].y + sections[road[1]].y, ); } noStroke(); @@ -67,7 +67,7 @@ function deliver() { let data = { graph: magazineToGraph(), start_node: forklift.currentSection, - dest_node: int(target.value()) + dest_node: int(target.value()), }; httpPost( 'http://localhost:8000/shortestPath', @@ -80,21 +80,21 @@ function deliver() { }, error => { console.log(error); - } + }, ); } function createMagazineLayout() { - unit = width / 5; + unit = width / 6; sections = { - 0: { x: unit * 2, y: 0 }, - 1: createVector(unit, unit), - 2: createVector(unit, 2 * unit), - 3: createVector(unit, 3 * unit), - 4: createVector(3 * unit, unit), - 5: createVector(3 * unit, 2 * unit), - 6: createVector(3 * unit, 3 * unit) + 0: { x: 2 * unit, y: unit }, + 1: createVector(unit, 2 * unit), + 2: createVector(unit, 3 * unit), + 3: createVector(unit, 4 * unit), + 4: createVector(3 * unit, 2 * unit), + 5: createVector(3 * unit, 3 * unit), + 6: createVector(3 * unit, 4 * unit), }; roads = [ [1, 5], @@ -105,7 +105,7 @@ function createMagazineLayout() { [5, 6], [3, 6], [4, 2], - [5, 3] + [5, 3], ]; } @@ -119,11 +119,11 @@ function magazineToGraph() { end = road[1]; graph[start][end] = Math.sqrt( Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2) + Math.pow(sections[start].y - sections[end].y, 2), ); graph[end][start] = Math.sqrt( Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2) + Math.pow(sections[start].y - sections[end].y, 2), ); } return graph; diff --git a/magazine/views.py b/magazine/views.py index 30bba36..aaac5f9 100644 --- a/magazine/views.py +++ b/magazine/views.py @@ -20,7 +20,6 @@ def classify(request): @csrf_exempt def shortestPath(request): loaded_request = json.load(request) - print(loaded_request) graph = loaded_request["graph"] graph = {int(k): v for k, v in graph.items()} @@ -62,4 +61,4 @@ def shortestPath(request): current = predecessor[current] path[node] = p[::-1] - return HttpResponse(path[dest_node]) + return HttpResponse(path[dest_node][1:])