DELAY node updated to not screw up canvas

Added Enable/Disable for Screensaver mode in DELAY node
This commit is contained in:
Alexander G. Morano
2024-10-29 20:54:20 -04:00
parent 23eb63bbb4
commit e2b09cb6d5
4 changed files with 31 additions and 51 deletions
+2
View File
@@ -193,6 +193,7 @@ class Lexicon(metaclass=LexiconMeta):
EDGE = 'EDGE', "Clip or Wrap the Canvas Edge"
EDGE_X = 'EDGE_X', "Clip or Wrap the Canvas Edge"
EDGE_Y = 'EDGE_Y', "Clip or Wrap the Canvas Edge"
ENABLE = 'ENABLE', "Enable or Disable"
END = 'END', "End of the range"
FALSE = '🇫', "False"
FILEN = '💾', "File Name"
@@ -779,6 +780,7 @@ try:
@PromptServer.instance.routes.post("/jovimetrix/message")
async def jovimetrix_message_post(request) -> Any:
json_data = await request.json()
print(json_data)
if (did := json_data.get("id")) is not None:
ComfyAPIMessage.MESSAGE[str(did)] = json_data
return web.json_response(json_data)
+9 -5
View File
@@ -600,7 +600,7 @@ class DelayNode(JOVBaseNode):
RETURN_NAMES = (Lexicon.PASS_OUT,)
SORT = 240
DESCRIPTION = """
Introduce pauses in the workflow that accept an optional input to pass through and a timer parameter to specify the duration of the delay. If no timer is provided, it defaults to a maximum delay. During the delay, it periodically checks for messages to interrupt the delay. Once the delay is completed, it returns the input passed to it.
Introduce pauses in the workflow that accept an optional input to pass through and a timer parameter to specify the duration of the delay. If no timer is provided, it defaults to a maximum delay. During the delay, it periodically checks for messages to interrupt the delay. Once the delay is completed, it returns the input passed to it. You can disable the screensaver with the `ENABLE` option
"""
@classmethod
@@ -610,9 +610,10 @@ Introduce pauses in the workflow that accept an optional input to pass through a
"optional": {
Lexicon.PASS_IN: (JOV_TYPE_ANY, {"default": None}),
Lexicon.TIMER: ("INT", {"default" : 0, "mij": -1}),
Lexicon.ENABLE: ("BOOLEAN", {"default": True, "tooltips":"Enable or disable the screensaver"})
},
"outputs": {
0: (Lexicon.PASS_OUT, {"tooltips":f"Pass through data when the delay ends"})
0: (Lexicon.PASS_OUT, {"tooltips":"Pass through data when the delay ends"})
}
})
return Lexicon._parse(d, cls)
@@ -623,14 +624,17 @@ Introduce pauses in the workflow that accept an optional input to pass through a
delay = JOV_DELAY_MAX
if delay > JOV_DELAY_MIN:
comfy_message(ident, "jovi-delay-user", {"id": ident, "timeout": delay})
# enable = parse_param(kw, Lexicon.ENABLE, EnumConvertType.BOOLEAN, True)
step = 1
pbar = ProgressBar(delay)
while step <= delay:
try:
data = ComfyAPIMessage.poll(ident, timeout=1)
if data.get('cmd', False):
interrupt_processing(True)
logger.warning(f"delay [cancelled] ({step}): {ident}")
if data.get('id', None) == ident:
if data.get('cmd', False) == False:
interrupt_processing(True)
logger.warning(f"delay [cancelled] ({step}): {ident}")
break
except TimedOutException as _:
if step % 10 == 0:
+4 -2
View File
@@ -25,6 +25,7 @@ app.registerExtension({
nodeType.prototype.onNodeCreated = async function () {
const me = onNodeCreated?.apply(this);
const widget_time = this.widgets.find(w => w.name == '⏱');
const widget_enable = this.widgets.find(w => w.name == 'ENABLE');
this.total_timeout = 0;
let showing = false;
let delay_modal;
@@ -34,9 +35,11 @@ app.registerExtension({
if (showing || event.detail.id != self.id) {
return;
}
if (widget_time.value > 5) {
if (widget_time.value > 4 && widget_enable.value == true) {
bubbles();
}
showing = true;
delay_modal = domShowModal(`
<div class="jov-modal-content">
@@ -64,7 +67,6 @@ app.registerExtension({
showing = false;
window.bubbles_alive = false;
// app.canvas.setDirty(true);
}
async function python_delay_update() {
+16 -44
View File
@@ -12,47 +12,33 @@ export const bewm = function(ex, ey) {
const colors = [ '#ffc000', '#ff3b3b', '#ff8400' ];
const bubbles = 25;
const explode = (x, y) => {
const explode = () => {
let particles = [];
let ratio = window.devicePixelRatio;
let c = document.createElement('canvas');
let ctx = c.getContext('2d');
c.style.position = 'absolute';
c.style.left = (x - 100) + 'px';
c.style.top = (y - 100) + 'px';
c.style.pointerEvents = 'none';
c.style.width = 200 + 'px';
c.style.height = 200 + 'px';
c.style.zIndex = 100;
c.width = 200 * ratio;
c.height = 200 * ratio;
document.body.appendChild(c);
const ctx = app.canvas;
const canvas = ctx.getContext('2d');
ctx.style.pointerEvents = 'none';
for(var i = 0; i < bubbles; i++) {
particles.push({
x: c.width / 2,
y: c.height / 2,
x: canvas.width / 2,
y: canvas.height / 2,
radius: r(20, 30),
color: colors[Math.floor(Math.random() * colors.length)],
rotation: r(0, 360, true),
speed: r(8, 12),
speed: r(12, 16),
friction: 0.9,
opacity: r(0, 0.5, true),
yVel: 0,
gravity: 0.1
gravity: 0.15
});
}
render(particles, ctx, c.width, c.height);
setTimeout(() => document.body.removeChild(c), 1000);
render(particles, ctx);
}
const render = (particles, ctx, width, height) => {
requestAnimationFrame(() => render(particles, ctx, width, height));
ctx.clearRect(0, 0, width, height);
const render = (particles, ctx) => {
requestAnimationFrame(() => render(particles, ctx));
particles.forEach((p, i) => {
particles.forEach((p) => {
p.x += p.speed * Math.cos(p.rotation * Math.PI / 180);
p.y += p.speed * Math.sin(p.rotation * Math.PI / 180);
@@ -70,8 +56,6 @@ export const bewm = function(ex, ey) {
ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, false);
ctx.fill();
});
return ctx;
}
const r = (a, b, c) => parseFloat((Math.random() * ((a ? a : 1) - (b ? b : 0)) + (b ? b : 0)).toFixed(c ? c : 0));
@@ -85,14 +69,11 @@ export const bubbles = function() {
let mouseX;
let mouseY;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const particleArray = [];
class Particle {
constructor(mx = 0, my = 0) {
this.x = Math.random() * canvas.width;
this.y = canvas.height;
constructor() {
this.x = Math.random() * canvas.width * 0.85;
this.y = canvas.height * 0.85;
this.radius = Math.random() * 30;
this.dx = Math.random() - 0.5
this.dx = Math.sign(this.dx) * Math.random() * 1.27;
@@ -124,8 +105,6 @@ export const bubbles = function() {
}
move() {
// this.dx = (Math.random() - 0.5) * 2.27;
// this.dy = (Math.random() - 0.5) * 1.5;
this.x = this.x + this.dx + (Math.random() - 0.5) * 0.5;
this.y = this.y - this.dy + (Math.random() - 0.5) * 1.5;
@@ -158,25 +137,18 @@ export const bubbles = function() {
particleArray.push(particle);
}
} else {
canvas.removeEventListener("resize", handleResize);
canvas.removeEventListener("mousemove", handleMouseMove);
particleArray.length = 0; // Clear the particleArray
return;
}
};
const handleResize = () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
};
const handleMouseMove = (event) => {
mouseX = event.clientX;
mouseY = event.clientY;
};
canvas.addEventListener("resize", handleResize);
// canvas.addEventListener("mousemove", handleMouseMove);
canvas.addEventListener("mousemove", handleMouseMove);
animate();
}