# source-over - This is the default setting and draws new shapes on top of the existing canvas content. - 这是默认值。新图覆盖绘制在旧图上(保留旧图)
# source-in - The new shape is drawn only where both the new shape and the destination canvas overlap. Everything else is made transparent. - 新图只在与旧图重叠区域绘制(绘制区域外画布透明)
# source-out - The new shape is drawn where it doesn't overlap the existing canvas content. - 新图只在与旧图不重叠区域绘制(绘制区域外画布透明)
# source-atop - The new shape is only drawn where it overlaps the existing canvas content. - 新图只在与旧图重叠区域绘制(保留旧图)
# destination-over - New shapes are drawn behind the existing canvas content. - 新图覆盖绘制在旧图底下(保留旧图)
# destination-in - The existing canvas content is kept where both the new shape and existing canvas content overlap. Everything else is made transparent. - 新图与旧图的重叠区域作为蒙版裁剪旧图(重叠区域外画布透明)
# destination-out - The existing content is kept where it doesn't overlap the new shape. - 新图与旧图的非重叠区域作为蒙版裁剪旧图(重叠区域外画布透明)
# destination-atop - The existing canvas is only kept where it overlaps the new shape. The new shape is drawn behind the canvas content. - 新图只在与旧图的重叠区域绘制且绘制于旧图下(绘制区域外画布透明)
# lighter - Where both shapes overlap the color is determined by adding color values. - 重叠区域颜色矩阵相加
# copy - Only the new shape is shown. - 只显示新图
# xor - Shapes are made transparent where both overlap and drawn normal everywhere else. - 图像中,那些重叠和正常绘制之外的其他地方是透明的。
# multiply - The pixels are of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. - 重叠区域颜色矩阵相乘
# screen - The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) - 像素被倒转,相乘,再倒转,结果是一幅更明亮的图片。
# overlay - A combination of multiply and screen. Dark parts on the base layer become darker, and light parts become lighter. - multiply和screen的结合,原本暗的地方更暗,原本亮的地方更亮。
# darken - Retains the darkest pixels of both layers. - 保留两个图层中最暗的像素。
# lighten - Retains the lightest pixels of both layers. - 保留两个图层中最亮的像素。
# color-dodge - Divides the bottom layer by the inverted top layer. - 将底层除以顶层的反置。
# color-burn - Divides the inverted bottom layer by the top layer, and then inverts the result. - 将反置的底层除以顶层,然后将结果反过来。
# hard-light - A combination of multiply and screen like overlay, but with top and bottom layer swapped. - 屏幕相乘(A combination of multiply and screen)类似于叠加,但上下图层互换了。
# soft-light - A softer version of hard-light. Pure black or white does not result in pure black or white. - 用顶层减去底层或者相反来得到一个正值。
# difference - Subtracts the bottom layer from the top layer or the other way round to always get a positive value. - 一个柔和版本的强光(hard-light)。纯黑或纯白不会导致纯黑或纯白。
# exclusion - Like difference, but with lower contrast. - 和difference相似,但对比度较低。
# hue - Preserves the luma and chroma of the bottom layer, while adopting the hue of the top layer. - 保留了底层的亮度(luma)和色度(chroma),同时采用了顶层的色调(hue)。
# saturation - Preserves the luma and hue of the bottom layer, while adopting the chroma of the top layer. - 保留底层的亮度(luma)和色调(hue),同时采用顶层的色度(chroma)。
# color - Preserves the luma of the bottom layer, while adopting the hue and chroma of the top layer. - 保留了底层的亮度(luma),同时采用了顶层的色调(hue)和色度(chroma)。
# luminosity - Preserves the hue and chroma of the bottom layer, while adopting the luma of the top layer. - 保持底层的色调(hue)和色度(chroma),同时采用顶层的亮度(luma)。
① 准备两个canvas,一个是背景,只在图片载入的时候渲染一遍,一个是前景,用于合成前景图和绘图区域(destination-out)。事实上仅用一个canvas也能实现,每次绘图时先在画布上绘制前景图,然后把背景与绘图区域通过source-atop合成,再讲结果绘制到画布上。相较起来,前者性能显然会更好。
② 通过lineTo来涂抹绘图区域,而不是arc画圆,避免帧率过低时连线不平滑,因此当鼠标按下时,需要调用beginPath来重置画笔。