Question

How can I integrate globalCompositeOperation(or any other plugin which will give me 'multiply' color manipulation) into jCanvas jQuery plugin?

// How do I get this working? //
var ctx = document.getElementById('canvas').getContext('2d');
ctx.globalCompositeOperation = 'darker';

// With this - //
$("canvas").drawArc({
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50
});

$("canvas").drawArc({
  fillStyle: "#395797",
  x: 170, y: 100,
  radius: 50,
  opacity: 1
});
Was it helpful?

Solution 2

Okay I solved it. After struggling with it for hours, it was too simple: I used context blender plugin.

JS code:

$("#canvasReal").drawArc({ // Draw on the real canvas
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50
});

$("#canvasOff").drawArc({ // Draw on the off screen canvas
  fillStyle: "#395797",
  x: 150, y: 100,
  radius: 50
});

// Blend off-screen canvas onto the real canvas
    var over = canvasOff.getContext('2d'); 
    var under = canvasReal.getContext('2d');
    over.blendOnto(under,'multiply'); 

HTML code:

<canvas width="500" height="250" id="canvasReal"></canvas>
<canvas width="500" height="250"id="canvasOff" style="display:none;"></canvas>

OTHER TIPS

For the record, jCanvas has a compositing property, the value for which maps to ctx.globalCompositeOperation.

$("canvas").drawArc({
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50,
  compositing: 'darker'
});

-Caleb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top