I have a circular arc drawn in canvas is it possible to give it linear gradient with three colors??
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s possible! There is a method in Javascript, named
createLinearGradientwhich gets as source the canvas context and applies a gradient defined bysx,sy,dx,dycoordinates. The first two options defines the starting coordinates and last two the ending coordinates.After invoking this method you can apply gradient colors to your canvas by calling the
colorStopmethod:These are the basic ingredients for implementing a gradient on a canvas. The next step would be to calculate the circular color gradient positions if you need a circular gradient. This can be satisfied by the following formula:
Then plugin the resulted
xandyposition into the createLinearGradient method, which would create a nice looking circular gradient. Of course you need to use thearcmethod to make it circular.