<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: fakelaboratory</title>
    <description>The latest articles on DEV Community by fakelaboratory (@fakelaboratory).</description>
    <link>https://dev.to/fakelaboratory</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1213703%2F2fa18e9a-cc3a-4ce9-8c4f-02970093a0e6.png</url>
      <title>DEV Community: fakelaboratory</title>
      <link>https://dev.to/fakelaboratory</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fakelaboratory"/>
    <language>en</language>
    <item>
      <title>Physics: boiling water</title>
      <dc:creator>fakelaboratory</dc:creator>
      <pubDate>Tue, 23 Jan 2024 16:33:39 +0000</pubDate>
      <link>https://dev.to/fakelaboratory/physics-boiling-water-3ogi</link>
      <guid>https://dev.to/fakelaboratory/physics-boiling-water-3ogi</guid>
      <description>&lt;h2&gt;
  
  
  Idea
&lt;/h2&gt;

&lt;p&gt;This simulation about thermodynamics. Basic boiling of water, I was interested in bubbles, how they "born" and then moves to the surface. A simple heating element and water:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frzg9jqsaopehhr2xaaiw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frzg9jqsaopehhr2xaaiw.jpg" alt="Image description" width="800" height="589"&gt;&lt;/a&gt;&lt;br&gt;
In result I have the Jupyter/Colab notebook and the animation:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvx2obvs95046fh7t7tl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvx2obvs95046fh7t7tl.gif" alt="Image description" width="512" height="512"&gt;&lt;/a&gt;&lt;br&gt;
And sure the code, because it made by moderngl, library for python.&lt;/p&gt;



&lt;p&gt;I was mistaken, in first, by pressure... I thought Archimedes force in bubbles versus pressure(ye I only study physics). But it is was start and I wrote this algorithm:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Algorithm, transformation cycle of molecule(group):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;if molecule temperature &amp;gt; 100,then check neighbors, if near exist gas then connect, else randomly can transform to gas(change state and remove from the common array). if connected to someone - register the new transformation group and try to reorginize to a big cube shape &lt;/li&gt;
&lt;li&gt;check registered groups the archimed force(1), if the archimed force more than pressure(!my error) of water then this group now in the transportation state(moving up) &lt;/li&gt;
&lt;li&gt;check groups which in the transportation state: if not on the surface then move up, else(on surface) check can be free or not(2). can be free if pressure inside the group more than surface tension force. if near other groups - connect(merge)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Algorithm for all molecules(water):&lt;br&gt;
1.Fill holes(shift down if bottom now the gas and not in the common array)&lt;br&gt;
2.Try to make the water surface flat&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hvh74z2ztemrovoxs73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hvh74z2ztemrovoxs73.png" alt="Image description" width="794" height="794"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But I dropped the part when count surface tension on surface.&lt;br&gt;
In this algorithm I found an interesting "philosophical" interpretation - bubbles trying to connect to each other after transformation to gas on the bottom, and then together going up to the surface... Also interesting is constants about size and mass of molecules - because with some parameters it works but with some not, but sure they still near to which I found in tables and the internet.&lt;/p&gt;
&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://colab.research.google.com/drive/1-MyJUJe_BF76JA2P1mZTywSaLCJFTT1j?usp=sharing"&gt;https://colab.research.google.com/drive/1-MyJUJe_BF76JA2P1mZTywSaLCJFTT1j?usp=sharing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/fakelaboratory/publish/blob/main/Boiling_water_simulation.ipynb"&gt;https://github.com/fakelaboratory/publish/blob/main/Boiling_water_simulation.ipynb&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible to split for four parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import libraries
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!pip install moderngl
!pip install pyrr
!pip install moviepy
import moderngl as gl
import numpy as np
import random
import pyrr as pyrr
from PIL import Image
import moviepy.editor as mpy
from google.colab import files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;ModernGL library for GL, pyrr for matrix transformations, moviepy and PIL - for animation creating. Also in the full code you can see creating context in this part, because if something failed then context will not creates.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shader and vertices
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctx.enable(gl.BLEND)
prog = ctx.program(
    vertex_shader="""
        #version 330
        in vec4 in_vert;
        void main() {
            gl_Position = in_vert;
        }
    """,
    fragment_shader="""
        #version 330
        uniform vec4 u_color;
        out vec4 f_color;
        void main() {
            f_color = u_color;
        }
    """,
)
vertices = np.asarray([
    [-0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 ,  0.5 , -0.5, 1.0] ,
    [ 0.5 ,  0.5 , -0.5, 1.0] ,
    [-0.5 ,  0.5 , -0.5, 1.0] ,
    [-0.5 , -0.5 , -0.5, 1.0] ,

    [-0.5 , -0.5 ,  0.5, 1.0] ,
    [ 0.5 , -0.5 ,  0.5, 1.0] ,
    [ 0.5 ,  0.5 ,  0.5, 1.0] ,
    [ 0.5 ,  0.5 ,  0.5, 1.0] ,
    [-0.5 ,  0.5 ,  0.5, 1.0] ,
    [-0.5 , -0.5 ,  0.5, 1.0] ,

    [-0.5 ,  0.5 ,  0.5, 1.0] ,
    [-0.5 ,  0.5 , -0.5, 1.0] ,
    [-0.5 , -0.5 , -0.5, 1.0] ,
    [-0.5 , -0.5 , -0.5, 1.0] ,
    [-0.5 , -0.5 ,  0.5, 1.0] ,
    [-0.5 ,  0.5 ,  0.5, 1.0] ,

    [ 0.5 ,  0.5 ,  0.5, 1.0] ,
    [ 0.5 ,  0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 ,  0.5, 1.0] ,
    [ 0.5 ,  0.5 ,  0.5, 1.0] ,

    [-0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 , -0.5, 1.0] ,
    [ 0.5 , -0.5 ,  0.5, 1.0] ,
    [ 0.5 , -0.5 ,  0.5, 1.0] ,
    [-0.5 , -0.5 ,  0.5, 1.0] ,
    [-0.5 , -0.5 , -0.5, 1.0] ,

    [-0.5 ,  0.5 , -0.5, 1.0] ,
    [ 0.5 ,  0.5 , -0.5, 1.0] ,
    [ 0.5 ,  0.5 ,  0.5, 1.0] ,
    [ 0.5 ,  0.5 ,  0.5, 1.0] ,
    [-0.5 ,  0.5 ,  0.5, 1.0] ,
    [-0.5 ,  0.5 , -0.5, 1.0]
],dtype='f4')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here basic shader, with the uniform color and vertices for cube. All elements in simulation is cube, and this is the original cube. Also:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def transform(v,type,args):
  if(type=="rotation"):
    mat = pyrr.matrix44.create_from_axis_rotation([args[0],args[1],args[2]],args[3])
  if(type=="scale"):
    mat = pyrr.matrix44.create_from_scale([args[0],args[1],args[2]])
  if(type=="translation"):
    mat = pyrr.matrix44.create_from_translation([args[0],args[1],args[2]])
  for i in range(len(v)):
    v[i]= pyrr.matrix44.apply_to_vector(mat, v[i])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is basic transformation, they are used while all code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Main logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is most complex part, but in general two classes: &lt;em&gt;Molecule&lt;/em&gt; and &lt;em&gt;Water&lt;/em&gt;. Molecule is basic "object" with position, size, and state. State 0 it is water, the state 1 is gas. It is needed in render and in logic.&lt;/p&gt;

&lt;p&gt;Water contains all molecules and also &lt;em&gt;group_transform&lt;/em&gt;, &lt;em&gt;group_transport&lt;/em&gt;. When molecules change own state and connected with neighbors gas molecules - they are group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#in general if both molecules not in groups, create group
#if first in group but second not then connect second
#if in different groups, merge groups and delete second group
#with adding element to group_transform arrays, with id's of groups
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also function &lt;em&gt;reorganize&lt;/em&gt;, which contain physics calcs and logic with moving from group to group, moving in group. When group in transportation phase, then it is big molecule, and acceleration is force/mass.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Render&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here just render by creating VAO,VBO for molecules, few colors. And in each frame calling the reorganize function. Also after render - export to GIF.&lt;/p&gt;




&lt;h2&gt;
  
  
  End
&lt;/h2&gt;

&lt;p&gt;When I tried to count 100000 molecules, RAM(13gb) was crashed. What I think about it? I still code without optimization with idea to be scalable, for more RAM and for more logic, because for more interesting interactions will need a data about each molecules. I mean first what in the head: it is not render all molecules, but only which really need, create illusion, but it is not what I trying to achieve. &lt;br&gt;
Achieved idea of recursive process, in all scales of the water object the logic will works. Maybe needed to add more layers for the transformation layer, then will heats not only one level of molecules, but millimeter of molecules for example. It'll give big bubbles, because now it in molecular level. &lt;br&gt;
Big bubbles is big groups.&lt;/p&gt;

</description>
      <category>physics</category>
      <category>python</category>
      <category>colab</category>
      <category>moderngl</category>
    </item>
    <item>
      <title>Modern GL + Google Colab = triangle animation</title>
      <dc:creator>fakelaboratory</dc:creator>
      <pubDate>Mon, 18 Dec 2023 16:54:50 +0000</pubDate>
      <link>https://dev.to/fakelaboratory/modern-gl-google-colab-triangle-animation-38bc</link>
      <guid>https://dev.to/fakelaboratory/modern-gl-google-colab-triangle-animation-38bc</guid>
      <description>&lt;p&gt;Rendered not in my PC image:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdu0g30ahrv2x5vgqizo1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdu0g30ahrv2x5vgqizo1.gif" alt="Image description" width="512" height="512"&gt;&lt;/a&gt;&lt;br&gt;
*i mean not this gif here in your browser but in colab cloud?&lt;/p&gt;

&lt;p&gt;Link to colab: &lt;br&gt;
&lt;a href="https://colab.research.google.com/drive/10Ig1Nqbwqd1lF7HAF0rJuxpZpThgjHcB?usp=sharing"&gt;https://colab.research.google.com/drive/10Ig1Nqbwqd1lF7HAF0rJuxpZpThgjHcB?usp=sharing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This notebook restored from old(2018) google notebook, with some changes in code. Links to references in comments of the notebook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!pip install moderngl
!pip install moviepy
import moderngl as gl
import numpy as np
from PIL import Image
import moviepy.editor as mpy

ctx = gl.create_context(standalone=True, backend='egl')
print(ctx.info)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prog = ctx.program(
    vertex_shader="""
        #version 330
        in vec2 in_vert;
        in vec3 in_color;
        out vec3 v_color;
        void main() {
            v_color = in_color;
            gl_Position = vec4(in_vert, 0.0, 1.0);
        }
    """,
    fragment_shader="""
        #version 330
        in vec3 v_color;
        out vec3 f_color;
        void main() {
            f_color = v_color;
        }
    """,
)

vertices = np.asarray([

    -0.75, -0.75,  1, 0, 0,
    0.75, -0.75,  0, 1, 0,
    0.0, 0.649,  0, 0, 1

], dtype='f4')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def render_frame(time):
  vbo = ctx.buffer(vertices.tobytes())
  vao = ctx.vertex_array(prog, vbo, "in_vert", "in_color")

  fbo = ctx.framebuffer(
    color_attachments=[ctx.texture((512, 512), 3)]
  )
  fbo.use()
  fbo.clear(0.0+time, 0.0+time, 0.0+time, 1.0)
  vao.render()

  return np.array(Image.frombytes(
    "RGB", fbo.size, fbo.color_attachments[0].read(),
    "raw", "RGB", 0, -1
  ))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clip = mpy.VideoClip(render_frame, duration=2) # 2 seconds
clip.write_gif("anim.gif",fps=15)
#now in files anim.gif
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;May the new year bless you with health, wealth, and happiness.&lt;/em&gt;&lt;br&gt;
from "65 Happy New Year Wishes for Friends and Family 2024" countryliving article&lt;/p&gt;

</description>
      <category>moderngl</category>
      <category>colab</category>
      <category>python</category>
    </item>
    <item>
      <title>Physics: Momentum</title>
      <dc:creator>fakelaboratory</dc:creator>
      <pubDate>Thu, 14 Dec 2023 14:39:48 +0000</pubDate>
      <link>https://dev.to/fakelaboratory/momentum-2a1j</link>
      <guid>https://dev.to/fakelaboratory/momentum-2a1j</guid>
      <description>&lt;p&gt;In this experiment - the simple collision. With transferring momentum from one object to another. I split the application of momentum to the block object(see next picture) for two parts: the rotating part and the general motion part&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoomaepbcore8estrpkv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoomaepbcore8estrpkv.png" alt="Image description" width="800" height="565"&gt;&lt;/a&gt;&lt;br&gt;
*by coefficients of collision's point to radius&lt;/p&gt;

&lt;p&gt;Calcs of momentum transferring, is general, thanks to:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnu6381xsqkabdjrnksf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnu6381xsqkabdjrnksf.png" alt="Image description" width="636" height="545"&gt;&lt;/a&gt;&lt;br&gt;
I tried to solve it in my way, looks similar to these calcs...&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq5zsxzbye26y5krqwy0.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq5zsxzbye26y5krqwy0.JPG" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
Not only similar, but the same, same in Khan, same In Wolfram, same by hands, same by tables, same by code, three tests passed&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyztoft1dp212xnmnyv6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyztoft1dp212xnmnyv6r.png" alt="Image description" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br&gt;
Just a cube directed to the wide block, possible to set masses and move the cube(left/right)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkj48qy8010y43zol4za.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkj48qy8010y43zol4za.png" alt="Image description" width="745" height="494"&gt;&lt;/a&gt;&lt;br&gt;
Link to play around:&lt;br&gt;
&lt;a href="https://fakelaboratory.github.io/publish/Momentum/"&gt;https://fakelaboratory.github.io/publish/Momentum/&lt;/a&gt;&lt;br&gt;
Source:&lt;br&gt;
&lt;a href="https://github.com/fakelaboratory/publish/tree/main/Momentum"&gt;https://github.com/fakelaboratory/publish/tree/main/Momentum&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In general same code like in the last experiment with Newton's laws, because it is a same framework, I mean masses, friction and speed(acceleration), move and rotate points. If interested in - please read the code, for notes 'll be usefull in the last article something(&lt;a href="https://dev.to/fakelaboratory/newtons-laws-of-motion-232p"&gt;https://dev.to/fakelaboratory/newtons-laws-of-motion-232p&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>physics</category>
      <category>javascript</category>
      <category>webgl</category>
      <category>simulation</category>
    </item>
    <item>
      <title>Physics: Newton's Laws of motion</title>
      <dc:creator>fakelaboratory</dc:creator>
      <pubDate>Mon, 27 Nov 2023 13:53:10 +0000</pubDate>
      <link>https://dev.to/fakelaboratory/newtons-laws-of-motion-232p</link>
      <guid>https://dev.to/fakelaboratory/newtons-laws-of-motion-232p</guid>
      <description>&lt;h2&gt;
  
  
  Physics
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Force of gravity = mass * gravity acceleration&lt;/li&gt;
&lt;li&gt;Force of slide = force(gravity)*cos(plane angle)&lt;/li&gt;
&lt;li&gt;Force of friction(opposite to slide) = friction coefficient *force(gravity) * sin(plane angle)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz78p0rqorgvpc8md8odd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz78p0rqorgvpc8md8odd.png" alt="Image description" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additional force(custom push) from top of view:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fek88zoiy84taqc74fptl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fek88zoiy84taqc74fptl.png" alt="Image description" width="600" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//horizontal application(from top of view) of setted in ui the force
cube.force_x = force.magnitude*Math.cos(Math.PI*force.angle/180+Math.PI)*-1;
cube.force_result = cube.force_slide + cube.force_friction + cube.force_x; 
cube.acceleration_x = cube.force_result/ cube.mass; // from F = m*a
cube.init_velocity_x = 0; // set start point

//vertical(from top of view) application of setted in ui the force
cube.force_y = force.magnitude*Math.sin(Math.PI*force.angle/180);
cube.acceleration_y = cube.force_y/ cube.mass; // from F = m*a
cube.init_velocity_y = 0; // set start point
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the simuluation by moving with the initial speed equal to zero, then with &lt;code&gt;Δd=V(init)*time + (1/2)*acceleration*time^2&lt;/code&gt; move points to delta and increase the init speed through acceleration. &lt;br&gt;
The time is frame iteration, 1000/24, for example.&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4n25trh9ddzvnmeemcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4n25trh9ddzvnmeemcn.png" alt="Image description" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Sketch of UI:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg7ufbkjogkcfhcutche.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg7ufbkjogkcfhcutche.png" alt="Image description" width="800" height="538"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Real screenshot:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrscl4jcpt363e5f7q4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrscl4jcpt363e5f7q4j.png" alt="Image description" width="656" height="513"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Structure:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frbim7gdpeyw23o70nxth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frbim7gdpeyw23o70nxth.png" alt="Image description" width="642" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;objects_render&lt;/em&gt; is for buffers, program, shaders of WebGL&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;glmjs&lt;/em&gt; are helping files, glmjs library(matrix operations) and helper file, where code for rotate object, move by glmjs.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;objects_logic&lt;/em&gt; files of plane, cube, time, force...
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plane {
   vertices; //array positions, colors
   angle; //degree
   inclane(angle) {
      //inclane plane and cube
      cube.inclane()
   } 
}
cube {
   vertices;
   mass; //kg
   build_physics(); //calculate forces and accelerations 
   inclane(); //also
}
force {
   vertices; //vizualiation, blue line
   angle; //degree
   magnitude; //newton
   inclane();
}  
time {
   //some coefficients and iter of time
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for example plane object:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mb3lz6b8vbzhvmh6atm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mb3lz6b8vbzhvmh6atm.png" alt="Image description" width="800" height="408"&gt;&lt;/a&gt;&lt;br&gt;
As possible to see in the screenshot this simulation is using additional arrays for vertices, in example of the plane it is just a "backup" of original vertices, but for the cube: more easy just move cube in x,y(top of view),store this position and render it in another array with x,y + inclane... &lt;/p&gt;

&lt;p&gt;Tried to test with real physics(I mean in the room with paper and matches) looks the similar. Also I added acceleration coefficient for "slow motion" because all happening so fast. But it is my philosophy interpretations... &lt;/p&gt;

&lt;p&gt;Code here:&lt;br&gt;
&lt;a href="https://github.com/fakelaboratory/publish/tree/main/Newton's%20laws%20of%20motion"&gt;https://github.com/fakelaboratory/publish/tree/main/Newton's%20laws%20of%20motion&lt;/a&gt;&lt;br&gt;
Test through browser:&lt;br&gt;
&lt;a href="https://fakelaboratory.github.io/publish/Newton's%20laws%20of%20motion/"&gt;https://fakelaboratory.github.io/publish/Newton's laws of motion/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>physics</category>
      <category>simulation</category>
      <category>javascript</category>
      <category>webgl</category>
    </item>
  </channel>
</rss>
