Canvas
Biryani plate draw karo — JavaScript se pixel level control.
You know those beautiful biryani photos on restaurant websites? Now imagine drawing them yourself — not with a camera, but with code. Every grain of rice, every piece of mutton, every sprig of mint — drawn pixel by pixel using JavaScript.
The <canvas> element creates a blank drawing surface. Using the Canvas API (JavaScript), you can draw shapes, text, images, and animations. It's like having a digital paintbrush that follows your code.
Setting up Canvas:
<canvas id="myCanvas" width="600" height="400"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
// Now draw with ctx!
ctx.fillStyle = '#f97316'; // Orange color
ctx.fillRect(50, 50, 100, 80); // x, y, width, height
</script>- <canvas> — The blank surface. Set width and height.
- getContext('2d') — Get the drawing tool. Always needed.
- fillStyle — Color for filling shapes.
- strokeStyle — Color for borders/outlines.
- lineWidth — Thickness of lines.
Canvas lets you draw these shapes:
- fillRect / strokeRect — Rectangles and squares
- arc() — Circles, semi-circles, pie slices
- moveTo + lineTo — Lines and paths
- fillText / strokeText — Text with font styling
- createLinearGradient — Gradient fills
- drawImage — Draw images onto canvas
Draw a biryani plate using Canvas shapes.
<!-- canvas: 500x400 -->
<!-- Draw: plate oval, rice, meat pieces, mint garnish -->Done — Key Points:
- ✅ <canvas> creates a blank drawing surface
- ✅ getContext('2d') gets the drawing API
- ✅ fillRect, arc, moveTo/lineTo draw shapes
- ✅ fillStyle sets colors, gradients, patterns
- ✅ Canvas is pixel-based — animatable at 60fps
Want to track your progress?
Log in to save your place and pick up where you left off.
Progress track karna chahte ho?
Login karo apni progress save karne ke liye aur jahan chhoda tha wahan se shuru karo.
Login