1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| "use strict";
function BoxParam() { this.width = 100; this.height = 100; this.depth = 100; this.setRandom = function () { this.width = Math.random() * 200; this.height = Math.random() * 200; this.depth = Math.random() * 200; }; this.strokeColor = "#456"; this.fillColor = "#f3a"; this.bgColor = "#fff"; this.hasBoder = true; this.hasFill = true; this.canRotate = true; }
function LabelParam() { this.text = "defult"; this.offset = { x: 50, y: 25 }; this.size = 10; this.textColor = "#123"; }
const boxParam = new BoxParam(); const labelParam = new LabelParam();
let font = null; function preload() { font = loadFont("mgenplus-1c-black.ttf"); }
function setup() { createCanvas(400, 200, WEBGL);
textFont(font);
const pane = new Tweakpane({ title: "Parameters", });
pane.addInput(boxParam, "canRotate");
const sizeControle = pane.addFolder({ title: "SizePanal", }); sizeControle.addInput(boxParam, "width", { min: 10, max: 200, step: 20 }); sizeControle.addInput(boxParam, "height", { options: { 50: 50, 100: 100, 150: 150 }, }); sizeControle.addInput(boxParam, "depth", { options: { S: 50, M: 100, L: 150 }, }); sizeControle .addButton({ title: "setRandom", }) .on("click", () => { boxParam.setRandom(); pane.refresh(); });
const colorControle = pane.addFolder({ title: "ColorPanal", }); colorControle.addInput(boxParam, "bgColor"); colorControle.addInput(boxParam, "strokeColor"); colorControle.addInput(boxParam, "fillColor"); colorControle.addInput(boxParam, "hasBoder"); colorControle.addInput(boxParam, "hasFill");
const stringControle = pane.addFolder("StringPanal"); stringControle.addInput(labelParam, "text"); stringControle.addInput(labelParam, "offset"); stringControle.addInput(labelParam, "size"); stringControle.addInput(labelParam, "textColor"); }
function draw() { background(color(boxParam.bgColor));
push(); if (boxParam.canRotate) { rotateX(frameCount * 0.01); rotateY(frameCount * 0.01); } if (boxParam.hasBoder) { stroke(boxParam.strokeColor); } else { noStroke(); } if (boxParam.hasFill) { fill(boxParam.fillColor); } else { noFill(); } box(boxParam.width, boxParam.height, boxParam.depth); pop();
textSize(labelParam.size); fill(labelParam.textColor); text(labelParam.text, labelParam.offset.x, labelParam.offset.y); }
|