1+ <!--Made By Boujjou Achraf-->
2+ < html >
3+ < head >
4+ < style >
5+
6+ /*basic reset */
7+
8+ * {
9+ margin : 0 ;
10+ padding : 0 ;
11+ }
12+
13+ body {background : black;}
14+ canvas {display : block;}
15+
16+ </ style >
17+ </ head >
18+ < body >
19+
20+ < canvas id ="c "> </ canvas >
21+
22+ < script >
23+ // geting canvas by id c
24+ var c = document . getElementById ( "c" ) ;
25+ var ctx = c . getContext ( "2d" ) ;
26+
27+ //making the canvas full screen
28+ c . height = window . innerHeight ;
29+ c . width = window . innerWidth ;
30+
31+ //chinese characters - taken from the unicode charset
32+ var matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%" ;
33+ //converting the string into an array of single characters
34+ matrix = matrix . split ( "" ) ;
35+
36+ var font_size = 10 ;
37+ var columns = c . width / font_size ; //number of columns for the rain
38+ //an array of drops - one per column
39+ var drops = [ ] ;
40+ //x below is the x coordinate
41+ //1 = y co-ordinate of the drop(same for every drop initially)
42+ for ( var x = 0 ; x < columns ; x ++ )
43+ drops [ x ] = 1 ;
44+
45+ //drawing the characters
46+ function draw ( )
47+ {
48+ //Black BG for the canvas
49+ //translucent BG to show trail
50+ ctx . fillStyle = "rgba(0, 0, 0, 0.04)" ;
51+ ctx . fillRect ( 0 , 0 , c . width , c . height ) ;
52+
53+ ctx . fillStyle = "#0F0" ; //green text
54+ ctx . font = font_size + "px arial" ;
55+ //looping over drops
56+ for ( var i = 0 ; i < drops . length ; i ++ )
57+ {
58+ //a random chinese character to print
59+ var text = matrix [ Math . floor ( Math . random ( ) * matrix . length ) ] ;
60+ //x = i*font_size, y = value of drops[i]*font_size
61+ ctx . fillText ( text , i * font_size , drops [ i ] * font_size ) ;
62+
63+ //sending the drop back to the top randomly after it has crossed the screen
64+ //adding a randomness to the reset to make the drops scattered on the Y axis
65+ if ( drops [ i ] * font_size > c . height && Math . random ( ) > 0.975 )
66+ drops [ i ] = 0 ;
67+
68+ //incrementing Y coordinate
69+ drops [ i ] ++ ;
70+ }
71+ }
72+
73+ setInterval ( draw , 35 ) ;
74+
75+
76+ </ script >
77+ </ body >
78+ </ html >
0 commit comments