p5.js:shape
(共通部分)
code:test.js
function setup() {
createCanvas(300, 300);
background('#eee');
stroke('#aaa');
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
ellipse(mouseX, mouseY, 80, 80);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
arc(mouseX, mouseY, 80, 80, 0, HALF_PI, PIE);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
line(mouseX, mouseY, 150, 150);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
point(mouseX, mouseY);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
quad(mouseX, mouseY, mouseX+10, mouseY+80,mouseX+70, mouseY+80,mouseX+100, mouseY+30,);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
rect(mouseX, mouseY, 80, 60);
}
code:testxx.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
triangle(mouseX, mouseY, mouseX+15, mouseY+30, mouseX+-15, mouseY+30);
}
正多角形
code:test.js
function draw() {
if (mouseIsPressed) {
fill(0,0,0,10);
} else {
fill('#fff');
}
var corner=3;
translate(mouseX,mouseY);
beginShape();
for (var i=0; i<corner; i++) {
var angle=map(i, 0, corner, 0, 360);
var x=sin(radians(angle))*30;
var y=cos(radians(angle))*30;
vertex(x, y);
}
endShape(CLOSE);
}
https://img.shields.io/badge/p5.js-shape-ED225D.svg?logo=p5.js&style=for-the-badge