ពណ៌​ប្រដេញ

នៅ​ក្នង​គំនូរ 2D នៅ​លើ​ធាតុ canvas យើង​អាច​បង្កើត​ ពណ៌​ប្រដេញ (gradient) ​បាន​គ្រប់​បែប​យ៉ាង សំរាប់​ដាក់​អោយ​រូប​និង​អត្ថបទ​គ្រប់​ប្រភេទ​។ យ៉ាងណាម៉ិញ ពណ៌​ប្រដេញ​មាន ២ ប្រភេទ​គឺ ពណ៌​ប្រដេញ​ត្រង់ (linear gradient) និង ពណ៌​ប្រដេញ​មូល (radial/circular gradient) ។ នៅ​ក្នុងការបង្កើត​ពណ៌​ប្រដេញ​ត្រង់ ​យើង​ត្រូវ​យក​វិធី​មាន​ស្រាប់​ឈ្មោះ createLinearGradient(x,y,x1,y1) មក​ប្រើ ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖



ស្រដៀង​គ្នា​ដែរ នៅ​ក្នុង​ការបង្កើត​ពណ៌​ប្រដេញ​មូល យើង​ចាំបាច់​ត្រូវ​យក​វិធី​មាន​ស្រាប់​ឈ្មោះ reateRadialGradient(x,y,r,x1,y1,r1) មក​ប្រើ​ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖



Colors, Styles, and Shadows
Method Description
createLinearGradient() Creates a linear gradient (to use on canvas content)
createPattern() Repeats a specified element in the specified direction
createRadialGradient() Creates a radial/circular gradient (to use on canvas content)
addColorStop() Specifies the colors and stop positions in a gradient object
fillStyle Sets or returns the color, gradient, or pattern used to fill the drawing
strokeStyle Sets or returns the color, gradient, or pattern used for strokes
shadowColor Sets or returns the color to use for shadows
shadowBlur Sets or returns the blur level for shadows
shadowOffsetX Sets or returns the horizontal distance of the shadow from the shape
shadowOffsetY Sets or returns the vertical distance of the shadow from the shape