算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
constraint【设计与创意】Use this skill whenever the design must structurally prevent invalid actions — input validation, disabled states, required fields, type-restricted inputs, mode locks, role-based gates, hardware lockouts. Trigger when designing forms, picking input types, designing destructive flows, gating multi-step procedures, or thinking about how to prevent a cla…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
A constraint is anything that limits the actions a user can perform on a system. Some constraints are physical (you can't insert a USB-C connector upside-down because the shape rejects it). Some are psychological (you don't try to push a door labeled "PULL" because the convention overrides the impulse). Both kinds work upstream of error: instead of catching wrong actions after they happen, constraints make wrong actions hard or impossible.
A constraint is a deliberate limitation on what the user can do. The limitation may be implemented in the physical structure of the design (a slot that only accepts one shape), in the system's software (a button disabled until preconditions are met), or in the user's psychology (a convention that makes the wrong action feel obviously wrong). All three reduce error rates dramatically — constraints are usually cheaper than recovery, because they prevent the recovery from being needed.
Every error you prevent at the design layer is an error you don't have to detect, recover from, explain, or apologize for. Constraints are the design layer's strongest move because they operate before error occurs:
The discipline: when you're tempted to add a confirmation, ask first whether a constraint would do the same job better. Often yes.
In hardware, physical constraints are the shape of an object directing how it can be used.
The book identifies three subtypes:
Channels that direct motion. Examples:
In software UI: a slider input is a path constraint — the user can only move along one dimension.
Rotary controls. Convert applied force into rotation. Examples:
In software UI: rotation gestures, dial inputs, the "spin" of an iOS time picker.
Block, slow, or redirect motion. Examples:
In software UI: a modal dialog blocks interaction with the page beneath; a permission gate blocks access to a feature.
Constraints that don't physically prevent action but lean on perception, convention, or knowledge.
The book identifies three subtypes:
Communicate meaning through language and iconography. Examples:
In software UI: a "Disabled" badge; a "Restricted" tooltip; a warning icon.
Learned practices. Examples:
Conventions are a constraint because the user expects certain actions to do certain things; design that conforms is constrained-by-convention to behave as expected.
Perceived relationships between controls and effects. Examples:
Good mappings constrain user error by making the wrong action feel wrong.
Constraints that don't reflect real requirements feel arbitrary and frustrating:
The discipline: constrain real requirements; communicate the constraint clearly when it surprises.
<input type="email" required maxlength="254" autocomplete="email" />
<input type="tel" inputmode="numeric" pattern="[0-9-]+" />
<input type="number" min="0" max="999" step="1" />
The browser enforces the constraints. type="email" rejects malformed emails; min="0" rejects negative numbers. The user can't submit invalid input.
<form id="signup">
<input name="email" type="email" required />
<input name="password" type="password" required minlength="12" />
<button id="submit" disabled>Create account</button>
</form>
<script>
const form = document.getElementById('signup');
const btn = document.getElementById('submit');
form.addEventListener('input', () => {
btn.disabled = !form.checkValidity();
});
</script>
Submit can't trigger until the form is valid. Pair with inline validation messages so the user knows what's missing.
function DeleteButton({ project, currentUser }) {
const canDelete = currentUser.role === 'admin' || project.ownerId === currentUser.id;
if (!canDelete) {
return null; // hide entirely; user can't even attempt
}
return <button onClick={confirmDelete}>Delete project</button>;
}
Users without permission don't see the button. The wrong action can't happen.
The destructive button is disabled until the user types the resource name. The constraint converts a single click into a deliberate multi-step action.
<dialog>
<h2>Delete workspace "Acme Inc"?</h2>
<p>This cannot be undone. Type <strong>Acme Inc</strong> to confirm:</p>
<input id="confirm" />
<button id="delete-btn" disabled class="destructive">Delete workspace</button>
</dialog>
<script>
document.getElementById('confirm').addEventListener('input', e => {
document.getElementById('delete-btn').disabled = e.target.value !== 'Acme Inc';
});
</script>
A drag-and-drop with a strict drop-zone restriction:
function isValidDropTarget(item, target) {
if (item.type === 'file' && target.acceptsFiles) return true;
if (item.type === 'folder' && target.acceptsFolders) return true;
return false;
}
dropZone.addEventListener('dragover', e => {
if (isValidDropTarget(draggedItem, dropZone)) {
dropZone.classList.add('drop-valid');
e.preventDefault(); // allow drop
} else {
dropZone.classList.add('drop-invalid');
// do not preventDefault — drop won't fire
}
});
The browser's drag-and-drop API itself is a constraint mechanism: not preventing default during dragover prevents the drop. The user can't complete the wrong drop.
USB-C connectors have rotational symmetry — they fit either way. USB-A connectors do not. Generations of users have struggled with the USB-A "flip the cable to insert it correctly" failure. USB-C eliminated the failure mode at the design layer; no error to recover from.
The lesson for software: when you can change the design so the failure can't happen, do that.
The auto-pilot can be disengaged by pulling back firmly on the yoke. The disengagement is constrained — a casual touch doesn't trigger it, a firm pull does. The constraint matches the seriousness of the action.
A child-safety cap requires push-and-twist simultaneously. The constraint reduces accidental childhood poisoning dramatically. The cost: arthritic adults sometimes struggle with the cap. Trade-off acknowledged; the design is calibrated to the population at greatest risk.
Equipment that requires continuous operator engagement (a hand on the trigger, a foot on the pedal) shuts off if the operator becomes incapacitated. The constraint protects against operator failure.
Modern security designs constrain code to only the capabilities it explicitly needs. A web page can't read your filesystem; an app can't access your microphone without explicit permission; a sandbox limits what an embedded program can do. Each is a constraint at the system layer.
affordance — affordance suggests what can be done; constraint limits what can't. Companion principles.mapping — good mapping is a psychological constraint that makes wrong actions feel wrong.forgiveness — when constraint isn't possible, forgiveness handles the recovery.errors — constraints prevent the slip and mistake categories of error.expectation-effect — constraints work better when they match user expectation.visibility — constraints must be visible to be navigable.constraint-physical — paths, axes, barriers; structural constraints in physical or screen-equivalent form.constraint-psychological — symbols, conventions, mappings; the constraint of expectation and learned practice.Constraint is one of the most powerful design tools and one of the most under-used. The reflexive design move on encountering an error is to add a confirmation or improve recovery; the better move, when possible, is to make the wrong action structurally impossible. Constraints are unglamorous but pay continuously across every user, every day.