xxxxxxxxxx
105
let osc;
let points=[];
let lines=[];
let k = 0;
let t = 1.1;
let radio = 170;
let input, input2, input3;
let m;
let turn=0;
let base = 528;
function setup() {
createCanvas(1000, 800);
angleMode(DEGREES);
input = createInput();
input.position(width/2+180, height-180);
input.size(40, 30);
input2 = createInput();
input2.position(width/2+180, height-130);
input2.size(40, 30);
input2.input(Reset);
input3 = createInput();
input3.position(width/2+180, height-80);
input3.size(40, 30);
input3.input(Reset);
osc = new p5.Oscillator();
osc.setType('triangle');
osc.freq(240);
osc.amp(0);
osc.start();
}
function draw() {
background(255);
strokeWeight(1.2);
textSize(24);
fill(200,50,180);
textAlign(CENTER, CENTER);
text("The expression of divisors of the natural integer n", width/2,60);
text(" 自然数 n とその約数の構造を絵で表したもの", width/2,90);
strokeWeight(0.5);
textSize(20);
text("connecting constant-distance points on the regular n-polygon", width/2,150);
text("正 n 多角形の頂点を等間隔に結んだもの", width/2,180);
textSize(20);
text("input the value of n here (n の数をいれてください)", width/2-120,height-160);
text("input the value of a here (a の数をいれてください)", width/2-120,height-110);
text("input the value of b here (b の数をいれてください)", width/2-120,height-60);
text("ドから1オクターブ上のドまでを n 平均律にわけて、a、bごとに離れた音を奏でます", width/2,height-10);
n = input.value();
a = int(input2.value());
b = int(input3.value());
if(a>0&!b>0){b=a};
strokeWeight(3);
fill(150,0,100,50);
translate(width/2, height/2);
rotate(-90);
stroke(0);
ellipse(0,0,radio*2,radio*2);
fill(255,0,0);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
stroke(i*255/n,0,255);
line(radio * cos(360/n * (i*j)),radio * sin(360/n * (i*j)),radio * cos(360/n * (i*(j+1))),radio * sin(360/n * (i*(j+1))));}
}
if(turn%2==0){m=a}
if(turn%2==1){m=b}
for(i=0;i<n;i++){
points[i]=ellipse(radio * cos(360/n * i),radio * sin(360/n * i),10,10);
}
pointx = (1-t)*radio * cos(360/n * k)+t*radio*cos(360/n*(k+m));
pointy = (1-t)*radio * sin(360/n * k)+t*radio*sin(360/n*(k+m));
fill(255,255,0);
ellipse(pointx,pointy,20,20);
if(t==0 & k==0){
osc.freq(base, 0);
osc.amp(0.5, 0);
}
if(t>0.15&&t<0.25){osc.amp(0,0);};
t+=0.03;
if(t>1){
t=0;
k+=m;
turn+=1;
if(m>0){
osc.freq(base*pow(2,(k/n-int(k/n))), 0);
osc.amp(0.5, 0);
}
}
}
function Reset(){
t = 0;
k = 0;
turn = 0;
osc.freq(base, 0);
osc.amp(0.5, 0);
}