-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
*.iml | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body style="background-color: blue;"> | ||
<div style="background-color: rgba(255,0,0,0.7);width: 100px;height: 100px;"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(function () { | ||
|
||
let img = new Image(); | ||
img.onload = e => { | ||
document.body.appendChild(img); | ||
}; | ||
img.src = "dog.jpg"; | ||
|
||
})(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<!--<img src="dog.jpg">--> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function () { | ||
|
||
let canvas = document.querySelector("canvas"); | ||
|
||
function loadImage(src) { | ||
return new Promise((resolve, reject) => { | ||
let img = new Image(); | ||
img.onload = () => { | ||
resolve(img); | ||
}; | ||
img.onerror = reject; | ||
img.src = src; | ||
}); | ||
} | ||
|
||
async function main() { | ||
let img = await loadImage("dog.jpg"); | ||
|
||
//draw image | ||
/** | ||
* @type {CanvasRenderingContext2D | null} | ||
*/ | ||
let context2d = canvas.getContext("2d"); | ||
context2d.drawImage(img, 0, 0); | ||
|
||
let imageData = context2d.getImageData(0, 0, 200, 200); | ||
// console.log(imageData.data.length); | ||
console.log(imageData.data); | ||
|
||
let rImageData = context2d.createImageData(200, 200); | ||
for (let i = 0; i < imageData.data.length; i += 4) { | ||
let r = imageData.data[i]; | ||
let g = imageData.data[i + 1]; | ||
let b = imageData.data[i + 2]; | ||
let value = Math.round((r + g + b) / 3); | ||
rImageData.data[i] = value; | ||
rImageData.data[i + 1] = value; | ||
rImageData.data[i + 2] = value; | ||
rImageData.data[i + 3] = 255; | ||
} | ||
|
||
context2d.putImageData(rImageData, 200, 0); | ||
} | ||
|
||
main(); | ||
})(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
<canvas width="400" height="400" style="border-style: solid;"></canvas> | ||
|
||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.