From 6477a32b4a98fec45723e355a4bab8756d6d0f16 Mon Sep 17 00:00:00 2001 From: hellekin Date: Wed, 25 Apr 2018 22:59:37 +0200 Subject: Woooojajajjaa --- assets/js/index.js | 131 ++++++++++++++++++----------------------------- assets/js/pedometer.js | 134 ++++++++++++++++++++++++++++--------------------- butterfly.svg | 41 +++++++++++++++ qw.html | 115 ------------------------------------------ qw3.html | 88 ++++++++++++++++++++++++++++++++ 5 files changed, 254 insertions(+), 255 deletions(-) create mode 100644 butterfly.svg delete mode 100644 qw.html create mode 100644 qw3.html diff --git a/assets/js/index.js b/assets/js/index.js index 5d5ade0..cbcf143 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,96 +1,61 @@ +var map, wingr,wingl,muscler, musclel, stringr, stringl, cavity, flight_path, flight_path_length, last_point, step; + +var prev_step = 0 +step = 0; +map = Snap('#left-bits'); +wingr = map.select('#wingr'); +wingrbbox = wingr.getBBox(); +wingl = map.select('#wingl'); +winglbbox = wingl.getBBox(); +musclel = map.select('#musclel'); +musclelbbox = musclel.getBBox(); +muscler = map.select('#muscler'); +musclerbbox = muscler.getBBox(); +stringl = map.select('#stringl'); +stringlbbox = stringl.getBBox(); +stringr = map.select('#stringr'); +stringrbbox = stringr.getBBox(); +cavity = map.select('#cavity'); +cavitybbox = cavity.getBBox(); +flight_path = map.select('#path'); +flight_path_l = Snap.path.getTotalLength(flight_path); +last_point = flight_path.getPointAtLength(flight_path_length); + +console.log('step', step, 'final', flight_path_l) + +function angle(n) { + return Math.random() * (n * 2) + n; +} - - - var map, wingr,wingl,muscler, musclel, stringr, stringl, cavity, flight_path, flight_path_length, last_point, step; - - // window.onload = function () { - - step = 0; - map = Snap('#left-bits'); - wingr = map.select('#wingr'); - wingrbbox = wingr.getBBox(); - wingl = map.select('#wingl'); - winglbbox = wingl.getBBox(); - musclel = map.select('#musclel'); - musclelbbox = musclel.getBBox(); - muscler = map.select('#muscler'); - musclerbbox = muscler.getBBox(); - stringl = map.select('#stringl'); - stringlbbox = stringl.getBBox(); - stringr = map.select('#stringr'); - stringrbbox = stringr.getBBox(); - cavity = map.select('#cavity'); - cavitybbox = cavity.getBBox(); - flight_path = map.select('#path'); - - - - flight_path_length = Snap.path.getTotalLength(flight_path); - -flight_path_length= flight_path_length/100 - - last_point = flight_path.getPointAtLength(flight_path_length); +let cb = function() { -console.log ('len'+ flight_path_length); + prev_step = step + step = step + parseInt(pas.innerHTML) * 10; + if (step > flight_path_l) prev_step = step = 0 + $('#pas').text(step) + $('#prev_step').text(prev_step) + $('#step').text(step) + $('#next_step').text(flight_path_l) - - let cb=function(){step=step+100; + console.log('pas', pas.innerHTML) - Snap.animate(step, flight_path_length, function() { -//console.log('pas'); - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); + Snap.animate(prev_step, step, function(val) { + //console.log('pas'); + step = val; + moveToPoint = Snap.path.getPointAtLength( flight_path, val ); x = moveToPoint.x ; y = moveToPoint.y ; -// console.log('animating ' + x + ' ' + y); + // console.log('animating ' + x + ' ' + y); wingr.transform('translate(' + x + ',' + y + ') '+', '+wingrbbox.cx+', '+wingrbbox.cy); - },5000, mina.easeout); - - - Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; wingl.transform('translate(' + x + ',' + y + ')' + (moveToPoint.alpha - 90)+', '+winglbbox.cx+', '+winglbbox.cy); - },5000, mina.easeout); - -Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; - cavity.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - 90)+', '+cavitybbox.cx+', '+cavitybbox.cy+')'); - },5000, mina.easeout); - -Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; - musclel.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - 90)+', '+musclelbbox.cx+', '+musclelbbox.cy+')'); - },5000, mina.easeout); - -Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; - muscler.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - 90)+', '+musclerbbox.cx+', '+musclerbbox.cy+')'); + cavity.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - angle(-10))+', '+cavitybbox.cx+', '+cavitybbox.cy+')'); + musclel.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - angle(20))+', '+musclelbbox.cx+', '+musclelbbox.cy+')'); + muscler.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - angle(30))+', '+musclerbbox.cx+', '+musclerbbox.cy+')'); + stringr.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - angle(-20))+', '+stringrbbox.cx+', '+stringrbbox.cy+')'); + stringl.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - angle(9))+', '+stringlbbox.cx+', '+stringlbbox.cy+')'); },5000, mina.easeout); - -Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; - stringr.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - 90)+', '+stringrbbox.cx+', '+stringrbbox.cy+')'); - },5000, mina.easeout); - -Snap.animate(step, flight_path_length, function() { - moveToPoint = Snap.path.getPointAtLength( flight_path, step ); - x = moveToPoint.x ; - y = moveToPoint.y ; - stringl.transform('translate(' + x + ',' + y + ') rotate('+ (moveToPoint.alpha - 90)+', '+stringlbbox.cx+', '+stringlbbox.cy+')'); - },5000, mina.easeout); - + } document.addEventListener("requestMove", cb,false); - - diff --git a/assets/js/pedometer.js b/assets/js/pedometer.js index 53079a9..af3d240 100644 --- a/assets/js/pedometer.js +++ b/assets/js/pedometer.js @@ -1,73 +1,93 @@ $(document).ready(function(){ -console.log("print"); + var has_accel = false -//on déclare l'ensemble des variables ax et ay sont les données d'acceleration, n c'est la norme, maxn et minn les valeurs max et min de la norme, et pas le nombre de pas -var n=0, maxn = 0, minn = 0, pas = 0, + $('#left-bits').css({ width: '50vw', height: '50vh', background: '#fff' }) + + console.log("-- ready --"); + + //on déclare l'ensemble des variables ax et ay sont les données d'acceleration, n c'est la norme, maxn et minn les valeurs max et min de la norme, et pas le nombre de pas + var n=0, maxn = 0, minn = 0, pas = 0, ax = 0, ay = 0, az = 0, pass=0; -//programme d'alberto desarullo qui va chercher les données de l'accelerometre -if (window.DeviceMotionEvent != undefined) { - window.ondevicemotion = function(e) { - ax = event.accelerationIncludingGravity.x ; - ay = event.accelerationIncludingGravity.y ; - az = event.accelerationIncludingGravity.z ; -// et les affiche dans la page html - document.getElementById("accelerationX").innerHTML = e.accelerationIncludingGravity.x; - document.getElementById("accelerationY").innerHTML = e.accelerationIncludingGravity.y; - document.getElementById("accelerationZ").innerHTML = e.accelerationIncludingGravity.z; -// on affiche également la norme sa valeur max et le nombre de pas - document.getElementById("n").innerHTML = n; - document.getElementById("pas").innerHTML = pas; - document.getElementById("maxn").innerHTML = maxn; - - } - + function report_status() { +// console.log('ax', ax, 'ay', ay, 'az', az) + // et les affiche dans la page html + document.getElementById("accelerationX").innerHTML = ax; + document.getElementById("accelerationY").innerHTML = ay; + document.getElementById("accelerationZ").innerHTML = az; + // on affiche également la norme sa valeur max et le nombre de pas + document.getElementById("n").innerHTML = n; + document.getElementById("pas").innerHTML = pas; + document.getElementById("maxn").innerHTML = maxn; + } - var ev = new Event("requestMove"); + function odmHandler(e) { - function pollAccelerometer() { - setInterval( function() { - - // on calcule la norme c'est à dire la taille du vecteur qui est défini par les points d'accélération ax ay et az - n0 = n; - n=Math.sqrt (ax*ax + ay*ay + az*az); - // console.log(n); - - //on calcule un min et max pour la norme - if (n < n0) { minn = n ; - }else if (n > n0) { maxn = n ; - } - - // console.log(maxn); + has_accel = true + + ax = event.accelerationIncludingGravity.x ; + ay = event.accelerationIncludingGravity.y ; + az = event.accelerationIncludingGravity.z ; + + report_status() + } - //on défini un seuil qui correspond à un pas - if ((maxn - minn) > 10) {pas = pas+1; - - } + function fakeAccel() { + var min = -12, max = 12 + return Math.random() * (max - min) + min; + } + + function mockAccelerometer() { + + has_accel = false + ax = fakeAccel() + ay = fakeAccel() + az = fakeAccel() + + report_status() + } - if (pas>10) { - // console.log(pas); - document.dispatchEvent(ev); - } - pas++; - // on vérifie cela chaque 250 milisecondes - }, 350); + function accel_norm(ax, ay, az) { + return Math.sqrt (ax*ax + ay*ay + az*az); } -//function mockAccelerometer() { -// setInterval( function() { -// console.log(pas); -// if (pas===100) { -// document.dispatchEvent(ev); -// } -// pas++; -// },1000); -//} + //programme d'alberto desarullo qui va chercher les données de l'accelerometre + if (window.DeviceMotionEvent != undefined) { + window.ondevicemotion = odmHandler + var ev = new Event("requestMove"); + + function pollAccelerometer() { + setInterval(makeStep, 250) + } + + function makeStep() { + if (!has_accel) { + mockAccelerometer() + } + // on calcule la norme c'est à dire la taille du + // vecteur qui est défini par les points + // d'accélération ax ay et az + n0 = n; + n = accel_norm(ax,ay,az) + + // on calcule un min et max pour la norme + if (n < n0) { + minn = n ; + } else if (n > n0) { + maxn = n ; + } + + // on définit un seuil qui correspond à un pas + if ((maxn - minn) > 10) { + pas = pas+1; + document.dispatchEvent(ev); + } + } -pollAccelerometer(); -} + pollAccelerometer(); + } }); diff --git a/butterfly.svg b/butterfly.svg new file mode 100644 index 0000000..b94a903 --- /dev/null +++ b/butterfly.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + diff --git a/qw.html b/qw.html deleted file mode 100644 index a8ea433..0000000 --- a/qw.html +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - -
- - - - - - - - image/svg+xml - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - diff --git a/qw3.html b/qw3.html new file mode 100644 index 0000000..f29a8ef --- /dev/null +++ b/qw3.html @@ -0,0 +1,88 @@ + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + -- cgit v1.2.3