Skip to content

Commit

Permalink
Merge pull request #1 from iPolyomino/triangle-background
Browse files Browse the repository at this point in the history
canvas background
  • Loading branch information
syasin-5d committed Dec 7, 2018
2 parents 228a18b + 8cd9bde commit 1bb972c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions index.html
Expand Up @@ -9,6 +9,7 @@
</head>

<body onload="draw();">
<canvas id="canvas"></canvas>
<div id="wrap">
<header>
<h1>NeonDrop っぽいサイト、作ってみたっす!</h1>
Expand All @@ -19,8 +20,6 @@ <h1>NeonDrop っぽいサイト、作ってみたっす!</h1>
下のはcanvasで三角形をたくさん生成してみたやつっす <br/>
リロードするたびに三角形の色とか、変わるっすよ!
</p>
<canvas id="canvas" width="540" height="400">
</canvas>
</div>

</div>
Expand Down
16 changes: 8 additions & 8 deletions neondrop.css
@@ -1,13 +1,9 @@
@charset "UTF-8";
body {
background-image: url('neondrop.png');
background-attachment: fixed;
background-size: 100% 100%;
}

#wrap {
div#wrap {
width: 780px;
margin: 0 auto;
position: relative;
}

header {
Expand All @@ -18,9 +14,13 @@ header {
text-align: center;
}

canvas {
canvas#canvas {
background-color: white;
border: 1px solid black;
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}

div#main {
Expand Down
7 changes: 7 additions & 0 deletions neondrop.js
Expand Up @@ -10,6 +10,9 @@ const pink = "#CC00FF";
function draw(){
var canvas = document.getElementById("canvas");
if(canvas.getContext){
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var ctx = canvas.getContext("2d");

var colors = [yellow, blue, cyan, pink];
Expand All @@ -24,6 +27,10 @@ function draw(){
drawTriangle({ctx:ctx, x:x, y:y, rotate:rotate, color:color});
}

window.onresize = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
draw();
};
}
}

Expand Down

0 comments on commit 1bb972c

Please sign in to comment.