本文へ移動
日本語
「図形のブール演算」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

面積で集合演算を学ぶ教科書風の図です。円 A と三角形または正方形 B の輪郭が平面を三つの領域(A だけ、両方、B だけ)に分け、演算はその領域の選び方として表されます。左の図は作図で、選んだ領域に色が付き、領域をなぞると加えたり外したりできます。各図形の中心の丸で図形を動かせます。右の図は結果だけを塗りつぶして示します。見出しには演算名と面積の関係式、演算の下のボタンには各領域の面積、読み取り行には結果の面積が出ます。

向いている場面

  • Teach set operations with something you can measure: the union, intersection and differences of two shapes and the inclusion–exclusion identity for their areas.
  • Explain what union, subtract and intersect do in a vector drawing tool before learners use them.

向かない場面

  • For editing real vector paths, use a drawing tool: the shapes here are fixed in size.

使い方

import React, { useState } from 'react'
import { CampBadgePress } from './CampBadgePress.jsx'

export function SetLesson() {
  const [operation, setOperation] = useState('intersection')
  const [area, setArea] = useState(null)
  return (
    <CampBadgePress
      value={operation}
      onChange={(next, details) => {
        setOperation(next)
        setArea(details.area)
      }}
      shape="square"
      labels={{ title: 'Where two shapes overlap' }}
    />
  )
}

プロパティ

プロパティ型既定値説明
value'union' | 'intersection' | 'aMinusB' | 'bMinusA' | 'xor' | 'a' | 'b' | 'none'—Controlled result: the operation, or the set that the chosen regions make ('a', 'b' and 'none' are reached by sweeping or the region chips).
defaultValuestring'union'Starting result when uncontrolled, and what Reset returns to.
onChange(value, { reason, regions, area }) => void—Called with the new result and { reason ('operation', 'region', 'sweep', 'cancel' or 'reset'), regions ([A − B, A ∩ B, B − A] as 0 or 1), area (square units) }.
positions{ a: [x, y], b: [x, y] }—Controlled centres of the circle A and of shape B, in units on the 20 × 16 grid.
defaultPositions{ a: [x, y], b: [x, y] }{ a: [7.5, 8], b: [12.5, 8.6] }Starting centres when uncontrolled.
onPositionsChange(positions, { reason }) => void—Called while a shape is dragged or moved with the keys; reason is 'drag', 'key', 'cancel' or 'reset'.
shape'triangle' | 'square''triangle'Shape B: a triangle with base 10 and height 8, or a square with side 8. A is a circle of radius 5.
labelsobject—Replaces any built-in text: title, construction, result, operation, regions, names and formulas (objects keyed by result), regionNames (three), readout ('{set}'), empty, unit, moveA, moveB, help, regionText ('{name}', '{area}'), movedText ('{shape}', '{x}', '{y}', '{area}') and reset.
localestring'en'Language tag for the decimal readouts.
classNamestring—Extra class on the card, for example to set its width (30rem by default, never wider than its container).

アクセシビリティ

  • The operations are a radio group labelled with their names (the visible text is the symbol): Tab reaches the chosen one, arrows move and select.
  • Each region is a toggle button (aria-pressed) whose name includes its area; sweeping on the figure does the same with a pointer.
  • Each shape's knob is a focusable button: arrows move the shape by 0.5 units, Shift with an arrow by 2. A polite status announces the new position and the overlap.
  • The area of the result is a polite live region; the result figure is an image labelled with the result's name and area. Reset is a button, marked unavailable while nothing has changed.
  • Dragging uses pointer capture; a cancelled gesture restores the regions or the position it started from. The construction figure sets touch-action none so a sweep does not scroll the page.

モーション

Region fills fade for --ds-duration-base; a shape moved with the keys glides for --ds-duration-fast and follows the pointer directly while dragged. With reduced motion every change lands at once.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

CampBadgePress.jsxcamp-badge-press.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フォーム入力
「空き時間グリッド」は Pro に含まれます。解除するとプレビューが表示されます。
「カスケード選択」は Pro に含まれます。解除するとプレビューが表示されます。