자연수
오른쪽 아래의 슬라이더를 움직이면
p5.js
코드 보기
function setup() {
createCanvas(600, 620);
modslider = createSlider(2, 120, 9, 1);
modslider.position(430, 590);
}
function draw() {
translate(20, 20);
background(255);
mod = modslider.value();
size = 560 / (mod-1);
from = color(255, 153, 0);
to = color(0, 102, 255);
noStroke();
for (var i = 1; i < mod; i++) {
for (var j = 1; j < mod; j++) {
now = (i*j) % mod;
fill(lerpColor(from, to, now/(mod-1)));
rect((i-1)*size, (j-1)*size, size, size);
if (mod < 40) {
fill(0);
textSize(size/2);
textAlign(CENTER, CENTER);
text(now, (i-1)*size + size/2, (j-1)*size + size/2);
}
}
}
stroke(0);
for (var i = 0; i < mod; i++) {
line(0, i*size, 560, i*size);
line(i*size, 0, i*size, 560);
}
}
'Others > Processing' 카테고리의 다른 글
p5.js 연습 008. 리사주 곡선(Lissajous curve) (0) | 2017.07.21 |
---|---|
p5.js 연습 007. 장미 곡선(Rose curve) (0) | 2017.07.21 |
p5.js 연습 006. 프랙탈 스파이로그래프(fractal spirograph) (0) | 2017.07.14 |
p5.js 연습 005. 에피사이클로이드(epicycloid) (0) | 2017.07.09 |
p5.js 연습 004. 스파이로그래프(Spirograph) (0) | 2017.07.07 |