From 51b09204736abcf82fc7cd0d707de7b71b2c7e7c Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Tue, 13 Dec 2022 10:28:54 +0800 Subject: [PATCH 01/15] learned and finished day01 --- 01 - JavaScript Drum Kit/index-START.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index c771dea..66f0dc0 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,6 +58,23 @@ From 37d7e445470aac535f37792352b02bf3c8b69bee Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Wed, 14 Dec 2022 11:10:35 +0800 Subject: [PATCH 02/15] learned and finished day02 --- 02 - JS + CSS Clock/index-START.html | 98 ++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384..15e9c9c 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -61,13 +61,111 @@ background:black; position: absolute; top:50%; + right: 50%; /*as the length of each pointer are different, need to set this style to let thier end of the right side in same position*/ + transform: rotate(90deg); /*pointers start horizontally -> vertically */ + transform-origin: 100%; /* set rotate center to the right end of pointers */ + + /*for the transform of the first loading*/ + transition-timing-function: cubic-bezier(0.9, 0.54, 0.26, 1.68); /*specify the speed of the switching effect */ + } + + .clock-face:after { + width: 1em; + height: 1em; + left: 50%; + top: 50%; + position: absolute; + display: block; + content: ''; + background-color: black; + border-radius: 50%; + transform: translate(-50%, -50%); + } + + .hour-hand { + width: 40%; + border-bottom-left-radius: .5rem; + border-top-left-radius: .5rem; + transition: all 3s; + } + + .min-hand { + width: 45%; + height: 4px; + transition: all 0.1s; + } + + .second-hand { + height: 2px; + border-bottom-left-radius: 100%; + border-top-left-radius: 100%; + background-color: red; + transition: all .05s cubic-bezier(0.9, 0.54, 0.26, 1.68); /* transition time should be set ahead of timing function */ } + + From 4d88995181699ad09dde9590c421b0e1e3ece4f1 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Thu, 15 Dec 2022 11:24:12 +0800 Subject: [PATCH 03/15] learned and finished day03 --- 03 - CSS Variables/index-START.html | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 7171607..406f088 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,10 +21,21 @@

Update CSS Variables with JS

From 137744ff5936929285b2ae198e16c2af83f3e864 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Fri, 16 Dec 2022 10:45:15 +0800 Subject: [PATCH 04/15] learned and finished day04 --- 04 - Array Cardio Day 1/index-START.html | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 4162bce..19cab10 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -33,28 +33,67 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600)); + console.log("List of inventors who were born in the 1500's: "); + console.table(fifteen); // Array.prototype.map() // 2. Give us an array of the inventors' first and last names + const names = inventors.map(inventor => (inventor.first + ' ' + inventor.last)); + // const names = inventors.map(inventor => `${inventor.first} ${inventor.last}`); + console.log("Array of inventors' fullnames: "); + console.log(names); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const birthadteSort = inventors.sort((a,b) => (a.year > b.year) ? 1 : -1); // order: -1 front of, 1 back of + console.log("List sorted by birthdate, oldest to youngest: "); + console.table(birthadteSort); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const totalYear = inventors.reduce((total, inventor) => { + return total + (inventor.passed - inventor.year); + },0); + console.log("Years of all the inventors live: "); + console.log(totalYear); // 5. Sort the inventors by years lived + const ageSort = inventors.sort((a,b) => { + const last = a.passed - a.year; + const next = b.passed - b.year; + return (next < last) ? -1 : 1; // next < last, -1 means put a front of b, a is older + }); + console.log("List sorted by years lived, long to short: "); + console.table(ageSort); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris - + // const category = document.querySelector('.mw-category'); + // const links = Array.from(category.querySelectorAll('a')); + // const de = links.map(link => link.textContent).filter(name => name.includes('de')); // 7. sort Exercise // Sort the people alphabetically by last name + const sortLastName = people.sort((a,b) => { + return (a.split(', ')[1] > b.split(', ')[1] ? 1 : -1); + }) + console.table(sortLastName); // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + const count = data.reduce((obj, item) => { + // console.log('obj:' + obj); + // console.log('item:' + item); + // console.log('obj-item: '+ obj[item]); + if(!obj[item]) { + obj[item] = 0; + } + obj[item]++; // e.g.: obj{ 'car': 1 } + return obj; + },{}); // init obj = {} + console.log(count); From d8f6c30b4b6d2de11a7eed8ecee410f705bc6592 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Sat, 17 Dec 2022 11:29:39 +0800 Subject: [PATCH 05/15] learned and finished day05 --- 05 - Flex Panel Gallery/index-START.html | 63 +++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index 04e974b..b454eb2 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -24,6 +24,8 @@ .panels { min-height:100vh; overflow: hidden; + + display: flex; } .panel { @@ -41,6 +43,12 @@ font-size: 20px; background-size:cover; background-position:center; + + flex: 1; + justify-content: center; + align-items: center; + display: flex; + flex-direction: column; } @@ -53,7 +61,41 @@ .panel > * { margin:0; width: 100%; - transition:transform 0.5s; + /*text transform (origin)*/ + /* transition:transform 0.5s; */ + + /* optimise: delay text transition */ + transition: transform 0.5s 0.7s; + + flex: 1 0 auto; + display: flex; + justify-content: center; + align-items: center; + } + + .panel > *:first-child { + transform: translateY(-100%); + } + + .panel > *:last-child { + transform: translateY(100%); + } + + + /* .panel.open-actived > *:first-child { + transform: translateY(0); + } + .panel.open-actived > *:last-child { + transform: translateY(0); + } */ + + /*optimise: .open-actived -> .open, use only one eventListener*/ + .panel.open > *:first-child { + transform: translateY(0); + } + + .panel.open > *:last-child { + transform: translateY(0); } .panel p { @@ -67,6 +109,8 @@ } .panel.open { + flex: 5; + font-size:40px; } @@ -107,7 +151,24 @@ From 4a0f366062f427c399c554e4375f590445d65cc1 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Mon, 19 Dec 2022 10:38:20 +0800 Subject: [PATCH 06/15] learned and finished day06 --- 06 - Type Ahead/index-START.html | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886..6f3d688 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,46 @@ From aa3dd8a0be5c0de242698192a39197d058c42a89 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Tue, 20 Dec 2022 09:48:59 +0800 Subject: [PATCH 07/15] learned and finished day07 --- 07 - Array Cardio Day 2/index-START.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 206ec31..233f7d6 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,31 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19? + const isAdult = people.some(person => { + const curYear = new Date().getFullYear(); + return curYear - person.year >= 19; + }); + console.log(isAdult); + //console.log({isAdult}); // => {isAdult: true} + // Array.prototype.every() // is everyone 19? + const isAllAdults = people.every(person => { + new Date().getFullYear() - person.year >= 19; + }) + console.log(isAllAdults); // Array.prototype.find() // Find is like filter, but instead returns just the one you are looking for // find the comment with the ID of 823423 + const comment = comments.find( comment => comment.id == 823423 ); + console.log(comment); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const commentIndex = comments.findIndex(comment => comment.id == 823423); + const newComments = [...comments.slice(0,commentIndex), ...comments.slice(commentIndex+1)]; + console.table(newComments); From e37bf5ead6e1b9dcf2e0050f007b382155443ab0 Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Wed, 21 Dec 2022 09:15:49 +0800 Subject: [PATCH 08/15] learned and finished day08 --- 08 - Fun with HTML5 Canvas/index-START.html | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148d..f8e65d5 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,57 @@ From 6e4d33519e36e4ccc415d58ca8f90be5e9b3839e Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Sat, 7 Jan 2023 21:36:42 +0800 Subject: [PATCH 14/15] learned and finished day17-18 --- 17 - Sort Without Articles/index-start.html | 12 +++++++++++ 18 - AddingUpTimesWithReduce/index-start.html | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/17 - Sort Without Articles/index-start.html b/17 - Sort Without Articles/index-start.html index 9bbd250..4ae529b 100644 --- a/17 - Sort Without Articles/index-start.html +++ b/17 - Sort Without Articles/index-start.html @@ -46,7 +46,19 @@ diff --git a/18 - AddingUpTimesWithReduce/index-start.html b/18 - AddingUpTimesWithReduce/index-start.html index abdf4c9..18f4c55 100644 --- a/18 - AddingUpTimesWithReduce/index-start.html +++ b/18 - AddingUpTimesWithReduce/index-start.html @@ -5,6 +5,7 @@ Videos +

total time:

  • Video 1 @@ -182,6 +183,26 @@
From e75cdeef4839dd5570932d7167176b4e95512f5e Mon Sep 17 00:00:00 2001 From: lchungy90 Date: Mon, 9 Jan 2023 16:35:20 +0800 Subject: [PATCH 15/15] learned and finished day 19 --- 19 - Webcam Fun/index-start.html | 15 +++-- 19 - Webcam Fun/index.js | 107 +++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 19 - Webcam Fun/index.js diff --git a/19 - Webcam Fun/index-start.html b/19 - Webcam Fun/index-start.html index 5909522..6c014a1 100644 --- a/19 - Webcam Fun/index-start.html +++ b/19 - Webcam Fun/index-start.html @@ -10,7 +10,8 @@
- +
- + -
+
+ + unsaveImg + +
- + diff --git a/19 - Webcam Fun/index.js b/19 - Webcam Fun/index.js new file mode 100644 index 0000000..4400299 --- /dev/null +++ b/19 - Webcam Fun/index.js @@ -0,0 +1,107 @@ +window.onload = function() { + canvas = document.querySelector('canvas'); + video = document.querySelector('video'); + ctx = canvas.getContext('2d'); + img = document.querySelector('#myimg'); + slider = document.querySelector('.rgb'); + a = document.querySelector('a'); + + filter = { + rmin: 0, + rmax: 255, + gmin: 0, + gmax: 255, + bmin: 0, + bmax: 255 + } + + + askWebcam(); + + slider.onchange = function(e) { + ctx.putImageData(origindata, 0, 0); + const target = e.target; + const startPos = { + 'r': 0, + 'g': 1, + 'b': 2 + }[target.name[0]]; + var tempFilter = checkFilter(target.name, target.value); + const filterMin = tempFilter.min; + const filterMax = tempFilter.max; + var img = ctx.getImageData(0, 0, 300, 200); + + + var imgd = img.data; + for (var i = startPos, len = imgd.length; i < len; i += 4) { + if (imgd[i] < filterMin) { + imgd[i] = filterMin; + } else if (imgd[i] > filterMax) { + imgd[i] = filterMax; + } + } + ctx.putImageData(img, 0, 0); + img.src = canvas.toDataURL(); + } + +} + + +function takePhoto() { + ctx.drawImage(video, 0, 0, 300, 200); + origindata = ctx.getImageData(0, 0, 300, 200); +} + +function savePhoto() { + img.src = canvas.toDataURL(); + a.href = canvas.toDataURL(); + a.setAttribute('download', 'handsome'); +} + + +function askWebcam() { + navigator.getUserMedia = navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia; + if (navigator.getUserMedia) { + navigator.getUserMedia({ + audio: false, + video: { + width: 300, + height: 200 + } + }, function(stream) { + video.srcObject = stream; + video.onloadedmetadata = function(e) { + video.play(); + } + }, function(err) { + console.log('Error occured:' + err.name); + }); + } else { + console.log('this navigator doesn\'t support webcam!'); + } +} + + +function checkFilter(name, value) { + var _min; + var _max; + var _antiname = { + 'rmin': 'rmax', + 'rmax': 'rmin', + 'gmin': 'gmax', + 'gmax': 'gmin', + 'bmin': 'bmax', + 'bmax': 'bmin' + }[name] + filter[name] = value; + //当下限值超过上限时,将两者对调 + _min = Math.min(filter[name], filter[_antiname]); + _max = Math.max(filter[name], filter[_antiname]); + console.log(filter); + return { + min: _min, + max: _max + } +} \ No newline at end of file