Advertisement
ivodevweb

Untitled

Jan 27th, 2023
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 7.50 KB | Software | 0 0
  1. <html>
  2. <head>
  3.   <style>
  4.       /* CSS styles for the table */
  5.   table, tr, td, th{
  6.         table-layout: fixed;
  7.         border:#000 solid 1px;
  8.         width:150px;
  9.         padding:0px;
  10.         font-size:10px;
  11.     }
  12.         td{
  13.         width:auto;
  14.         height:100%;
  15.     }
  16.     th{
  17.         background-color:#FFE4B5;
  18.         color:#000;
  19.     }
  20.       /* Other CSS styles */
  21.       body {
  22.         background-color: #f2f2f2;
  23.       }
  24.       h1 {
  25.         padding: 10px;
  26.         text-align: center;
  27.       }
  28.       #pendulo {
  29.         padding: 20px;
  30.         align-content: center;
  31.         width: 800px;
  32.         height: 500px;
  33.         background-color: black;
  34.       }
  35.       //animação de pendulo
  36.       * {
  37.         margin: 0;
  38.         padding: 0;
  39.         box-sizing: border-box;
  40.       }
  41.  
  42. #contas{
  43.           display: flex;
  44.           flex-direction: row;
  45.           align-items: center;
  46.           justify-content: center;
  47.       }
  48. .base {
  49.   width: 500px;
  50.   border-top: 5px solid gray;
  51.   margin: auto;
  52.   text-align: center;
  53.   position: relative;
  54.   padding: 0 0 30px;
  55. }
  56.  
  57. .holder {
  58.   width: 30px;
  59.   height: 20px;
  60.   background: black;
  61.   margin: auto;
  62.   border-radius: 0 0 50% 50%;
  63. }
  64.  
  65. .thread {
  66.   display: inline-block;
  67.   width: 2px;
  68.   height: 200px;
  69.   background: black;
  70.   border-radius: 5px;
  71.   position: relative;
  72.   transform-origin: 50% 0;
  73.   animation: moveIt 2.5s ease-in-out infinite;
  74. }
  75.  
  76. .thread:after {
  77.   content: "";
  78.   position: absolute;
  79.   width: 5px;
  80.   height: 5px;
  81.   border-radius: 50%;
  82.   background: red;
  83.   border: 2px solid white;
  84.   top: -4.5px;
  85.   left: -3.5px;
  86. }
  87.  
  88. .knob {
  89.   width: 10px;
  90.   height: 10px;
  91.   position: absolute;
  92.   top: -18px;
  93.   left: -4.5px;
  94.   border: 2px solid rgba(255, 255, 255, .5);
  95.   border-radius: 50%;
  96.   border-bottom: 2px solid transparent;
  97. }
  98.  
  99. .pendulum {
  100.   width: 20px;
  101.   height: 20px;
  102.   background: -moz-radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%);
  103.   background: -webkit-radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%);
  104.   background: -o-radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%);
  105.   background: -ms-radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%);
  106.   background: radial-gradient(circle at 70% 35%, white, #66d63e 30%, #40a31d 50%);
  107.   border-radius: 50%;
  108.   position: absolute;
  109.   bottom: -10px;
  110.   left: -9px;
  111. }
  112.  
  113. .shadow {
  114.   width: 30px;
  115.   height: 15px;
  116.   background: rgba(0, 0, 0, 0.2);
  117.   border-radius: 50%;
  118.   margin: 50px auto 0;
  119.   animation: moveShade 1.25s ease-in-out alternate infinite;
  120. }
  121.  
  122. @keyframes moveIt {
  123.   0%, 100% {
  124.     transform: rotate(45deg);
  125.   }
  126.   50% {
  127.     transform: rotate(-45deg);
  128.   }
  129. }
  130.  
  131. @keyframes moveShade {
  132.   0% {
  133.     transform: translateX(-220px) scale(1.4, .5);
  134.     filter: blur(20px);
  135.   }
  136.   50% {
  137.     filter: blur(3px);
  138.   }
  139.   100% {
  140.     transform: translateX(220px) scale(1.4, .5);
  141.     filter: blur(20px);
  142.   }
  143. }
  144.  
  145.  
  146.  </style>
  147.  
  148. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  149. <title>Pêndulo Grávitico</title>
  150. <link href="style.css" type="text/css" rel="stylesheet"/>
  151.  
  152.     <script type="text/javascript">
  153. </script>
  154.   <!-- Carrega a biblioteca Plotly -->
  155.   <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
  156. </head>
  157.    
  158. <body>
  159.    
  160.    
  161. <header>
  162. <img
  163.     src="https://ivo.com.pt/wp-content/uploads/2020/05/ivoprincipal.png"
  164.     alt="Ivo Baptista">
  165. <div>
  166.     <strong>Ivo Baptista</strong>
  167.     <span>EfolioB de Física</span>
  168. </div>
  169. </header>
  170.     <div id=container style="display: inline-block; text-align: center;">
  171. <div class="base">
  172.   <div class="holder"></div>
  173.   <div class="thread">
  174.     <div class="knob"></div>
  175.     <div class="pendulum"></div>
  176.   </div>
  177.   <div class="shadow"></div>
  178. </div>
  179.   <!-- Cria uma div onde é exibido o gráfico -->
  180.   <div id="Pendulo"></div>
  181.     </div>
  182.     <h1>Grafico Pêndulo Gravítico</h1>
  183.     <div id=contas>
  184.         <div>A=</div><div id="minhaDiv"></div> </div>
  185.  
  186.     <h4>________t(s)____________theta(rad)__________w(s)_____________k1x______________k1v______________k2x_____________k2v________</h4>
  187.    
  188.       <!-- Cria uma tabela -->
  189. <table id="tabela" cellspacing="5" cellpadding="10">
  190. ...
  191. </table>
  192.  
  193.  
  194.     <p style="font-size:x-small">
  195.      ** Realizado por: Ivo Vieira Baptista - @UAb  **</p>
  196.      <p style="font-size:x-small">
  197.      ** -----------------------------------------  **</p>
  198.   <script>
  199.  
  200. // Constantes
  201. const m = 2.6 * 0.001;  // Massa em kg
  202. const L = 1.0;     // Length of rope in meters
  203. const rho = 1.28;  // Massa específica do ar em kg/m^3
  204. const g = 9.81;    // Aceleração da gravidade em m/s^2
  205. const cd = 0.1;    // Coeficiente de arrasto aerodinâmico para uma esfera
  206. const R = 0.3;     // Raio da esfera em metros
  207.  
  208. // Área frontal do pêndulo
  209. const A = Math.PI * R**2;
  210.      
  211. document.getElementById("minhaDiv").innerHTML = A;
  212.      
  213. // Calcula o coeficiente de arrasto aerodinâmico
  214. const b =  1/2 * rho * cd * A;
  215.  
  216. // Valores iniciais
  217. let theta0 = 0.05;  // Ângulo inicial em rad
  218. let w0 = 0.0;       // Velocidade angular inicial em rad/s
  219. let t0 = 0.0;       // Tempo inicial em segundos
  220. const h = 0.1;      // Passo de tempo em segundos
  221.  
  222. // Listas para armazenar os resultados
  223. const t = [t0];
  224. const theta = [theta0];
  225. const w = [w0];
  226.  
  227. // Loop de tempo
  228. while (t[t.length - 1] <= 100.0) {
  229.     // Cálculo dos valores intermediários
  230.     let k1x = w[w.length-1];
  231.     let k1v = (-Math.sign(w[w.length-1])*(b*L/m) *(w[w.length-1])**2)-(g/L)*theta[theta.length-1];  
  232.     let k2x = w[w.length-1] + k1v*h;
  233.     let k2v = (-Math.sign((w[w.length-1] + k1v*h))*(b*L/m)*((w[w.length-1] + k1v)*h)**2 - (g/L) * ((theta[theta.length-1]+k1x*h)));
  234.  
  235.     // Atualização dos valores de θ e w
  236.     theta.push(theta[theta.length-1] + ((k1x + k2x) / 2.0)*h);  // Metodo Heun
  237.     w.push(w[w.length-1] + ((k1v + k2v) / 2.0)*h);    // Metodo Heun
  238.  
  239.     // Atualização do tempo
  240.     t.push(t[t.length - 1] + h);
  241.       //Tabela
  242. function criarTabela(conteudo) {
  243.   var tabela = document.createElement("table");
  244.   var thead = document.createElement("thead");
  245.   var tbody=document.createElement("tbody");
  246.   var thd=function(i){return (i==0)?"th":"td";};
  247.   for (var i=0;i<conteudo.length;i++) {
  248.     var tr = document.createElement("tr");
  249.     for(var o=0;o<conteudo[i].length;o++){
  250.       var t = document.createElement(thd(i));
  251.       var texto=document.createTextNode(conteudo[i][o]);
  252.       t.appendChild(texto);
  253.       tr.appendChild(t);
  254.     }
  255.     (i==0)?thead.appendChild(tr):tbody.appendChild(tr);
  256.   }
  257.   tabela.appendChild(thead);
  258.   tabela.appendChild(tbody);
  259.   return tabela;
  260. }
  261. document.getElementById("tabela").appendChild(criarTabela([
  262.   [ t[t.length - 1].toFixed(2),theta[theta.length-1].toFixed(10),w[w.length-1].toFixed(10),k1x.toFixed(5),k1v.toFixed(5),k2x.toFixed(5),k2v.toFixed(5) ]
  263.  
  264. ]));
  265.    
  266. }
  267.  
  268. // Cria o gráfico com linha vermelha para θ
  269. const trace1 = {
  270.     x: t,
  271.     y: theta,
  272.     type: 'scatter',
  273.     name: 'θ',
  274.     marker: {color: 'red'},
  275. };
  276.  
  277. // Cria grafico com linhaa azul para w
  278. const trace2 = {
  279.     x: t,
  280.     y: w,
  281.     type: 'scatter',
  282.     name: 'w',
  283.     marker: {color: 'blue'},
  284. };
  285.  
  286. // Adiciona os dados ao layout
  287. const data = [trace1, trace2];
  288.  
  289. // Adiciona títulos aos eixos
  290. const layout = {
  291.     xaxis: {
  292.         title: 't (s)',
  293.     },
  294.     yaxis: {
  295.         title: 'θ (rad), w (rad/s)',
  296.     },
  297. };
  298.  
  299. // Exibe o gráfico
  300. Plotly.newPlot('Pendulo', data, layout);
  301.  
  302.  </script>
  303.  
  304.     <script type="text/javascript"> implementa();</script>                          <!-- Implementação automatica dos valores por defeito -->        
  305.  
  306. </body>
  307. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement