From 0281d19f1038ee5b77f6b081148d882e474b70ec Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 26 Mar 2019 12:52:23 +0100 Subject: [PATCH] Adds UI, magazine visualisation and forklift This commit adds the prototype of user interface, canvas on which magazine is drawn and forklift class. --- SZI1/__pycache__/settings.cpython-37.pyc | Bin 2236 -> 2326 bytes SZI1/settings.py | 5 + magazine/__pycache__/admin.cpython-37.pyc | Bin 0 -> 185 bytes magazine/__pycache__/models.cpython-37.pyc | Bin 0 -> 182 bytes magazine/__pycache__/urls.cpython-37.pyc | Bin 273 -> 398 bytes magazine/__pycache__/views.cpython-37.pyc | Bin 355 -> 563 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 155 bytes magazine/models.py | 3 - magazine/static/magazine/forklift.js | 53 +++++++++++ magazine/static/magazine/sketch.js | 86 ++++++++++++++++++ magazine/static/magazine/style.css | 3 + magazine/templates/magazine/index.html | 77 ++++++++++++++++ magazine/urls.py | 4 +- magazine/views.py | 8 ++ 14 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 magazine/__pycache__/admin.cpython-37.pyc create mode 100644 magazine/__pycache__/models.cpython-37.pyc create mode 100644 magazine/migrations/__pycache__/__init__.cpython-37.pyc delete mode 100644 magazine/models.py create mode 100644 magazine/static/magazine/forklift.js create mode 100644 magazine/static/magazine/sketch.js create mode 100644 magazine/static/magazine/style.css create mode 100644 magazine/templates/magazine/index.html diff --git a/SZI1/__pycache__/settings.cpython-37.pyc b/SZI1/__pycache__/settings.cpython-37.pyc index 268ef67b5ea2aa5e82a48fc2a0d96b5ebde4d862..b75e1d982099c5f32483313eae4df16e7f1ca02d 100644 GIT binary patch delta 333 zcmX|-&q@MO6vpRXZ#s;Q&W!&{Yx<{65k5m&!hkEsAP#{@pIj!Wg-HuHt$F|vg1|*C zTZY@7q$lVFYFigY51bz#KMrT{ecCUMSvO5XQ&T^Ey?!2>MfN?eHl7fdF*1;Vi6m06 zV8c-+jx;5Zks1WD$RUpcic*9On^Pefnb@KvN+|c)Eq_b(qu8Et>`Zyc$bySqb?IVn z!TkjfLM8>-I3x!ZN<&aa?MYT4w|-Kc@pV3$amgtUj|$*{<{f|h{xO5}yPoWg!u$UG zhYL}m=)o@bbJp=2O}}*!bkF^E@MSDb_p;r3*9NX? eXW&lCy6;@6D7YRe#Y9AK5#?<1s5eD|S&@IRb5jTa delta 231 zcmbOxv`3KFiIYGIv|1)luWoBXFsp8NtE=erOOxD+w*zC^E!YINO9O4+_=^P&#g`kf<-T8#MlGr#~=<2Faa43KwK;UBvKes7;_kM8KW2(8B&;n88n$+0!0}# z8E>&BrsQVk`Drpm@ug%X=B4NBCFkdr6lEqAfecv5P{a(Rz{D>z{m|mnqGJ85#N_-W zeV6>?(%jU%l4AXUqWrAXWFR9r%F|FkH!(f2Dl;!tA8fE*LFFwDo80`A(wtN~Mxar} HK+FID`IRk{ literal 0 HcmV?d00001 diff --git a/magazine/__pycache__/models.cpython-37.pyc b/magazine/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ec69abaa0dfc383a308c06a843e178b5d0909a35 GIT binary patch literal 182 zcmZ?b<>g`kf<-T8#8?99#~=<2Faa43KwK;UBvKes7;_kM8KW2(8B&;n88n$+0!0}# z8E>)W=BK3Q6#Hp1-QrBiO3X{o*Gow%0%=~!P{abHz{D?e{m|mnqGJ85#N_-WeV6>? z(%jU%l4AXUqWrAXWFR9r%F|FkH!(f2Dl;!tA7ZFpLFFwD8z8$hC)JJ-XjU;0GXMa5 C94y!X literal 0 HcmV?d00001 diff --git a/magazine/__pycache__/urls.cpython-37.pyc b/magazine/__pycache__/urls.cpython-37.pyc index ca0aa14791dd6db6c7faed61ede57b3da270b97a..49513de235b0cf46e31bf3ccd5baedba83dc8c08 100644 GIT binary patch literal 398 zcmX|6y-ve05Vqr{O@AUG!8@QVi5S=rLWl(hgj8UNkSY@&X(HRH>;!06<~{(Az$IxeZXDFQIyYIW7&*#%P9uc(9{nxt>jPIWOSs%d(UVDK~5J4qTG^f<#Kn9BC3^5Zu z*;8R2QUX+j!0Nu}i@}<{1jr)@>w$>GaLvjfkHlz7lJN%hNJ3q2!P_~;$u+2ja6 zc1Btgpl-gm&HRX`C1@~JVHlQ-|E>wqxdFE`-(Vuo#yE|OwqUecHa2#|hGaGfSOjnrERV76wbyt$-J4D z_vUjGcki-D(+D`y&vT=>z8(38}_ zP1cZwBhNsF*58-IcElf%$6B3w3s%-0sdF}Gy(?R_$^sixQ+CxZKN#H`kNw8oH@<^_ a!N#ocvO$@ye}Qp-o9HpcW#~K!CgKZIkS&t{ diff --git a/magazine/__pycache__/views.cpython-37.pyc b/magazine/__pycache__/views.cpython-37.pyc index 399f9dc4ef6035b5c8075021d316d8566af123e4..d8cabd271f3cb1dc9a7a765706164e6c6810797f 100644 GIT binary patch literal 563 zcmY+Ay-veG49D;C)r11#0T^J+(g-0jA%uVdmI_g^Lzd4_WlydDVb!szDy2uKC7TMlpLd;K+a;69&IF5c9lI8H6*tM+|giq-}nV{&h3rJ&KDBx z^nY9)7h0}m7DgEP>O6|Kj!q6^w?%5a3F*4=N}VaD^!aHE)`cFYO_-M%Q8B)^eY$B5 z_F2bKx}qjoeWeFdD9ANtMk5XES<#|mWP{zJZT^SC Z9tt~@?Mkaz2|M=gWVc_G{5hc?df%Scdny0` delta 169 zcmdnY@|Y>WiIt$!Q+ diff --git a/magazine/migrations/__pycache__/__init__.cpython-37.pyc b/magazine/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8dff860fbe80f104c173f5ec169e43f1ca6be6fb GIT binary patch literal 155 zcmZ?b<>g`kf<-T8#DM6>AOZ#$feZ&AE@lA|DGb33nv8xc8Hzx{2;!HEerR!OQL%nj zVsd_xzDs^`X>Mv>NwI!FQGQlxGLR7*U5HkP(y0a$1 literal 0 HcmV?d00001 diff --git a/magazine/models.py b/magazine/models.py deleted file mode 100644 index 71a8362..0000000 --- a/magazine/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/magazine/static/magazine/forklift.js b/magazine/static/magazine/forklift.js new file mode 100644 index 0000000..fee6151 --- /dev/null +++ b/magazine/static/magazine/forklift.js @@ -0,0 +1,53 @@ +class Forklift { + constructor(x, y) { + this.positoin = createVector(x, y); + this.speed = 5; + this.path = []; + this.currentTarget = ''; + this.targetId = 0; + this.velocity = createVector(0, 0); + this.direction = createVector(0, 0); + this.end = false; + } + + draw() { + fill(225, 255, 0); + ellipse(this.positoin.x, this.positoin.y, 20); + } + + setPath(path) { + this.path = path; + this.currentTarget = this.path[this.targetId]; + this.setVelocity(); + } + + nextTarget() { + this.targetId += 1; + if (this.targetId < this.path.length) { + this.currentTarget = this.path[this.targetId]; + } else { + this.end = true; + } + } + + targetReached() { + return this.end; + } + + setVelocity() { + this.direction = p5.Vector.sub( + sections[this.currentTarget], + this.positoin + ); + this.velocity = this.direction.setMag(this.speed); + } + + move() { + this.positoin = p5.Vector.add(this.positoin, this.velocity); + debugger; + if (this.positoin.equals(sections[this.currentTarget])) { + this.nextTarget(); + this.setVelocity(); + } + } +} diff --git a/magazine/static/magazine/sketch.js b/magazine/static/magazine/sketch.js new file mode 100644 index 0000000..ebb1597 --- /dev/null +++ b/magazine/static/magazine/sketch.js @@ -0,0 +1,86 @@ +let sections; +let roads; +let packageClaim; +let going = false; +let forklift; + +function setup() { + createCanvas(500, 500).parent('canvas'); + frameRate(30); + + createMagazineLayout(); + + select('#button').mousePressed(deliver); + + forklift = new Forklift(sections['START'].x, sections['START'].y); +} + +function draw() { + background(64); + drawMagazine(); + forklift.draw(); + if (going) { + if (forklift.targetReached()) { + going = false; + } else { + forklift.move(); + } + } +} + +function drawMagazine() { + noFill(); + stroke(220); + strokeWeight(10); + for (let road of roads) { + line( + sections[road[0]].x, + sections[road[0]].y, + sections[road[1]].x, + sections[road[1]].y + ); + } + noStroke(); + textAlign(CENTER, CENTER); + for (let section of Object.keys(sections)) { + if (section === 'START') { + fill(80); + rect(sections[section].x - 15, sections[section].y, 30, 30); + } else { + fill(30); + ellipse(sections[section].x, sections[section].y, 30); + fill(255); + text(section, sections[section].x, sections[section].y); + } + } +} + +function deliver() { + path = ['B', 'A', 'D', 'E', 'F']; + forklift.setPath(path); + going = true; +} + +function createMagazineLayout() { + unit = width / 5; + + sections = { + START: { x: unit * 2, y: 0 }, + A: createVector(unit, unit), + B: createVector(2 * unit, unit), + C: createVector(2 * unit, 2 * unit), + D: createVector(unit, 2 * unit), + E: createVector(unit, 3 * unit), + F: createVector(2 * unit, 3 * unit) + }; + roads = [ + ['START', 'B'], + ['A', 'B'], + ['A', 'E'], + ['E', 'D'], + ['E', 'F'], + ['D', 'C'], + ['B', 'C'], + ['C', 'F'] + ]; +} diff --git a/magazine/static/magazine/style.css b/magazine/static/magazine/style.css new file mode 100644 index 0000000..24dbbbd --- /dev/null +++ b/magazine/static/magazine/style.css @@ -0,0 +1,3 @@ +body { + background-color: rgb(109, 61, 61); +} diff --git a/magazine/templates/magazine/index.html b/magazine/templates/magazine/index.html new file mode 100644 index 0000000..6136c2a --- /dev/null +++ b/magazine/templates/magazine/index.html @@ -0,0 +1,77 @@ + + +{% load static %} + + + + + + + + +
+
+

Package description

+ + + + + + + + + + + + + + +
+ Hard + Soft +
+ +
+
+
+

Sections

+

A - Cartons

+

B - Barrels

+

C - Plastic boxes

+

D - ______

+

E - ______

+

F - ______

+

G - ______

+
+
+ + \ No newline at end of file diff --git a/magazine/urls.py b/magazine/urls.py index 97d2641..5da255f 100644 --- a/magazine/urls.py +++ b/magazine/urls.py @@ -1,6 +1,8 @@ from django.urls import path +from django.views.generic import TemplateView from . import views urlpatterns = [ - path('', views.index, name='index') + path('', TemplateView.as_view(template_name='magazine/index.html')), + path('classify', views.classify, name='classify'), ] diff --git a/magazine/views.py b/magazine/views.py index c3a67a8..5961bd5 100644 --- a/magazine/views.py +++ b/magazine/views.py @@ -1,8 +1,16 @@ from django.shortcuts import render from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt + +import json # Create your views here. def index(request): return HttpResponse('It lives!') + + +@csrf_exempt +def classify(request): + return HttpResponse(json.load(request))