హ్ట్మ్ల్ కాన్వాస్ టెక్స్ట్
కాన్వెక్స్ పైన పదాలు రాయండి
కాన్వెక్స్ పైన పదాలు రాయండి అనేది అత్యంత ముఖ్యమైన అంశం మరియు పద్ధతులు ఉన్నాయి:
- font - పదాల ఫాంట్ అంశాలను నిర్వహించడం
- fillText(text,x,y) - కాన్వెక్స్ పైన "ఫిల్ల్ చేసిన" పదాలు రాయండి
- strokeText(text,x,y) - కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ కాదు)
fillText() ఉపయోగించండి
ఉదాహరణ
ఫాంట్ని "30px Arial" గా సెట్ చేయండి మరియు కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ చేయండి):
జావాస్క్రిప్ట్:
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); ctx.font = "30px Arial"; ctx.fillText("హలో వరల్డ్", 10, 50);
strokeText() ఉపయోగించండి
ఉదాహరణ
ఫాంట్ని "30px Arial" గా సెట్ చేయండి మరియు కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ కాదు):
జావాస్క్రిప్ట్:
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); ctx.font = "30px Arial"; ctx.strokeText("హలో వరల్డ్", 10, 50);
రంగును జోడించి మధ్యలో వచ్చే పదాలు
ఉదాహరణ
ఫాంట్ని "30px Comic Sans MS" గా సెట్ చేయండి మరియు కాన్వెక్స్ మధ్యలో రెడ్ రంగుతో రాయండి:
జావాస్క్రిప్ట్:
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); ctx.font = "30px Comic Sans MS"; ctx.fillStyle = "red"; ctx.textAlign = "center"; ctx.fillText("హలో వరల్డ్", canvas.width/2, canvas.height/2);