xxxxxxxxxx
43
let vertPath = "./shaders/attr.vert";
let fragPath = "./shaders/attr.frag";
let shader_id;
let geo;
let bgCol;
function preload(){
shader_id = loadShader(vertPath, fragPath);
}
function setup(){
createCanvas(600, 600, WEBGL);
bgCol = createColorPicker()
geo = new p5.Geometry()
let v0 = createVector(-40, 0, 0);
let v1 = createVector(0, -40, 0);
let v2 = createVector(40, 0, 0);
geo.vertices.push(v0, v1, v2)
geo.vertexColors.push(1,0,0,1,0,1,0,1,0,0,1,1)
}
function draw(){
background(bgCol.value());
orbitControl()
noStroke()
shader(shader_id);
beginShape();
fill(255,0,0);
vertex(-40, 0, 0);
fill(0,255,0);
vertex(0, -40, 0);
fill(0,0,255);
vertex(40, 0, 0);
endShape(CLOSE);
push()
translate(0,50,0)
model(geo)
pop()
}