konvabean
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| konvabean [2026/05/25 19:20] – created wikiadmin | konvabean [2026/05/26 13:54] (current) – [LLM Meta Prompt] wikiadmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | |||
| ====== MIStudio Konva Bean ====== | ====== MIStudio Konva Bean ====== | ||
| ===== TL;DR / Quick Start ===== | ===== TL;DR / Quick Start ===== | ||
| + | |||
| + | < | ||
| + | See the end of the document for a prompt that you can use with your favorite LLM - ChatGPT, CoPilot, Claude, Gemini, etc. to create any graphics you can imagine... | ||
| + | </ | ||
| **Three critical rules** | **Three critical rules** | ||
| Line 40: | Line 43: | ||
| init(container) { | init(container) { | ||
| container.innerHTML = ""; | container.innerHTML = ""; | ||
| + | container.style.overflow = " | ||
| + | container.style.position = " | ||
| + | |||
| + | this.stageHost = document.createElement(" | ||
| + | this.stageHost.style.position = " | ||
| + | this.stageHost.style.left = " | ||
| + | this.stageHost.style.top = " | ||
| + | this.stageHost.style.width = " | ||
| + | this.stageHost.style.height = " | ||
| + | this.stageHost.style.overflow = " | ||
| + | container.appendChild(this.stageHost); | ||
| + | |||
| + | var w = container.clientWidth || container.offsetWidth || 300; | ||
| + | var h = container.clientHeight || container.offsetHeight || 200; | ||
| this.stage = new window.Konva.Stage({ | this.stage = new window.Konva.Stage({ | ||
| - | container: | + | container: |
| - | width: | + | width: |
| - | height: | + | height: |
| }); | }); | ||
| Line 51: | Line 68: | ||
| this.circle = new window.Konva.Circle({ | this.circle = new window.Konva.Circle({ | ||
| - | x: 100, | + | x: w / 2, |
| - | y: 100, | + | y: h / 2, |
| radius: 40, | radius: 40, | ||
| fill: " | fill: " | ||
| Line 58: | Line 75: | ||
| this.layer.add(this.circle); | this.layer.add(this.circle); | ||
| - | | + | |
| + | var self = this; | ||
| + | |||
| + | | ||
| + | if (!self.stage || !self.circle) { | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | var w = container.clientWidth || container.offsetWidth || 1; | ||
| + | var h = container.clientHeight || container.offsetHeight || 1; | ||
| + | |||
| + | self.stage.width(w); | ||
| + | self.stage.height(h); | ||
| + | |||
| + | self.circle.x(w / 2); | ||
| + | self.circle.y(h / 2); | ||
| + | |||
| + | self.layer.draw(); | ||
| + | }; | ||
| + | |||
| + | this.resizeObserver = new ResizeObserver(function() { | ||
| + | self.resize(); | ||
| + | }); | ||
| + | |||
| + | this.resizeObserver.observe(container); | ||
| + | |||
| + | this.resize(); | ||
| + | } | ||
| + | |||
| + | cleanup() { | ||
| + | if (this.resizeObserver) { | ||
| + | this.resizeObserver.disconnect(); | ||
| + | this.resizeObserver = null; | ||
| + | } | ||
| + | |||
| + | if (this.stage) { | ||
| + | this.stage.destroy(); | ||
| + | this.stage = null; | ||
| + | } | ||
| + | |||
| + | this.circle = null; | ||
| + | this.layer = null; | ||
| + | this.stageHost = null; | ||
| + | this.resize = null; | ||
| } | } | ||
| Line 66: | Line 126: | ||
| var value = parseFloat(obj.value); | var value = parseFloat(obj.value); | ||
| - | this.circle.fill(value > 50 ? " | + | |
| - | this.layer.draw(); | + | |
| + | this.layer.draw(); | ||
| + | } | ||
| } catch (err) { | } catch (err) { | ||
| console.error(err); | console.error(err); | ||
| Line 329: | Line 391: | ||
| ===== LLM Meta Prompt ===== | ===== LLM Meta Prompt ===== | ||
| - | Copy this into ChatGPT/ | + | Copy this into ChatGPT/ |
| < | < | ||
konvabean.1779751243.txt.gz · Last modified: by wikiadmin
