summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/filters/canvas-opacity-blend-modes-expected.html
blob: 3eb75819818a8d9aa4ee0f9f1c15cab08a3b7613 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<body>
</body>
<script>
  /*
  Compare how the opacity is handled in different blend modes when setting its
  value with filters or with properties.
  */

  function drawSquares(canvasId, x, y, compositeOperation) {
    var canvas = document.getElementById(canvasId);
    var ctx = canvas.getContext('2d');
    canvas.style.position = 'absolute';
    canvas.style.left = `${x}px`;
    canvas.style.top = `${y}px`;

    ctx.globalCompositeOperation = 'source-over';
    ctx.globalAlpha = 1.0;
    ctx.fillStyle = 'green';
    ctx.fillRect(0, 0, 200, 60);
    ctx.fillStyle = 'blue';
    ctx.fillRect(0, 0, 50, 50);
    ctx.globalAlpha = 0.7;
    ctx.fillStyle = 'red';
    ctx.fillRect(50, 0, 50, 50);
    ctx.globalCompositeOperation = compositeOperation;
    ctx.globalAlpha = 0.5;
    ctx.fillStyle = 'yellow';
    ctx.fillRect(25, 25, 50, 50);
  }

  // Fomatted in the same matrix as the drawn elements.
  var compositeOperations =
    ['source-over', 'source-in', 'source-out', 'source-atop','destination-over',
    'destination-in', 'destination-out', 'destination-atop', 'lighter', 'copy',
    'xor', 'multiply', 'screen', 'overlay', 'darken',
    'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light',
    'difference', 'exclusion', 'hue', 'saturation', 'color',
    'luminosity'];

  for (var i = 0; i < compositeOperations.length; i++){
    var canvas = document.createElement('canvas');
    canvas.id = `canvas-${i}`;
    document.body.appendChild(canvas);
    drawSquares(canvas.id, (i%5)*300, Math.floor(i/5)*300,
      compositeOperations[i]);
  }
</script>