原生js+canvas实现骰子作图

编程入门 行业动态 更新时间:2024-10-08 20:38:28

原生js+canvas实现<a href=https://www.elefans.com/category/jswz/34/1739690.html style=骰子作图"/>

原生js+canvas实现骰子作图

最终效果大家可以试一下:,上传图片后记得要点一下那个start(那个滑动条最好不要拉到最左边去了,虽然渲染出的最接近原图,但cpu不好的同学浏览器会卡死)。

其实这个个人小玩意早在几个月前就做好了,主要就是用大小不一的点(或其他)来重新绘制图片。

首先在一个闭包中进行初始化,并进行原生代码的封装

(function(doc){var concatImg = {init(){var getId = doc.getElementById.bind(doc)this.file = getId('uoploadImg')this.cas = getId('canvas')this.canvas = doc.createElement('canvas')this.ctx = this.cas.getContext('2d')this.ctx2 = this.canvas.getContext('2d')this.img = new Image()this.fr = new FileReader()this.range = getId('range')this.autoCalc = getId('autocalc')this.trigger = getId('start')this.colour = getId('colour')this.path = getId('pathinfo')this.selection = getId('selection')this.maxUnitPixel = +this.range.valuethis.unitPixelColor = this.colour.valuethis.isAutoCalc = this.autoCalc.checkedthis.selectionValue = this.selection.valuethis.pixelCollection =[...'1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}|:"<>?-=[]\\;\',./`~']this.pixelCollectionLen = this.pixelCollection.lengththis.drawDetail = this.primitiveDrawDetailthis.bindEvent.call(this)},
}
}(document)

这里是表单控制

<div class="row">
    <div class="col-lg-4">
        <div class="input-group">
            <section class="input-group-btn">
                <button class="btn btn-success" type="button" id="start">Start</button>
            </section>
            <input type="text" class="form-control" placeholder="name of the file:" id="pathinfo">
            <input type="file" id="uoploadImg" class="form-control" accept="image/*">
            <span class="input-group-addon">auto calculate:
                <input type="checkbox" aria-label="..." id="autocalc">
            </span>
        </div>
        <select id="selection" class="form-control">
            <option value="1">dot</option>
            <option value="2">character</option>
            <option value="3">brick</option>
        </select>
    </div>
    <div class="col-lg-2">
        long of side setting:

更多推荐

原生js+canvas实现骰子作图

本文发布于:2024-03-23 15:17:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1739691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:骰子   js   canvas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!