Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Click and drag to draw!
css
html, body { width: 100%; height: 100%; margin: 0px; overflow: hidden; background-color: #F0F0F0; } html:hover span, body:hover span { display: none; } canvas { cursor: crosshair; } span { font-family: 'Georgia', cursive; font-size: 40px; position: fixed; top: 50%; left: 50%; color: #000; margin-top: -40px; margin-left: -200px; }
JavaScript
// Drawing with text. Ported from Generative Design book - http://www.generative-gestaltung.de - Original licence: http://www.apache.org/licenses/LICENSE-2.0 // Application variables var position = {x: 0, y: window.innerHeight/2}; var counter = 0; var minFontSize = 3; var angleDistortion = 0; var letters = "There was a table set out under a tree in front of the house, and the March Hare and the Hatter were having tea at it: a Dormouse was sitting between them, fast asleep, and the other two were using it as a cushion, resting their elbows on it, and talking over its head. 'Very uncomfortable for the Dormouse,' thought Alice; 'only, as it's asleep, I suppose it doesn't mind.'"; // Drawing variables var canvas; var context; var mouse = {x: 0, y: 0, down: false} function init() { canvas = document.getElementById( 'canvas' ); context = canvas.getContext( '2d' ); canvas.width = window.innerWidth; canvas.height = window.innerHeight; canvas.addEventListener('mousemove', mouseMove, false); canvas.addEventListener('mousedown', mouseDown, false); canvas.addEventListener('mouseup', mouseUp, false); canvas.addEventListener('mouseout', mouseUp, false); canvas.addEventListener('dblclick', doubleClick, false); window.onresize = function(event) { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } } function mouseMove ( event ){ mouse.x = event.pageX; mouse.y = event.pageY; draw(); } function draw() { if ( mouse.down ) { var d = distance( position, mouse ); var fontSize = minFontSize + d/2; var letter = letters[counter]; var stepSize = textWidth( letter, fontSize ); if (d > stepSize) { var angle = Math.atan2(mouse.y-position.y, mouse.x-position.x); context.font = fontSize + "px Georgia"; context.save(); context.translate( position.x, position.y); context.rotate( angle ); context.fillText(letter,0,0); context.restore(); counter++; if (counter > letters.length-1) { counter = 0; } //console.log (position.x + Math.cos( angle ) * stepSize) position.x = position.x + Math.cos(angle) * stepSize; position.y = position.y + Math.sin(angle) * stepSize; } } } function distance( pt, pt2 ){ var xs = 0; var ys = 0; xs = pt2.x - pt.x; xs = xs * xs; ys = pt2.y - pt.y; ys = ys * ys; return Math.sqrt( xs + ys ); } function mouseDown( event ){ mouse.down = true; position.x = event.pageX; position.y = event.pageY; document.getElementById('info').style.display = 'none'; } function mouseUp( event ){ mouse.down = false; } function doubleClick( event ) { canvas.width = canvas.width; } function textWidth( string, size ) { context.font = size + "px Georgia"; if ( context.fillText ) { return context.measureText( string ).width; } else if ( context.mozDrawText) { return context.mozMeasureText( string ); } }; init();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>用文本绘图-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号