看补充 这个代码保存为html 显示的是滚动的汉字。可不可以改下代码让它显示数字或者拼音。50积分奉上!

代码【</head>
<body>

<canvas id="q"></canvas>
<script type="text/javascript" >
var s = window.screen;
var width = q.width = s.width;
var height = q.height = s.height;
var letters = Array(256).join(1).split('');
var draw = function () {
q.getContext('2d').fillStyle='rgba(0,0,0,.05)';
q.getContext('2d').fillRect(0,0,width,height);
q.getContext('2d').fillStyle='#0F0';
letters.map(function(y_pos, index){
text = String.fromCharCode(3e4+Math.random()*33);
x_pos = index * 10;
q.getContext('2d').fillText(text, x_pos, y_pos);
letters[index] = (y_pos > 758 + Math.random() * 1e4) ? 0 : y_pos + 10;
});
};
setInterval(draw, 33);
</script>】

这个代码保存为html 显示的是滚动的汉字。可不可以改下代码让它显示数字或者拼音。50积分先奉上!然后再加五十。

产生随机字符的关键代码是:

text = String.fromCharCode(3e4 + Math.random() * 33);


如果想要数字的话,可以改成:

text = Math.floor(Math.random()*10);


如果想要英文字母的话,可以改成:

text = String.fromCharCode(65 + Math.floor(Math.random()*25))

追问

英文数字都要 麻烦呢 100

你好在吗

追答text = String.fromCharCode(48 + Math.floor(Math.random()*73)); // 10个数字、26个字母大小写都有了

追问

你好在吗

我追加了 50

麻烦看下 万谢

温馨提示:答案为网友推荐,仅供参考