Void-voiD

Untitled

Aug 2nd, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Molecula</title>
  6. <link href="css/style.css" rel="stylesheet">
  7. </head>
  8. <body onload = "start()">
  9. <form>
  10. <!-- окно для ввода формулы/названия молекулы -->
  11. <input type="text" size="50" id="searchbox" border="5" placeholder="search here..."
  12. style="height:2%; width:20%; position:fixed; top:4%; left:39%;"
  13. onchange="getMolecula()">
  14.  
  15. <!-- кнопки для переключения стилей отображения -->
  16. <button id="ball_stick" style="height:3%; width:12%; position:fixed; left:17%; top:9%;"> Ball-and-stick </button>
  17. <button id="spacefill" style="height:3%; width:12%; position:fixed; left:30%; top:9%;"> Spacefill </button>
  18. <button id="stick" style="height:3%; width:12%; position:fixed; left:43%; top:9%;"> Stick </button>
  19. <button id="wireframe" style="height:3%; width:12%; position:fixed; left:56%; top:9%;"> Wireframe </button>
  20. <button id="surface" style="height:3%; width:12%; position:fixed; left:69%; top:9%;"> Surface </button>
  21.  
  22. <!-- кнопки переключения режима отображения -->
  23. <button id="view" style="height:4%; width:14%; position:fixed; left:34%; top:14%;"> View Mode </button>
  24. <button id="compare" style="height:4%; width:14%; position:fixed; right:34%; top:14%;"> Compare Mode </button>
  25. </form>
  26.  
  27. <!-- холст для отрисовки молекулы -->
  28. <canvas id="glcanvas" style="height:70%; width:80%; position:fixed; top:22%; left:10%"></canvas>
  29. <script type="text/javascript" src="code/openGL.js"></script>
  30. </body>
  31. </html>
  32.  
  33. -----------------------------------
  34.  
  35. let gl, canvas, current_molecula;
  36.  
  37. const start = () => {
  38. canvas = document.getElementById("glcanvas");
  39.  
  40. gl = initWebGL(canvas); // инициализация контекста GL
  41.  
  42. // продолжать только если WebGL доступен и работает
  43.  
  44. if (gl) {
  45. gl.clearColor(0.0, 0.0, 0.0, 1.0); // установить в качестве цвета очистки буфера цвета черный, полная непрозрачность
  46. gl.enable(gl.DEPTH_TEST); // включает использование буфера глубины
  47. gl.depthFunc(gl.LEQUAL); // определяет работу буфера глубины: более ближние объекты перекрывают дальние
  48. gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT); // очистить буфер цвета и буфер глубины.
  49. }
  50. }
  51.  
  52. const initWebGL = (canvas) => {
  53. gl = null;
  54.  
  55. try {
  56. // Попытаться получить стандартный контекст. Если не получится, попробовать получить экспериментальный.
  57. gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
  58. }
  59. catch(e) {}
  60.  
  61. // Если мы не получили контекст GL, завершить работу
  62. if (!gl) {
  63. alert("Unable to initialize WebGL. Your browser may not support it.");
  64. gl = null;
  65. }
  66.  
  67. return gl;
  68. }
  69.  
  70. // функция вызывается в случае ввода текста в поле для идентификации молекулы
  71. const getMolecula = () => {
  72. let text = document.getElementById("searchbox").value;
  73. if (text) {
  74. // alert(text)
  75. current_molecula = text;
  76.  
  77.  
  78. //Обращение к серверу
  79. const status = (response) => {
  80. if (response.status !== 200) {
  81. return Promise.reject(new Error(response.statusText))
  82. }
  83. return Promise.resolve(response)
  84. }
  85. const json = (response) => {
  86. return response.json()
  87. }
  88.  
  89. let link = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastformula/" + current_molecula + "/JSON";
  90.  
  91. //Скачивание по ссылке
  92. fetch(link)
  93. .then(status)
  94. .then(json)
  95. .then(function (data) {
  96. alert(data)
  97. })
  98. .catch(function (error) {
  99. alert(error)
  100. })
  101.  
  102. }
  103. }
  104.  
Add Comment
Please, Sign In to add comment