HTML कैनवस रेखाकार
- ऊपरी पृष्ठ Canvas आकार
- निचला पृष्ठ Canvas वृत्त
उदाहरण
150*100 पिक्सल का चतुर्भुज दूरी बनाएं:
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.rect(20, 20, 150, 100); ctx.stroke();
rect() विधि
rect() विधि पथ को एक चतुर्भुज जोड़ती है。
व्याकरण:
context.rect(x, y, width, height)
पारामीटर | वर्णन |
---|---|
x | चतुर्भुज के बाहरी शीर्ष के x स्थानांक |
y | चतुर्भुज के बाहरी शीर्ष के y स्थानांक |
width | चतुर्भुज की चौड़ाई पिक्सल में。 |
height | चतुर्भुज की ऊंचाई पिक्सल में。 |
और अधिक उदाहरण
उदाहरण
rect() विधि से तीन चतुर्भुजों को बनाएं:
जेवास्क्रिप्ट:
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); // लाल चतुर्भुज ctx.beginPath(); ctx.lineWidth = "6"; ctx.strokeStyle = "red"; ctx.rect(5, 5, 290, 140); ctx.stroke(); // हरा चतुर्भुज ctx.beginPath(); ctx.lineWidth = "4"; ctx.strokeStyle = "green"; ctx.rect(30, 30, 50, 50); ctx.stroke(); // नीला चतुर्भुज ctx.beginPath(); ctx.lineWidth = "10"; ctx.strokeStyle = "blue"; ctx.rect(50, 50, 150, 80); ctx.stroke();
अन्य देखें:
- ऊपरी पृष्ठ Canvas आकार
- निचला पृष्ठ Canvas वृत्त