Qu

Language & UI

Interactive sliders

QuStudio's Interactive Mode, as an actual catalog demo (previously this feature had NO dedicated demo -- only an inline default script baked into QuStudio's InteractiveModePanel.tsx component, never saved as a real, standalone .qu file anyone could open,

catalog/qu_interactive_sliders.qu

read, or run on its own outside the IDE).

What "Interactive Mode" actually is (verified against qu-studio-tauri/src/InteractiveModePanel.tsx, not guessed): a special comment syntax, `# @slider name min max step`, that QuStudio's UI scans for and renders as a real slider widget. Dragging a slider rewrites that variable's literal value in the script text, re-runs the whole script via `qu run --emit-data` (see main.rs's --emit-data flag, which dumps every top-level numeric variable as JSON), and re-plots whatever 2D/3D data came back -- debounced 300ms so dragging feels live, not laggy. This is QuStudio-specific tooling, not a Qu language feature: `qu run` on this file directly (no --emit-data) just runs it once with freq/amp/phase at their fixed starting values below, exactly like any other script -- the "interactive" part is entirely in how the IDE re-invokes it, not something this file does on its own.

Deliberately exercises BOTH plot shapes Interactive Mode supports from one script: a 3D grid (z, surface/scatter3d in the UI) and a plain 2D curve (y2), so switching view modes always has real data to show.

What it exercises

Results

printed
freq=3 amp=1 phase=0
z[0,0]=0.0307  z[39,39]=0.0307
y2[0]=-0.4121  y2[39]=0.4121
open this file in QuStudio's Interactive Mode to get real sliders for freq/amp/phase

The whole program

Runnable as it stands: qu run catalog/qu_interactive_sliders.qu

# qu_interactive_sliders.qu -- QuStudio's Interactive Mode, as an actual

# catalog demo (previously this feature had NO dedicated demo -- only an

# inline default script baked into QuStudio's InteractiveModePanel.tsx

# component, never saved as a real, standalone .qu file anyone could open,

# read, or run on its own outside the IDE).

#

# What "Interactive Mode" actually is (verified against

# qu-studio-tauri/src/InteractiveModePanel.tsx, not guessed): a special

# comment syntax, `# @slider name min max step`, that QuStudio's UI scans

# for and renders as a real slider widget. Dragging a slider rewrites that

# variable's literal value in the script text, re-runs the whole script via

# `qu run --emit-data` (see main.rs's --emit-data flag, which dumps every

# top-level numeric variable as JSON), and re-plots whatever 2D/3D data

# came back -- debounced 300ms so dragging feels live, not laggy. This is

# QuStudio-specific tooling, not a Qu language feature: `qu run` on this

# file directly (no --emit-data) just runs it once with freq/amp/phase at

# their fixed starting values below, exactly like any other script -- the

# "interactive" part is entirely in how the IDE re-invokes it, not

# something this file does on its own.

#

# Deliberately exercises BOTH plot shapes Interactive Mode supports from

# one script: a 3D grid (z, surface/scatter3d in the UI) and a plain 2D

# curve (y2), so switching view modes always has real data to show.

#

# Constructs exercised (all real, verified-working builtins):

#   linspace, zeros, nested for, sqrt/sin -- ordinary numeric code, nothing

#   Interactive-Mode-specific at the LANGUAGE level; the `# @slider ...`

#   lines are comments as far as `qu run` is concerned, meaningful only to

#   QuStudio's own scanner.


backend auto

# @slider freq 1 10 0.5

freq = 3
# @slider amp 0.1 3 0.1

amp = 1
# @slider phase 0 6.28 0.1

phase = 0

N = 40
xs = linspace(-3, 3, N)
ys = linspace(-3, 3, N)

Z = zeros(N, N)
for i = 1 to N
    for j = 1 to N
        r = sqrt(xs[i-1]^2 + ys[j-1]^2)
        Z[i-1, j-1] = amp * sin(freq * r + phase) / (r + 1)
    end for
end for

x = xs
y = ys
z = Z

# A plain 2D curve too, for 2D mode: x vs y2.

y2 = amp * sin(freq * xs + phase)

print("freq={freq} amp={amp} phase={phase}")
print("z[0,0]={z[0,0]:.4f}  z[{N-1},{N-1}]={z[N-1,N-1]:.4f}")
print("y2[0]={y2[0]:.4f}  y2[{N-1}]={y2[N-1]:.4f}")
print("open this file in QuStudio's Interactive Mode to get real sliders for freq/amp/phase")