paper-full+lodash实现可自定义的canvas文字句子拆分分散效果代码
代码语言:html
所属分类:其他
代码描述:paper-full+lodash实现可自定义的canvas文字句子拆分分散效果代码
代码标签: paper-full lodash 自定义 canvas 文字 句子 拆分 分散
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> * { margin: 0; padding: 0; border: none; font-family: serif; font-size: 20px; line-height: 1rem; box-sizing: border-box; } html, body { width: 100%; } body { padding: 3rem 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; background: #ddd; } canvas, input, .controls { border-radius: 0.25rem; } div, label { display: flex; } label { font-family: sans-serif; font-size: 0.9rem; font-variant-caps: all-small-caps; } .input-text { flex-direction: column; gap: 0.2rem; width: 512px; color: #777; } .input-text input { width: 100%; padding: 0.5rem 0.8rem; background: #fff; box-shadow: 0 0.25rem 0.333rem #0002 } .controls { width: 512px; padding: 1rem; flex-direction: column; gap: 1.5rem; background: #fff; box-shadow: 0 0.25rem 0.333rem #0002 } .controls > div { justify-content: space-between; } .controls label { gap: 0.5rem; } .input-colors, .input-colors > label, .input-sizes > label { align-items: center; } input[type=color] { padding: 0 0.1rem; border: 1px solid #0004; } </style> </head> <body> <canvas width=512 height=512></canvas> <label class=input-text> input some text here <input id=input type=text spellcheck=false value="The beautiful thing about learning is nobody can take it away from you."/> </label> <div class=controls> <div class=input-sizes> <label> font size <input id=fontsize type=range min=30 max=60 value=50 /> </label> <label> space size <input id=spacesize type=range min=6 max=16 value=9 /> </label> </div> <div class=input-colors> <label> <input id=bgcolor type=color value=#0000ff /> bg color </label> <label> <input id=paintcolor type=color value=#ffffff /> paint color </label> <label> <input id=invert type=checkbox /> invert spaces </label> </div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/paper-full.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/lodash.js"></script> <script > const canvas = document.querySelector("canvas") paper.setup(canvas) let INVERT = invert.checked, text = input.value, bg = bgcolor.value, paint = paintcolor.value, space = Array(+spacesize.value).fill(" ").join(""), size = fontsize.value, radius = size * 0.3, border = size * 0.3, padding = { h: size * 0.3, v: INVERT ? size * -0.1 : size * 0.1 } let rectGroup, textGroup, background const init = () => { background = new paper.Path.Rectangle({ point: [ 0, 0 ], size: [ paper.view.size.width, paper.view.size.height ], fillColor: bg, }) rectGroup = new paper.Group() rectGroup.style = { fillColor: paint, } textGroup = new paper.Group() textGroup.style = { fontFamily: "serif", fontSize: size, leading: size * 1.2, fillColor: INVERT ? paint : bg, } } const update = () => { init() handleContent.........完整代码请登录后点击上方下载按钮下载查看
网友评论0