Hello.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="hello.css">
  5. <meta charset="UTF-8">
  6. <title>Hello</title>
  7. </head>
  8. <body>
  9. <script>
  10. let host = 'http://127.0.0.1:5000/'
  11. </script>
  12. <canvas id="canvas" class="bg_canvas"></canvas>
  13. <div class="screen">
  14. <div id='cotanTitle' class="cotan_title">
  15. </div>
  16. <div id="method" class="mode">
  17. <h1 class="mode">CoTan<br>科学计算系统</h1>
  18. <h2 class="mode">CoTan工具</h2>
  19. <script>
  20. function start(mode_url){
  21. current_circle.add();
  22. let xhr = new XMLHttpRequest();
  23. xhr.onloadend = function () {
  24. console.log('run');
  25. if (xhr.status === 200) {
  26. current_circle.remove();
  27. }};
  28. xhr.open('get',host + mode_url,true);
  29. xhr.send();
  30. }
  31. </script>
  32. <button type="button" id="board" class="button white big" onclick="start('draftboard')">CoTan草稿板</button>
  33. <div class="nothing"></div>
  34. <button type="button" id="selenium" class="button white big" onclick="start('crawler')">自动化网页</button>
  35. <div class="nothing"></div>
  36. <button type="button" id="git" class="button white small" onclick="start('git')">git仓库控制器</button>
  37. <div class="nothing"></div>
  38. <button type="button" id="website" class="button white small" onclick="window.open('https://cotan.songzh.website');">CoTan社区</button>
  39. <h2 class="mode">数学系统</h2>
  40. <button type="button" id="alg" class="button white big" onclick="start('algebraicfactory')">代数工厂</button>
  41. <div class="nothing"></div>
  42. <button type="button" id="machine" class="button white big" onclick="start('machinelearner')">机器学习</button>
  43. <div class="nothing"></div>
  44. <button type="button" id="data" class="button white big" onclick="start('datascience')">数据科学</button>
  45. <div class="nothing"></div>
  46. <button type="button" id="func" class="button white small" onclick="start('functionfactory')">函数工厂</button>
  47. <div class="nothing"></div>
  48. <button type="button" id="geometric" class="button white small" onclick="start('functionmapping')">函数实验室</button>
  49. <h2 class="mode">物化系统</h2>
  50. <button type="button" id="physical" class="button white big">几何车间</button>
  51. <div class="nothing"></div>
  52. <button type="button" id="chemistry" class="button white big">物理车间</button>
  53. <div class="nothing"></div>
  54. <button type="button" id="laboratory" class="button white small">化学车间</button>
  55. <h2 class="mode">系统工具</h2>
  56. <button type="button" id="plugin" class="button white small" onclick="start('system')">系统管理</button>
  57. <div class="nothing"></div>
  58. <button type="button" id="process" class="button white small">通信管理器</button>
  59. </div>
  60. <script>
  61. let screen_width = 1200;
  62. let screen_height = 800;
  63. console.log(screen_height);
  64. document.getElementById("cotanTitle").style.width = String(screen_width -
  65. document.getElementById("method").offsetWidth - 1) + 'px';
  66. // 背景系统
  67. class Circle {
  68. constructor(x, y) {
  69. this.x = x;
  70. this.y = y;
  71. this.r = Math.random() * 10 ;
  72. this._mr = Math.random();
  73. this._mx = (Math.random() - 0.5) * 2;
  74. this._my = (Math.random() - 0.5) * 2 ;
  75. this.ax = 0;
  76. this.ay = 0;
  77. }
  78. drawCircle(ctx) {
  79. ctx.beginPath(); // 开始绘制
  80. ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI); // 画弧线
  81. ctx.closePath(); // 结束绘制
  82. ctx.fillStyle = 'rgba(204, 204, 204, 0.3)';
  83. ctx.fill();
  84. }
  85. drawLine(ctx, _circle) {
  86. let dx = this.x - _circle.x; // 差距
  87. let dy = this.y - _circle.y; // 差距
  88. let d = Math.sqrt(dx * dx + dy * dy); // 勾股距离
  89. if (d < 180) {
  90. ctx.beginPath();
  91. //开始一条路径,移动到位置 this.x,this.y。创建到达位置 _circle.x,_circle.y 的一条线:
  92. ctx.moveTo(this.x, this.y); //起始点
  93. ctx.lineTo(_circle.x, _circle.y); //终点
  94. ctx.closePath();
  95. ctx.strokeStyle = 'rgba(204, 204, 204, ' + String(1 - (d/180)) + ')';
  96. ctx.stroke();
  97. }
  98. }
  99. set_a(ax, ay){
  100. this.ax += ax;
  101. this.ax /= 2;
  102. this.ay += ay;
  103. this.ay /= 2;
  104. }
  105. set_a_first(){
  106. if (Math.abs(this._mx) > 3) {
  107. this.ax = 0;
  108. this._mx = (Math.random() - 0.5) * 2;
  109. }
  110. if (Math.abs(this._my) > 3) {
  111. this.ay = 0;
  112. this._my = (Math.random() - 0.5) * 2;
  113. }
  114. }
  115. // 圆圈移动
  116. // 圆圈移动的距离必须在屏幕范围内
  117. move(w, h) {
  118. this._mx += this.ax;
  119. this._my += this.ay;
  120. this._mx = (this.x < w && this.x > 1) ? this._mx : (-this._mx);
  121. this._my = (this.y < h && this.y > 1) ? this._my : (-this._my);
  122. this._mr = (this.r < 10 && this.r > 1) ? this._mr : (-this._mr);
  123. this.x += this._mx / 2;
  124. this.y += this._my / 2;
  125. this.r += this._mr / 2;
  126. if (this.r <= 0){
  127. this._mr = -this._mr;
  128. this.r = -this.r;
  129. }
  130. }}
  131. //鼠标点画圆闪烁变动
  132. class currentCirle extends Circle {
  133. constructor(x, y) {
  134. super(x, y);
  135. this.r = 8;
  136. this.R = 30;
  137. this.rad = 0;
  138. this.circle = [];
  139. }
  140. add() {
  141. console.log('add');
  142. document.getElementsByTagName('title').item(0).innerHTML = 'loading...';
  143. this.circle.push('rgba(204, 204, 204, 0.8)');
  144. }
  145. remove() {
  146. console.log('remove');
  147. this.circle.shift();
  148. if (this.circle.length === 0){
  149. document.getElementsByTagName('title').item(0).innerHTML = 'Hello';
  150. }
  151. }
  152. drawLine(ctx, _circle) {
  153. let dx = this.x - _circle.x; // 差距
  154. let dy = this.y - _circle.y; // 差距
  155. let d = Math.sqrt(dx * dx + dy * dy); // 勾股距离
  156. if (d < 180){
  157. ctx.beginPath();
  158. ctx.moveTo(this.x, this.y); //起始点
  159. ctx.lineTo(_circle.x, _circle.y); //终点
  160. ctx.closePath();
  161. ctx.strokeStyle = 'rgba(204, 0, 0, ' + String(1 - (d / 180)) + ')';
  162. ctx.stroke();
  163. _circle.set_a(dx / 1800, dy / 1800);
  164. }else{
  165. _circle.set_a_first()
  166. }
  167. }
  168. drawCircle(ctx) {
  169. let l = this.circle.length;
  170. for (let i of this.circle){
  171. let dx = this.R * Math.cos(this.rad);
  172. let dy = this.R * Math.sin(this.rad);
  173. ctx.beginPath(); // 开始绘制
  174. ctx.arc(this.x + dx, this.y + dy, this.r, 0, 2 * Math.PI); // 画弧线
  175. ctx.closePath(); // 结束绘制
  176. ctx.fillStyle = i;
  177. ctx.fill();
  178. this.rad += 2 * Math.PI * (1 / l);
  179. if (this.rad >= 2 * Math.PI){
  180. this.rad -= 2 * Math.PI}
  181. }
  182. this.rad += Math.PI * (15 / 180);
  183. }
  184. }
  185. //更新页面用requestAnimationFrame替代setTimeout
  186. window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  187. let canvas = document.getElementById('canvas');
  188. let ctx = canvas.getContext('2d');
  189. let w = canvas.width = canvas.offsetWidth;
  190. let h = canvas.height = canvas.offsetHeight;
  191. let circles = [];
  192. let current_circle = new currentCirle(0, 0); // 鼠标位置
  193. let update_times = 0;
  194. let draw = function () {
  195. ctx.clearRect(0, 0, w, h); // 清空
  196. for (let i = 0; i < circles.length; i++) {
  197. circles[i].move(w, h);
  198. circles[i].drawCircle(ctx);
  199. for (j = i + 1; j < circles.length; j++) {
  200. circles[i].drawLine(ctx, circles[j])
  201. }
  202. }
  203. if (current_circle.x) {
  204. current_circle.drawCircle(ctx);
  205. for (let k = 1; k < circles.length; k++) {
  206. current_circle.drawLine(ctx, circles[k])
  207. }
  208. }else{
  209. for (let k = 1; k < circles.length; k++) {
  210. current_circle.set_a_first()
  211. }
  212. }
  213. update_times += 1;
  214. if (update_times >= 100) {
  215. circles.push(new Circle(Math.random() * w, Math.random() * h));
  216. circles.shift();
  217. update_times = 0
  218. }
  219. requestAnimationFrame(draw)
  220. };
  221. let init = function (num) {
  222. for (var i = 0; i < num; i++) {
  223. circles.push(new Circle(Math.random() * w, Math.random() * h));
  224. }
  225. draw();
  226. };
  227. window.addEventListener('load', init(220));
  228. window.onmousemove = function (e) { // 鼠标进入范围
  229. // e = e || window.event;
  230. current_circle.x = e.clientX;
  231. current_circle.y = e.clientY;
  232. };
  233. window.onmouseout = function () { // 鼠标移出反围
  234. current_circle.x = null;
  235. current_circle.y = null;
  236. };
  237. </script>
  238. </div>
  239. </body>
  240. </html>