File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed
08 - Fun with HTML5 Canvas Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change 2626
2727 // Some and Every Checks
2828 // Array.prototype.some() // is at least one person 19?
29+ const isAdult = people . some ( person => ( ( new Date ( ) ) . getFullYear ( ) - person . year >= 19 ) ) ;
30+ console . log ( isAdult ) ;
2931 // Array.prototype.every() // is everyone 19?
30-
32+ const allAdults = people . every ( person => ( ( new Date ( ) ) . getFullYear ( ) - person . year >= 19 ) ) ;
33+ console . log ( allAdults ) ;
3134 // Array.prototype.find()
3235 // Find is like filter, but instead returns just the one you are looking for
3336 // find the comment with the ID of 823423
34-
37+ const comment = comments . find ( comment => comment . id === 823423 ) ;
38+ console . log ( comment ) ;
3539 // Array.prototype.findIndex()
3640 // Find the comment with this ID
3741 // delete the comment with the ID of 823423
42+ const index = comments . findIndex ( comment => comment . id === 823423 ) ;
43+
44+ const newComment = [
45+ ...comments . slice ( 0 , index ) ,
46+ ...comments . slice ( index + 1 )
47+ ]
48+ console . table ( comments ) ;
49+ console . table ( newComment ) ;
3850
3951 </ script >
4052</ body >
Original file line number Diff line number Diff line change 77< body >
88< canvas id ="draw " width ="800 " height ="800 "> </ canvas >
99< script >
10+ const canvas = document . querySelector ( '#draw' ) ;
11+ const ctx = canvas . getContext ( '2d' ) ;
12+ canvas . height = window . innerHeight ;
13+ canvas . width = window . innerWidth ;
14+ ctx . strokeStyle = '#BADA55' ;
15+ ctx . lineWidth = 100 ;
16+ let lastX = 0 ;
17+ let lastY = 0 ;
18+ ctx . lineJoin = 'round' ;
19+ ctx . lineCap = 'round' ;
20+ ctx . lineWidth = 100 ;
21+ let isDrawing = false ;
22+ let direction = false ;
23+ let hue = 0 ;
24+
25+ function draw ( e ) {
26+ if ( isDrawing ) {
27+ ctx . strokeStyle = `hsl(${ hue } , 100%, 50%)` ;
28+
29+ ctx . beginPath ( )
30+ ctx . moveTo ( lastX , lastY ) ;
31+ ctx . lineTo ( e . offsetX , e . offsetY ) ;
32+ ctx . stroke ( ) ;
33+ [ lastX , lastY ] = [ e . offsetX , e . offsetY ]
34+ hue ++ ;
35+ if ( hue >= 360 ) {
36+ hue = 0 ;
37+ }
38+ if ( ctx . lineWidth <= 1 || ctx . lineWidth >= 100 ) {
39+ direction = ! direction ;
40+ }
41+ if ( direction ) {
42+ ctx . lineWidth -= 0.1 ;
43+ } else {
44+ ctx . lineWidth += 0.1 ;
45+ }
46+ }
47+ }
48+
49+ canvas . addEventListener ( 'mousemove' , draw ) ;
50+ canvas . addEventListener ( 'mousedown' , ( e ) => {
51+ isDrawing = true ;
52+ [ lastX , lastY ] = [ e . offsetX , e . offsetY ] ;
53+
54+ } ) ;
55+ canvas . addEventListener ( 'mouseup' , ( ) => isDrawing = false ) ;
56+ canvas . addEventListener ( 'mouseout' , ( ) => isDrawing = false ) ;
57+
1058</ script >
1159
1260< style >
You can’t perform that action at this time.
0 commit comments