Skip to content

Commit 1ed999c

Browse files
author
Axel
committed
Add exercise 08 and Update showcase
1 parent 2a6999e commit 1ed999c

File tree

9 files changed

+116
-2
lines changed

9 files changed

+116
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ Temporary Items
3636
node_modules
3737
tapas.xcf
3838
_empty
39+
JavaScript30
3940

4041
# End of https://www.gitignore.io/api/osx,sass

01 - JavaScript Drum Kit/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function playSound(event) {
44
if (!audio) return;
55
audio.currentTime = 0;
66
audio.play();
7-
key.classList.add("playing"); //*
7+
key.classList.add("playing");
88
}
99

1010
function removeTransition (e) {

08 - Fun with HTML5 Canvas/dist/main.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var gulp = require('gulp'),
2+
browserSync = require('browser-sync').create(),
3+
babel = require("gulp-babel"),
4+
uglify = require('gulp-uglify'),
5+
plumber = require("gulp-plumber");
6+
7+
gulp.task('server', ['babel'], function() {
8+
9+
browserSync.init({
10+
server: "./",
11+
open: false
12+
});
13+
14+
gulp.watch("./*.html").on('change', browserSync.reload);
15+
gulp.watch("./*.s+(a|c)ss", ['sass']);
16+
gulp.watch("./*.js", ['babel']);
17+
});
18+
19+
gulp.task('babel', function () {
20+
return gulp.src("./main.js")
21+
.pipe(plumber())
22+
.pipe(babel({
23+
"presets": ["babel-preset-es2015"].map(require.resolve)
24+
}))
25+
.pipe(gulp.dest("./dist"))
26+
.pipe(browserSync.stream());
27+
});
28+
29+
gulp.task('miniJS', function () {
30+
return gulp.src("dist/main.js")
31+
.pipe(uglify())
32+
.pipe(gulp.dest("./dist"));
33+
});
34+
35+
36+
gulp.task('mini', ['miniJS']);
37+
gulp.task('default', ['server']);
33.7 KB
Loading

08 - Fun with HTML5 Canvas/index.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>HTML5 Canvas</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
7+
</head>
8+
<body>
9+
10+
<style>
11+
body, html {
12+
padding: 0;
13+
margin: 0; }
14+
</style>
15+
16+
<canvas id="draw" width="800" height="800"></canvas>
17+
18+
<script src="dist/main.js"></script>
19+
</body>
20+
</html>

08 - Fun with HTML5 Canvas/main.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const canvas = document.querySelector("#draw");
2+
const ctx = canvas.getContext('2d');
3+
4+
canvas.width = window.innerWidth;
5+
canvas.height = window.innerHeight;
6+
canvas.color = "red";
7+
8+
ctx.lineJoin = "round";
9+
ctx.lineCap = "round";
10+
ctx.lineWidth = 0;
11+
ctx.globalCompositeOperation = "hue";
12+
13+
let isDrawing = false;
14+
let lastX = 0;
15+
let lastY = 0;
16+
let hue = 0;
17+
let direction = true;
18+
19+
function draw(e){
20+
if (!isDrawing) return;
21+
// console.log(e);
22+
23+
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
24+
25+
ctx.beginPath();
26+
ctx.moveTo(lastX, lastY);
27+
ctx.lineTo(e.offsetX, e.offsetY);
28+
ctx.stroke();
29+
30+
[lastX, lastY] = [e.offsetX, e.offsetY];
31+
hue++;
32+
33+
if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
34+
direction = !direction;
35+
}
36+
if (direction) {
37+
ctx.lineWidth++;
38+
} else {
39+
ctx.lineWidth--;
40+
}
41+
}
42+
43+
canvas.addEventListener('mousedown', (e) => {
44+
isDrawing = true;
45+
[lastX, lastY] = [e.offsetX, e.offsetY];
46+
});
47+
48+
canvas.addEventListener('mousemove', draw);
49+
canvas.addEventListener('mouseup', () => isDrawing = false);
50+
canvas.addEventListener('mouseout', () => isDrawing = false);

dist/main.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.js

+5
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ const data = [
4343
title: "Type Ahead",
4444
url: "06 - Type Ahead/index.html",
4545
img: "06 - Type Ahead/image/06_port.jpg"
46+
},
47+
{
48+
title: "HTML5 Canvas",
49+
url: "08 - Fun with HTML5 Canvas/index.html",
50+
img: "08 - Fun with HTML5 Canvas/image/08_port.jpg"
4651
}
4752
];

0 commit comments

Comments
 (0)