processing.js
line and point
by uto usui
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<div class="wrap">
<h1>processing.js</h1>
<p class="lead">line and point</p>
<canvas id="myCanvas"></canvas>
</div>
<link href="https://fonts.googleapis.com/css?family=Dancing+Script:400,700" rel="stylesheet">
SCSS
body {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
font-family: 'Dancing Script';
text-align: center;
background-image: linear-gradient(-30deg,#f7cac9 20%,#91A8d0 85%);
}
h1 {
font-size: 42px;
font-weight: bold;
color: #32355a;
}
canvas {
margin: 20px auto;
border: 3px dashed rgba(#32355a, .55);
background-color: rgba(white, .15);
}
JavaScript
</script>
<script type="application/processing" data-processing-target="myCanvas">
// キャンバスのサイズ
size(480, 320);
// 点を描く
// point(x, y)
point(50, 50);
point(120, 120);
point(300, 250);
// 直線を描く
// line(1x, 1y, 2x, 2y)
line(0, 200, 300, 50);
line(400, 200, 100, 50);
line(200, 300, 300, 20);
// 線幅
strokeWeight(20);
// 線の端のスタイル
strokeCap(ROUND);
line(20, 230, 80, 230);
strokeCap(SQUARE);
line(20, 260, 80, 260);
strokeCap(PROJECT);
line(20, 290, 80, 290);