processing.js

load and save

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">save load</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%;
	min-height: 100vh;
  padding: 1em;
	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);
colorMode(HSB,360,100,100,100);
background(180, 35, 80, 20);

int w = width;
int h = height;
int rectW = 10;
int num = 20;
noStroke();

translate(w/2,h/2);


for(int i=0; i<num; i++){
	float randColor = random(150, 250);
	fill(randColor, 55, 70, 30);
	
	pushMatrix(); // ここの座標をセーブ
	
	// 座標を変換してから描画
	rotate(radians(i*30));
	translate(10*i, 0);
	rect(0, 0, rectW, rectW);
	
	popMatrix(); // 前の座標をロード
}