Skip to content

Commit ed767be

Browse files
committed
making cloth translucent
1 parent 0728c87 commit ed767be

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/03-cloth.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<canvas id="scratch" style="width: 800px; height: 500px; background: #000;"></canvas>
1515
<script type="text/javascript">
1616

17+
function lerp(a, b, p) {
18+
return (b-a)*p + a;
19+
}
1720

1821
window.onload = function() {
1922
var canvas = document.getElementById("scratch");
@@ -61,7 +64,7 @@
6164
if (coef > 255)
6265
coef = 255;
6366

64-
ctx.fillStyle = "rgba(" + coef + ",0," + (255-coef)+ ",1)";
67+
ctx.fillStyle = "rgba(" + coef + ",0," + (255-coef)+ "," +lerp(0.25,1,coef/255.0)+")";
6568

6669
ctx.fill();
6770
}

0 commit comments

Comments
 (0)