1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
//JS
//https://developer.mozilla.org/en/Canvas_tutorial/Applying_styles_and_colors
1. function draw() {
2. var ctx = document.getElementById('canvas').getContext('2d');
3.
4. // Create gradients
5. var lingrad = ctx.createLinearGradient(0,0,0,150);
6. lingrad.addColorStop(0, '#00ABEB');
7. lingrad.addColorStop(0.5, '#fff');
8. //lingrad.addColorStop(0.5, '#26C000');
9. //lingrad.addColorStop(1, '#fff');
10.
11. var lingrad2 = ctx.createLinearGradient(0,50,0,95);
12. lingrad2.addColorStop(0.5, '#000');
13. lingrad2.addColorStop(1, 'rgba(0,0,0,0)');
14.
15. // assign gradients to fill and stroke styles
16. ctx.fillStyle = lingrad;
17. ctx.strokeStyle = lingrad2;
18.
19. // draw shapes
20. ctx.fillRect(10,10,130,130);
21. ctx.strokeRect(50,50,50,50);
22.
23. } |
Partager