[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
<canvas id="drawInversedImageCanvas" width="300" height="200"></canvas> <script type="text/JavaScript" src="https://blog.cnobi.jp/v1/blog/user/118c300f2ee0ad311e5962b0167205f5/1371278164"> </script>
(function() { var canvas = document.getElementById("drawInversedImageCanvas"); var context = canvas.getContext("2d"); context.fillStyle = "rgb(0, 0, 255)"; context.fillRect(0, 0, 100, 100); context.strokeStyle = "rgb(255, 255, 255)"; context.strokeRect(10, 10, 80, 80); var imageData = context.getImageData(0, 0, 100, 100); for (var i = 0; i < imageData.data.length; i += 4) { var max = 255; imageData.data[i + 0] = max - imageData.data[i + 0]; imageData.data[i + 1] = max - imageData.data[i + 1]; imageData.data[i + 2] = max - imageData.data[i + 2]; imageData.data[i + 3] = max; } context.putImageData(imageData, 100, 0); })();
<canvas id="drawWaveCanvas" width="300" height="200"></canvas> <script type="text/JavaScript" src="https://blog.cnobi.jp/v1/blog/user/118c300f2ee0ad311e5962b0167205f5/1371278220"> </script>
(function() { var canvas = document.getElementById("drawGradationManuallyCanvas"); var context = canvas.getContext("2d"); var size = { width: 200, height: 100 }; var imageData = context.createImageData(size.width, size.height); for (var x = 0; x < size.width; x++) { for (var y = 0; y < size.height; y++) { var pixelIndex = x + y * size.width; var dataIndex = pixelIndex * 4; var max = 255; imageData.data[dataIndex + 0] = max * x / size.width; imageData.data[dataIndex + 1] = max * y / size.height; imageData.data[dataIndex + 2] = max; imageData.data[dataIndex + 3] = max; } } context.putImageData(imageData, 0, 0); })();
<canvas id="drawTranslatedRectCanvas" width="300" height="200"></canvas> <script> (function () { var canvas = document.getElementById("drawTranslatedRectCanvas"); var context = canvas.getContext("2d"); context.strokeRect(0, 0, 100, 50); context.translate(80, 80); context.strokeRect(0, 0, 100, 50); })(); </script>
<canvas id="drawRotatedRectCanvas" width="300" height="200"></canvas> <script> (function() { var canvas = document.getElementById("drawRotatedRectCanvas"); var context = canvas.getContext("2d"); context.strokeRect(0, 0, 100, 50); context.rotate(Math.PI / 6); //30° context.strokeRect(0, 0, 100, 50); })(); </script>
<canvas id="drawScaledRectCanvas" width="300" height="200"></canvas> <script> (function() { var canvas = document.getElementById("drawScaledRectCanvas"); var context = canvas.getContext("2d"); context.strokeRect(0, 0, 100, 50); context.scale(2, 2); context.strokeRect(0, 0, 100, 50); })(); </script>
<canvas id="drawClearRectDemoCanvas" width="300" height="200"></canvas> <script> (function() { var canvas = document.getElementById("drawClearRectDemoCanvas"); var context = canvas.getContext("2d"); context.fillRect(0, 0, 300, 200); context.clearRect(50, 50, 200, 100); })(); </script>
<canvas id="drawSaveRestoreDemoCanvas" width="300" height="200"></canvas> <script> (function() { var canvas = document.getElementById("drawSaveRestoreDemoCanvas"); var context = canvas.getContext("2d"); context.save(); context.fillStyle = "rgb(0, 0, 255)"; context.fillRect(0, 0, 100, 50); context.restore(); context.fillRect(0, 50, 100, 50); })(); </script>
<canvas id="drawClippedRectangleCanvas" width="300" height="300"></canvas> <script> (function() { var canvas = document.getElementById("drawClippedRectangleCanvas"); var context = canvas.getContext("2d"); context.rect(100, 100, 200, 200); context.stroke(); context.clip(); context.fillRect(0, 0, 200, 200); })(); </script>