Columbia Science Review
  • Home
  • About
    • Our Team
  • Online Articles
  • Events
    • 2022-2023
    • 2021-2022
    • 2020-2021
    • 2019-2020
    • 2018-2019
    • 2017-2018
    • 2016-2017
  • Publications
  • COVID-19 Hub
    • Interviews >
      • Biology of COVID-19
      • Public Health
      • Technology & Data
    • Frontline Stories >
      • Healthcare Workers
      • Global Health
      • Volunteer Efforts
    • Resources & Links >
      • FAQ's
      • Resource Hubs
      • Student Opportunities
      • Podcasts & Graphics
      • Mental Health Resources
      • Twitter Feeds
      • BLM Resources
    • Columbia Events >
      • Campus Events
      • CUMC COVID-19 Symposium
      • CSR Events
    • Our Team
  • Contact

When JavaScript Meets Desmos: Rebuilding Games with Mathematics

11/2/2025

0 Comments

 
By Jeff Ho
​Most computer programs are imperative, meaning that they tell the computer what to do next by expressing a sequence of commands that execute one step at a time. For example, video games that are written in JavaScript, might update a player’s position every frame, redraw the scene, and repeat the loop indefinitely, giving the user a continuous and smooth gameplay experience. The program simulates change by constantly rewriting the virtual world experience for the player.
Meanwhile, mathematics takes the opposite approach. Instead of instructing what happens next, it states what is always true. For example, a circle isn’t drawn step by step, it is the set of all points (x, y) which satisfies an equation (e.g. (x-a)2+(y-b)2 = r2). This style is known to be declarative, and it is also exactly how graphing tools like Desmos operate. Users don’t “draw” a line, they specify the equation. Then, Desmos instantly renders all points that satisfy it. The special “sliders” that Desmos has doesn’t move the graph step by step in this style, it continuously changes the parameters of the underlying equation. The platform then recalculates everything in real time, and gives a smooth and responsive graph that users can alter in real-time.

The sliders bring the art of mathematics to life, as many users start making static equations into something dynamic, visual, and interactive. A project called Minecraft in Desmos showcases this beautifully, where the creator explores the intersection of imperative and declarative styles within the Desmos environment. Before stepping into Javascript, it is essential to understand the translation from code to mathematics in Desmos.

Note that a traditional program run in steps:
if (x > 5) y = -y;

However, in Desmos, there is no “if-then” in time. Instead, we have to define the ‘program’ in a declarative style, where we state relationships that are always true. The beauty of this style is that the condition isn’t checked once, it’s continuously satisfied.
y = if(x > 5, -y, y)

Another program could be a loop:
for (let i=0; i<10; i++) drawBlock(i);

However, Desmos doesn’t loop, it uses lists: xi=[1,2,3,...,10], yi=sin(xi)
So all blocks appear simultaneously, meaning that it does not “do this ten times”, but rather “these ten things exist.” 
Even randomness in programming can take on a mathematical form. Instead of Math.random(), Desmos might use a deterministic function: r(n)=frac(sin(n)*10000)

To build a cube in Minecraft, game engines rely on polygons and rendering pipelines. In Desmos, each cube must be defined, so a single block can be expressed with inequalities where the cube is centered at (a, b, c): |x-a|0.5,|y-b|0.5, |z-c|0.5 

Then, creators can generate entire biomes, and while Desmos handles the visuals, JavaScript brings interactivity. Through the Desmos API, developers can connect real-time inputs, like mouse movements, key presses, or even randomized values directly to variables inside the calculator.

A key example in JavaScript is by setting the movement rules in Minecraft or many other games in 2D:
x += speed * dx;
y += speed * dy;
if (x > W) x -= W; // wrap
if (x < 0) x += W; // wrap

In Desmos we might use a time slider t and write:
x(t)=(x0+speed*dx*t) mod W
y(t)=(y0+speed*dy*t) mod H
with mod() performing the wraparound (since we are in a minecraft world with finite size, so we keep the avatar inside a finite world by wrapping).

Another key example is when the program creates dynamic lighting based on camera angle. For example, how one face of a cube brightens when facing the light source.
let lightAngle = 0;

setInterval(() => {
  lightAngle += 0.02;
  const lx = Math.cos(lightAngle);
  const lz = Math.sin(lightAngle);
  calc.setExpression({id: 'light', latex: `L_x=${lx}, L_z=${lz}`});
}, 50);


These code fragments show how Desmos and JavaScript work together, where JavaScript handles inputs and timing, and Desmos handles mathematics and visualization. In this sense, the “Minecraft in Desmos” project demonstrates a very innovative idea for more future projects: a graphing calculator can function as a declarative physics and graphics engine. The logic of gameplay, camera perspective, and shading all arise not from loops and pixels, but from equations that remain continuously true. 

When JavaScript meets Desmos, programming and mathematics merge. What’s usually expressed as step-by-step code becomes a living system of equations. Instead of commanding the computer to act, we define a world that must obey its own mathematical laws, just like the world we are living in right now. Whether plotting functions or building digital universes, the distinction between coding and calculating begins to blur since the art of mathematics arises in the intersection of these two typically independent fields. Overall, mathematics is not just a tool for understanding the world, but it is a language that is capable of building new ones and offers creative solutions.

0 Comments



Leave a Reply.

    Categories

    All
    Artificial Intelligence
    Halloween 2022
    Winter 2022-2023

    Archives

    November 2025
    April 2024
    January 2024
    February 2023
    November 2022
    October 2022
    June 2022
    January 2022
    May 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2020
    March 2020
    February 2020
    January 2020
    November 2019
    October 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    April 2018
    March 2018
    February 2018
    November 2017
    October 2017
    May 2017
    April 2017
    April 2016
    March 2016
    February 2016
    December 2015
    November 2015
    October 2015
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    May 2014
    April 2014
    March 2014
    February 2014
    December 2013
    November 2013
    October 2013
    April 2013
    March 2013
    February 2013
    January 2013
    December 2012
    November 2012
    October 2012
    April 2011
    March 2011
    February 2011
    September 2010
    August 2010
    July 2010
    June 2010
    May 2010
    April 2010
    March 2010
    February 2010
    January 2010
    December 2009
    November 2009
    July 2009
    May 2009

Columbia Science Review
© COPYRIGHT 2022. ALL RIGHTS RESERVED.
Photos from driver Photographer, BrevisPhotography, digitalbob8, Rennett Stowe, Kristine Paulus, Tony Webster, CodonAUG, Tony Webster, spurekar, europeanspaceagency, Christoph Scholz, verchmarco, rockindave1, robynmack96, Homedust, The Nutrition Insider
  • Home
  • About
    • Our Team
  • Online Articles
  • Events
    • 2022-2023
    • 2021-2022
    • 2020-2021
    • 2019-2020
    • 2018-2019
    • 2017-2018
    • 2016-2017
  • Publications
  • COVID-19 Hub
    • Interviews >
      • Biology of COVID-19
      • Public Health
      • Technology & Data
    • Frontline Stories >
      • Healthcare Workers
      • Global Health
      • Volunteer Efforts
    • Resources & Links >
      • FAQ's
      • Resource Hubs
      • Student Opportunities
      • Podcasts & Graphics
      • Mental Health Resources
      • Twitter Feeds
      • BLM Resources
    • Columbia Events >
      • Campus Events
      • CUMC COVID-19 Symposium
      • CSR Events
    • Our Team
  • Contact