xxxxxxxxxx
let rule
function setup() {
createCanvas(400, 400);
fill(0);
}
function draw() {
background(255);
//マウスの座標を画面内に制限
mX = constrain(mouseX,0,400);
mY = constrain(mouseY,0,400);
//予め定義したruleに従ってbeginShape()
beginShape(rule);
//sin波上に頂点を描画
//マウスのX座標:波の間隔
//マウスのY座標:波の高さ
for(let i = 0;i < 10;i++){
vertex(10 + 40*i, 200 + (mY-200)*sin(2*PI*(frameCount + 30*i*mX/width)/60));
}
endShape();
}
//1~7のキーが押された時、それぞれに対応したruleに変更
function keyPressed(){
switch(key){
case '1':
fill(0);
noStroke();
rule = null
break;
case '2':
noFill();
strokeWeight(2);
stroke(0);
rule = null
break;
case '3':
rule = POINTS
strokeWeight(5);
stroke(0);
break;
case '4':
strokeWeight(1);
stroke(0);
rule = LINES
break;
case '5':
fill(0);
noStroke();
rule = TRIANGLES
break;
case '6':
fill(0);
noStroke();
rule = TRIANGLE_STRIP
break;
case '7':
noFill();
strokeWeight(1);
stroke(0);
rule = TRIANGLE_STRIP
break;
default:
rule = null;
break;
}
}