「空き時間グリッド」は Pro に含まれます。解除するとプレビューが表示されます。
「図形の当てはめ」は Pro に含まれます。解除するとプレビューが表示されます。
仕組み
センチメートル方眼の上で図形を当てはめる、教科書風の図です。手描きの輪郭は灰色のまま残り、当てはめた図形がアクセント色の線と淡い塗りで重なります。楕円と円は閉じたスケッチと面積・中心・二次モーメントが同じで、三角形はスケッチの凸包に収まる最大の三角形を同じ面積に拡大したものです。自動では、スケッチから輪郭までの RMS 距離が小さいほうを三角形と楕円から選びます。三角形の頂点は A・B・C、楕円の半軸は a・b、円の半径は r と表示されます。方眼の下に面積、その下に四つの測定値(RMS 誤差を含む)が並びます。
向いている場面
- Teach what fitting means: a model shape that is as close as possible to imperfect data, with its error shown next to it.
- Geometry exercises where learners sketch a triangle or an ellipse and read its angles, axes or area without measuring by hand.
向かない場面
- For drawing precise shapes for a design, use a shape tool with handles: the fit always follows the sketch.
使い方
import React, { useState } from 'react'
import { ContourPress } from './ContourPress.jsx'
// Points are centimetres on the 24 × 11 cm grid, origin top left
const sketch = [[12.5, 2], [19, 9], [5.5, 8.8]]
export function GeometryExercise() {
const [points, setPoints] = useState(sketch)
const [fit, setFit] = useState(null)
return (
<ContourPress
value={points}
onChange={(next, details) => {
setPoints(next)
setFit(details.fit)
}}
labels={{ title: 'Fit a triangle to a sketch' }}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
value | Array<[x: number, y: number]> | — | Controlled sketch: the outline's points in centimetres on the 24 × 11 grid, origin top left. The outline is closed from the last point back to the first. |
defaultValue | Array<[x: number, y: number]> | [] | Starting sketch when uncontrolled. |
onChange | (points, { reason, fit }) => void | — | Called when a sketch is finished or cleared. reason is 'draw', 'keyboard' or 'clear'; fit is null or { type, area, error } plus sides, angles and perimeter (triangle), semiAxes, rotation and eccentricity (ellipse) or radius and circumference (circle), all in centimetres and degrees. |
mode | 'auto' | 'triangle' | 'ellipse' | 'circle' | — | Controlled fit mode. 'auto' keeps whichever of the triangle and the ellipse lies closer to the sketch. |
defaultMode | 'auto' | 'triangle' | 'ellipse' | 'circle' | 'auto' | Starting fit mode when uncontrolled. |
onModeChange | (mode) => void | — | Called when a fit mode is chosen. |
holdMs | number | 400 | How long the pointer must rest while drawing before the fit is previewed (160–1500 ms). Lifting fits in any case. |
labels | object | — | Replaces any built-in text: title, sketch, fitted, grid ('{unit}'), unit, canvas, help, empty, keys, mode, modeAuto, modeTriangle, modeEllipse, modeCircle, clear, readoutTriangle, readoutEllipse, readoutCircle, readoutEmpty, readoutSmall, sides, angles, perimeter, semiAxes, rotation, eccentricity, radius, diameter, circumference, error, pointAdded ('{n}', '{x}', '{y}'), pointRemoved ('{n}'), fittedText ('{shape}', '{area}', '{error}') and cleared. |
locale | string | 'en' | Language tag for the decimal readouts. |
className | string | — | Extra class on the card, for example to set its width (30rem by default, never wider than its container). |
アクセシビリティ
- The grid is an application region with its instructions as its description. With the keyboard, arrows move a cross-hair by 0.5 cm (Shift: 2 cm), Space adds a point, Enter closes the outline and fits it, Backspace removes the last point and Escape drops the points. A hint with these keys shows while the grid has keyboard focus.
- The fit mode is a radio group: Tab reaches the chosen mode, arrows move and select. Clear is a button, marked unavailable while the grid is empty.
- A polite live region announces each added point and each fit with its area and error. The measurements are a description list under the grid.
- Drawing uses pointer capture and touch-action none on the grid only; a cancelled gesture or a lost window focus drops the stroke and keeps the previous sketch. A tap changes nothing.
モーション
While the pointer rests for holdMs a dashed preview of the fit appears; lifting fills it in, and a new fit fades in over --ds-duration-base. With reduced motion every change lands at once.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
ContourPress.jsxcontour-press.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。
同じカテゴリ
フォーム入力「図形のブール演算」は Pro に含まれます。解除するとプレビューが表示されます。
「カスケード選択」は Pro に含まれます。解除するとプレビューが表示されます。







