UNPKG

@reis/seki

Version:

Seki – A modern javascript based Go board renderer and player, that is simple to use, extensible, compact and intuitive.

99 lines (82 loc) 1.92 kB
import Markup from './markup.js' import {markupTypes} from '../../constants/markup.js' /** * Sad smiley markup */ export default class MarkupSad extends Markup { //Type type = markupTypes.SAD //Additional properties lineCap /** * Load additional properties for this markup type */ loadProperties(x, y) { //Load parent properties const args = super.loadProperties(x, y) //Load additional properties this.loadThemeProp('lineCap', ...args) //Pass on args return args } /** * Get grid erase radius */ getGridEraseRadius() { return this.radius * 0.8 } /** * Draw */ draw(context, x, y) { //Parent draw super.draw(context, x, y) //Get data const {radius, color, lineWidth, lineCap} = this const absX = this.getAbsX(x) const absY = this.getAbsY(y) //Deltas const dEye = Math.round(radius * 0.36) const dxMouth = Math.round(radius * 0.6) const dyMouth = Math.round(radius * 0.6) const dxCp = Math.round(radius * 0.4) const dyCp = 0 //Prepare context this.prepareContext(context) //Configure context context.fillStyle = color context.strokeStyle = color context.lineWidth = lineWidth context.lineCap = lineCap //Draw element context.beginPath() context.arc( absX - dEye, absY - dEye, Math.round(radius / 6), 0, 2 * Math.PI, true ) context.fill() context.beginPath() context.arc( absX + dEye, absY - dEye, Math.round(radius / 6), 0, 2 * Math.PI, true ) context.fill() context.beginPath() context.moveTo(absX - dxMouth, absY + dyMouth) context.bezierCurveTo( absX - dxCp, absY + dyCp, absX + dxCp, absY + dyCp, absX + dxMouth, absY + dyMouth ) context.stroke() //Restore context this.restoreContext(context) } }