Files
2nd/10_Wiki/Topics/Domain_Programming/Topic_HTML/HTML_Canvas.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

7.6 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
html-canvas HTML Canvas Frontend draft conceptual
canvas element
HTML5 Canvas
<canvas>
2d context
getContext
B 0.90 2026-06-23 2026-06-23
html
web
frontend
canvas
graphics
html5
w3schools
https://www.w3schools.com/html/html5_canvas.asp

HTML Canvas

🎯 한 줄 통찰 (One-line insight)

The HTML <canvas> element is an empty container for graphics; all actual drawing — lines, shapes, text, gradients, images — is done at runtime with JavaScript via a 2D drawing context. [S1]

🧠 핵심 개념 (Core concepts)

  • <canvas> is just a container — it has no drawing ability of its own; JavaScript draws into it. [S1]
  • It can draw paths, boxes, circles, text, and images, and is supported by all major browsers. [S1]
  • Always set id, width, and height — the id lets scripts reference it; width/height set its drawable size. A border style makes the otherwise invisible canvas visible. [S1]
  • The 2D context is the drawing surface — obtain it with canvas.getContext("2d"); all drawing methods (moveTo, lineTo, arc, fillText, etc.) are called on that context object. [S1]
  • Gradients — created with createLinearGradient(...) or createRadialGradient(...), then color stops are added and the gradient is assigned to fillStyle. [S1]

🧩 추출된 패턴 (Extracted patterns)

  • Setup patterngetElementByIdgetContext("2d") → draw. [S1]
  • Path/line patternmoveTo(x,y) then lineTo(x,y) then stroke(). [S1]
  • Circle patternbeginPath()arc(x,y,r,0,2*Math.PI)stroke(). [S1]
  • Text pattern — set font, then fillText(...) (filled) or strokeText(...) (outline). [S1]
  • Gradient fill pattern — create gradient → addColorStop() → assign to fillStylefillRect(...). [S1]
  • Image patterndrawImage(img, x, y) paints an existing image element. [S1]

📖 세부 내용 (Details)

What is HTML Canvas? The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics — you must use JavaScript to actually draw. Canvas can draw paths, boxes, circles, text, and add images, and it works in all major browsers. [S1]

The Canvas element — a canvas is a rectangular area on an HTML page, specified with the <canvas> element. Always specify an id (to refer to it in a script) and a width and height (to define its size). To add a border, use the style attribute: [S1]

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">
</canvas>

Draw a Line — [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.moveTo(0, 0);
ctx.lineTo(200, 100);
ctx.stroke();
</script>

Draw a Circle — [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95, 50, 40, 0, 2 * Math.PI);
ctx.stroke();
</script>

Draw Text — set the font and use fillText(text, x, y): [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World", 10, 50);
</script>

Stroke Text — set the font and use strokeText(text, x, y) for outlined text: [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.strokeText("Hello World", 10, 50);
</script>

Draw Linear Gradient — gradients can fill rectangles, circles, lines, text, etc. Create a linear gradient, add color stops, set it as the fill style, and fill a rectangle: [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Create gradient
var grd = ctx.createLinearGradient(0, 0, 200, 0);
grd.addColorStop(0, "red");
grd.addColorStop(1, "white");

// Fill with gradient
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 150, 80);
</script>

Draw Radial Gradient — [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Create gradient
var grd = ctx.createRadialGradient(75, 50, 5, 90, 60, 100);
grd.addColorStop(0, "red");
grd.addColorStop(1, "white");

// Fill with gradient
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 150, 80);
</script>

Draw Image — use drawImage(image, x, y) to paint an existing image element onto the canvas: [S1]

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("scream");
ctx.drawImage(img, 10, 10);
</script>

🛠️ 적용 사례 (Applied in summary)

The examples above are the canonical applied uses: drawing a diagonal line, a circle, filled and outlined text, linear and radial gradient-filled rectangles, and painting an existing image into the canvas. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Canvas setup + draw a line (HTML + JavaScript):

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.moveTo(0, 0);
ctx.lineTo(200, 100);
ctx.stroke();
</script>

Circle (JavaScript):

ctx.beginPath();
ctx.arc(95, 50, 40, 0, 2 * Math.PI);
ctx.stroke();

Linear gradient fill (JavaScript):

var grd = ctx.createLinearGradient(0, 0, 200, 0);
grd.addColorStop(0, "red");
grd.addColorStop(1, "white");
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 150, 80);

⚖️ 비교 및 선택 기준 (Comparison & decision criteria)

The source frames Canvas in contrast to SVG: SVG describes 2D graphics in XML, while Canvas draws 2D graphics on the fly with JavaScript. In Canvas, once a graphic is drawn it is "forgotten" by the browser (immediate-mode, pixel/bitmap output), whereas in SVG each drawn shape is remembered as an object and re-rendered on change (retained-mode). Canvas is resolution dependent, has no built-in event handlers, has poor text rendering, but can save the result as a .png/.jpg image and is well suited to graphic-intensive games. See HTML SVG for the complementary trade-offs. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

No contradictions found in the source. Note the immediate-mode nature: Canvas does not retain a scene graph, so anything that must be interactive or re-rendered on data change has to be redrawn manually by your script. [S1]

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.90
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "HTML Canvas" page (Astra wiki-curation, P-Reinforce v3.1 format).