五种酷炫代码⾬的源代码1.脚本篇
@echo off
color 0a
:start
set num=0
set"echos= "
:num
set /a a1=%random%%%3
if"%a1%"=="1"set"a1= "
if"%a1%"=="2"set"a1= "
if"%a1%"=="0"set /a a1=%random%%%2
set echos=%echos%%a1%
set /a num=%num%+1
if"%num%"=="75"echo %echos%&&goto :start
goto :num
%0
使⽤步骤:
1.新建⽂本⽂档,重命名将后⾯的txt改成bat
2.右键选择编辑,进⼊⽂件
3.复制粘贴代码,保存
4.双击打开运⾏
2.超⽂本篇
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
html,body{width:100%;height:100%;}
body{
background: #000;
overflow: hidden;
margin:0;
padding:0;
}
</style>
</head>
<body>
<canvas id="cvs"></canvas>
<script type="text/javascript">
var cvs = ElementById("cvs");
var ctx = Context("2d");
var cw = cvs.width = document.body.clientWidth;
var ch = cvs.height = document.body.clientHeight;
//动画绘制对象
var requestAnimationFrame = questAnimationFrame || RequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var codeRainArr =[];//代码⾬数组
var cols =parseInt(cw/14);//代码⾬列数
var step =16;//步长,每⼀列内部数字之间的上下间隔
ctx.font ="bold 26px microsoft yahei";//声明字体,个⼈喜欢微软雅⿊
function createColorCv(){
//画布基本颜⾊
ctx.fillStyle="#242424";
ctx.fillRect(0,0,cw,ch);
}源代码1080p在线
//创建代码⾬
function createCodeRain(){
for(var n =0; n < cols; n++){
var col =[];
//基础位置,为了列与列之间产⽣错位
var basePos =parseInt(Math.random()*300);
//随机速度 3~13之间
var speed =parseInt(Math.random()*10)+3;
//每组的x轴位置随机产⽣
var colx =parseInt(Math.random()*cw)
//绿⾊随机
var rgbr=0;
var rgbg=parseInt(Math.random()*255);
var rgbb=0;
//ctx.fillStyle = "rgb("+r+','+g+','+b+")"
for(var i =0; i <parseInt(ch/step)/2; i++){
var code ={
x : colx,
y :-(step*i)-basePos,
speed : speed,
//                            text : parseInt(Math.random()*10)%2 == 0 ? 0 : 1  //随机⽣成0或者1
text :["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","s","t","u","v","w","x","y","z"][parseInt(Math.random()*11)],//随机⽣成字母数组中的⼀个
color :"rgb("+rgbr+','+rgbg+','+rgbb+")"
}
col.push(code);
}
codeRainArr.push(col);
}
}
//代码⾬下起来
function codeRaining(){
//把画布擦⼲净
ctx.clearRect(0,0,cw,ch);
/
/创建有颜⾊的画布
//createColorCv();
for(var n =0; n < codeRainArr.length; n++){
//取出列
col = codeRainArr[n];
//遍历列,画出该列的代码
for(var i =0; i < col.length; i++){
var code = col[i];
if(code.y > ch){
//如果超出下边界则重置到顶部
code.y =0;
}else{
//匀速降落
code.y += code.speed;
}
//颜⾊也随机变化
//颜⾊也随机变化
//ctx.fillStyle = "hsl("+(parseInt(Math.random()*359)+1)+",30%,"+(50-i*2)+"%)"; //绿⾊逐渐变浅
//ctx.fillStyle = "hsl(123,30%,"+(30-i*2)+"%)";
//绿⾊随机
//var r= 0;
//var g= parseInt(Math.random()*255) + 3;
/
/var b= 0;
//ctx.fillStyle = "rgb("+r+','+g+','+b+")"
ctx.fillStyle = lor;
//把代码画出来
ctx.,code.x,code.y);
}
}
requestAnimationFrame(codeRaining);
}
//创建代码⾬
createCodeRain();
/
/开始下⾬吧 GO>>
requestAnimationFrame(codeRaining);
</script>
</body>
</html>
使⽤步骤:
1.新建⽂本⽂档,重命名将txt改成html
2.右键编辑,进⼊⽂档
3.复制粘贴代码,保存
4.双击打开运⾏
3.Java篇(需要Java环境)
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.MemoryImageSource;
import java.util.Random;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.Timer;
public class test extends JDialog implements ActionListener {
private Random random =new Random();
private Dimension screenSize;
private JPanel graphicsPanel;
//⾏⾼,列宽
private final static int gap =20;
//存放⾬点顶部的位置信息(marginTop)
private int[] posArr;
//⾏数
private int lines;
//列数
private int columns;
public test(){
initComponents();
}
}
private void initComponents(){
setLayout(new BorderLayout());
graphicsPanel =new GraphicsPanel();
add(graphicsPanel, BorderLayout.CENTER);
//设置光标不可见
Toolkit defaultToolkit = DefaultToolkit();
Image image = ateImage(new MemoryImageSource(0,0, null,0,0));
Cursor invisibleCursor = ateCustomCursor(image,new Point(0,0),"cursor");
setCursor(invisibleCursor);
//ESC键退出
KeyPressListener keyPressListener =new KeyPressListener();
this.addKeyListener(keyPressListener);
//this.setAlwaysOnTop(true);
//去标题栏
this.setUndecorated(true);
//全屏
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setVisible(true);
screenSize = DefaultToolkit().getScreenSize();
lines = screenSize.height / gap;
columns = screenSize.width / gap;
posArr =new int[columns +1];
random =new Random();
for(int i =0; i < posArr.length; i++){
posArr[i]= Int(lines);
}
//每秒10帧
new Timer(100,this).start();
}
/**
* @return 随机字符
*/
private char getChr(){
return(char)(Int(94)+33);
}
@Override
public void actionPerformed(ActionEvent e){
}
private class GraphicsPanel extends JPanel {
@Override
public void paint(Graphics g){
Graphics2D g2d =(Graphics2D) g;
g2d.setFont(getFont().deriveFont(Font.BOLD));
g2d.setColor(Color.BLACK);
g2d.fillRect(0,0, screenSize.width, screenSize.height);
//当前列
int currentColumn =0;
for(int x =0; x < screenSize.width; x += gap){
int endPos = posArr[currentColumn];
g2d.setColor(Color.CYAN);
g2d.drawString(String.valueOf(getChr()), x, endPos * gap);
int cg =0;
for(int j = endPos -15; j < endPos; j++){
//颜⾊渐变
cg +=20;
if(cg >255){
if(cg >255){
cg =255;
}
g2d.setColor(new Color(0, cg,0));
g2d.drawString(String.valueOf(getChr()), x, j * gap);
}
//每放完⼀帧,当前列上⾬点的位置随机下移1~5⾏
posArr[currentColumn]+= Int(5);
//当⾬点位置超过屏幕⾼度时,重新产⽣⼀个随机位置
if(posArr[currentColumn]* gap >getHeight()){
posArr[currentColumn]= Int(lines);
}
currentColumn++;
}
}
}
private class KeyPressListener extends KeyAdapter {
@Override
public void keyPressed(KeyEvent e){
KeyCode()== KeyEvent.VK_ESCAPE){
}
}
}
public static void main(String[] args){
new test();
}
}
使⽤步骤:
1.如⼀⼆所⽰,建⽴Java⽂件
2.编译运⾏
4.c++篇
#include<stdio.h>
#include<time.h>
#include<Windows.h>
#include<graphics.h>
#define WIDTH 960
#define HEIGHT 640
#define STR_SIZE 20
#define STR_NUM 128
#define STR_WIDTH 15
typedef struct Rain
{
int x;
int y;
int speed;
TCHAR str[STR_SIZE];
}Rain;
Rain rain[STR_NUM];
// 随机⽣成⼀个字符
char CreateCh()
{
char ch =0;
int flag =rand()%3;// 0~2
if(flag ==0)
ch =rand()%26+'a';// 产⽣⼩写字母a~z

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。