processing.js
rotate and translate
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">translate</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(320, 320);
rectMode(CENTER); // rect(中心のx座標, 中心のy座標, 幅, 高さ)
colorMode(HSB,360,100,100,100);
background(180, 35, 80, 20);
int w = width;
int h = height;
int rectW = 10;
int num = 20;
int gutter = (w - rectW * num) / (num - 1) + rectW; // 間隔
noStroke();
translate(w/2,h/2);
for (int i=0; i<num; i++) {
float randColor = random(150, 250);
fill(randColor, 55, 70, 40);
rect(0, 0, rectW, rectW);
// 座標移動
translate(gutter, 0);
// 回転
// rotate(radians(角度));
rotate(radians(360/num));
}