Void-voiD

Untitled

Aug 2nd, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let gl, canvas, current_molecula;
  2.  
  3. const start = () => {
  4.   canvas = document.getElementById("glcanvas");
  5.  
  6.   gl = initWebGL(canvas);      // инициализация контекста GL
  7.  
  8.   // продолжать только если WebGL доступен и работает
  9.  
  10.   if (gl) {
  11.     gl.clearColor(0.0, 0.0, 0.0, 1.0);                      // установить в качестве цвета очистки буфера цвета черный, полная непрозрачность
  12.     gl.enable(gl.DEPTH_TEST);                               // включает использование буфера глубины
  13.     gl.depthFunc(gl.LEQUAL);                                // определяет работу буфера глубины: более ближние объекты перекрывают дальние
  14.     gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);      // очистить буфер цвета и буфер глубины.
  15.   }
  16. }
  17.  
  18. const initWebGL = (canvas) => {
  19.   gl = null;
  20.  
  21.   try {
  22.     // Попытаться получить стандартный контекст. Если не получится, попробовать получить экспериментальный.
  23.     gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
  24.   }
  25.   catch(e) {}
  26.  
  27.   // Если мы не получили контекст GL, завершить работу
  28.   if (!gl) {
  29.     alert("Unable to initialize WebGL. Your browser may not support it.");
  30.     gl = null;
  31.   }
  32.  
  33.   return gl;
  34. }
  35.  
  36. // функция вызывается в случае ввода текста в поле для идентификации молекулы
  37. const getMolecula = () => {
  38.     let text = document.getElementById("searchbox").value;
  39.     if (text) {
  40.         // alert(text)
  41.         current_molecula = text;
  42.        
  43.        
  44.         //Обращение к серверу
  45.         const status = (response) => {
  46.             if (response.status !== 200) {
  47.                 return Promise.reject(new Error(response.statusText))
  48.             }
  49.             return Promise.resolve(response)
  50.         }
  51.         const json = (response) => {
  52.             return response.json()
  53.         }
  54.        
  55.         let link = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastformula/" + current_molecula + "/JSON";
  56.        
  57.         //Скачивание по ссылке
  58.         fetch(link)
  59.         .then(status)
  60.         .then(json)
  61.         .then(function (data) {
  62.             alert('data', data)
  63.         })
  64.         .catch(function (error) {
  65.             alert('error', error)
  66.         })
  67.        
  68.     }
  69. }
  70.  
Add Comment
Please, Sign In to add comment