xxxxxxxxxx
function setup() {
createCanvas(400, 400);
background(230); // light gray background
drawOR(50, 50, 200, 200, 20);
//drawOR(100, 120, 40, 60, 30);
//drawOR(30, 200, 50, 70, 40);
noLoop();
}
function drawOR(x, y, w, h, l) {
// Draw input wires
line(x - l, y + h / 3, x, y + h / 3);
line(x - l, y + 2 * h / 3, x, y + 2 * h / 3);
// Draw the OR gate shape
beginShape();
// vertex(x, y); // top left corner
// Left curve
for (let angle = -HALF_PI; angle < HALF_PI + .2; angle += .2) {
let sx = x + cos(angle) * w * 0.1;
let sy = y + h / 2 + sin(angle) * h / 2;
// console.log(sx, sy);
vertex(sx, sy);
}
// Right curve
//for (let angle = HALF_PI; angle <= 3 * HALF_PI; angle += 0.01) {
// let sx = x + w + cos(angle) * w * 0.5;
// let sy = y + h / 2 + sin(angle) * h / 2;
// vertex(sx, sy);
//}
// vertex(x, y + h); // bottom left corner
endShape(CLOSE);
// Draw output wire
line(x + 1.5 * w, y + h / 2, x + 1.5 * w + l, y + h / 2);
}
// Test the drawOR function with different sizes