๐ŸŒ
LMU
cs.lmu.edu โ€บ ~ray โ€บ notes โ€บ introjavascriptgraphics
JavaScript Graphics
All weโ€™re doing here is one or two examples for each type of graphics technique. A browser window contains elements. Elements can have colors (even gradients), borders, background colors, background images, fancy borders, opacity settings, and all kinds of paddings and margins. Elements can even be images! With rounded borders we can get circles. Importantly, CSS also allows elements to be positioned. With JavaScript, we can vary all of these settings over time to make animations.
๐ŸŒ
Reddit
reddit.com โ€บ r/graphicsprogramming โ€บ javascript for graphics programming?
r/GraphicsProgramming on Reddit: JavaScript for graphics programming?
February 6, 2024 -

TLDR: Graphics programming for the most part isn't common, even more so using WebGL/GLSL. What are your thoughts on using JS and the libraries that make it more accessible?

Some context, I'm a frontend web developer and work with JavaScript/TypeScript daily. I gained an interest in graphics programming through watching Acerola on YouTube. I mainly wanted to produce post processing effects, but more so generate/manipulate images.

I found it hard to jump into writing shaders with unity, and GLSL for WebGL is honestly a mess with too much overhead needed. With that, JavaScript is missing a lot of the basic things one would normally use. Things like generating Perlin noise or Vector types.

So far, I've created my own Perlin/Value noise library, quite a few filter effects (such as gaussian blur, B&W + colorize, wave distortion, edge detection, ect.), and even implemented various types of image scaling methods from box/tent to Lagrange-Chebyshev interpolation. Along the way I've also created a few GEMM utilities, but also quite a few calculus and trig utilities.

I'm currently working on creating Vector classes (2, 3, and 4, including their respective integer variants), in addition to a Color class. The Vector classes are based on C#, Unity, and Godot, with a few more additional features. The Color class is primarily based on Godot, but heavily expands on the blend method to support basically all the modes you would find in Adobe Photoshop. It uses sRGB/linearRGB for the most part, but can convert to/from HTML, HSV, HSL, and okLCH.

Over on r/javascript, all of this is well outside the realm of the casual web developer and is exceptionally niche. However, I'm noticing a trend of more games and interactive graphics being build with JS, typically using bloated libraries for rendering/physics.

So, what are your thoughts on having a "bare bones" library that implements what's missing in JS for graphics programming(minus the rendering parts)?

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn โ€บ JavaScript โ€บ Client-side_web_APIs โ€บ Drawing_graphics
Drawing graphics - Learn web development | MDN
November 22, 2024 - Because of its complexity, most people write 3D graphics code using a third party JavaScript library such as Three.js, PlayCanvas, or Babylon.js. Most of these work in a similar way, providing functionality to create primitive and custom shapes, position viewing cameras and lighting, covering surfaces with textures, and more.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javascript โ€บ javascript_graphics.htm
JavaScript - Graphics
<html> <body> <h2> JavaScript - Graphics (WebGL) </h2> <canvas id="webgl-canvas" width="600" height="400"></canvas> <div id="error"> </div> <script> // Get the canvas element and its WebGL context var canvas = document.getElementById('webgl-canvas'); let errorDiv = document.getElementById('error'); // Get context of webgl var gl = canvas.getContext('webgl'); if (!gl) { console.error('Your browser may not support WebGL.'); } // Vertex shader program var vsSource = ` attribute vec4 aVertexPosition; void main(void) { gl_Position = aVertexPosition; } `; // Fragment shader program var fsSource = `
๐ŸŒ
Humphryscomputing
humphryscomputing.com โ€บ Notes โ€บ Networks โ€บ javascript.graphics.html
JavaScript graphics - Dr. Mark Humphrys
Can do quite a lot of 2D graphics using getContext("2d"); in JavaScript. ... WebGL is a very low-level API. Even though it is JavaScript, programming in it is complex, verbose and probably only for graphics specialists.
๐ŸŒ
Programmingbasics
programmingbasics.org โ€บ en โ€บ downloads โ€บ html5canvas โ€บ index.html
Programming Basics: Graphics and Animation with HTML5 Canvas and Javascript
This is a presentation on how to write computer programs for doing simple graphics and animation. It uses the programming language JavaScript and is based on html5 canvas. The presentation is provided primarily in video form, but the text and slides from the presentation are provided as well.
๐ŸŒ
Creative Bloq
creativebloq.com โ€บ web design
11 JavaScript frameworks for creating graphics | Creative Bloq
September 22, 2021 - D3.js is the big boss of JavaScript graphics libraries. With over a million weekly downloads on npm, it is quite possibly the most well known and widely used of all the graphics libraries. It even has its own Wikipedia page.
Find elsewhere
๐ŸŒ
InfoWorld
infoworld.com โ€บ home โ€บ software development โ€บ using javascript and graphics
Using JavaScript and graphics | InfoWorld
August 1, 1996 - JavaScript extends the features of graphics in HTML pages by making image selection and appearance dynamic. With just a moderate amount of JavaScript coding, it's possible to conditionally choose graphic files for use on a page, resize and distort images, and even create images on the fly.
๐ŸŒ
W3Schools
w3schools.com โ€บ graphics
HTML Graphics
The graphic above shows four elements: a red rectangle, a gradient rectangle, a multicolor rectangle, and a multicolor text inside a <canvas> element. JavaScript libraries are used for both Artificial Intelligence graphs and other charts:
๐ŸŒ
CodeHS
codehs.com โ€บ tutorial โ€บ 12396
Tutorial: Basic Graphics in JavaScript | CodeHS
Click on one of our programs below to get started coding in the sandbox!
๐ŸŒ
LinkedIn
linkedin.com โ€บ learning โ€บ learning-html-canvas โ€บ graphics-programming-with-javascript
Graphics programming with JavaScript - Learning HTML Canvas Video Tutorial | LinkedIn Learning, formerly Lynda.com
It wasn't until HTML5 came along, ... Canvas element lets you do just that. Using standard JavaScript, you can draw whatever you want in both 2D and 3D graphics....
Published ย  November 26, 2018
Views ย  11K
๐ŸŒ
CodeLucky
codelucky.com โ€บ home โ€บ javascript graphics: introduction to web graphics programming
JavaScript Graphics: Introduction to Web Graphics Programming - CodeLucky
June 15, 2025 - JavaScript, with its powerful capabilities, offers developers a robust toolkit for crafting stunning visual experiences on the web. This comprehensive guide will introduce you to the exciting realm of web graphics programming using JavaScript, ...
๐ŸŒ
Rheinwerk Computing
blog.rheinwerk-computing.com โ€บ how-to-integrate-vector-graphics-in-a-javascript-program
How to Integrate Vector Graphics in a JavaScript Program
April 24, 2025 - In addition to being able to draw pixel-based graphics via JavaScript using the Canvas API, you can also use JavaScript to create vector graphics.
๐ŸŒ
p5.js
p5js.org
p5.js
p5.js is a friendly tool for learning to code and make art. It is a free and open-source JavaScript library built by an inclusive, nurturing community. p5.js welcomes artists, designers, beginners, educators, and anyone else ยท Lauren Lee McCarthy ...
Top answer
1 of 3
3

Programming on Khan Academy uses the JavaScript language along with the library ProcessingJS.

Here is a stand-alone program example derived from Processing.js Quick Start. This performs a very simple animation.

The graphics functions will match the the documentation at khanacademy.org and also here.

To run this, you need to download the file "processing.js" from here and save the following as "hello.html" (or whatever you want to call it), then open "hello.html" with a browser.

<script src="processing.js"></script>
<script type="application/processing" data-processing-target="pjs">
void setup() {
  size(200, 200);
  stroke(0), strokeWeight(2);
  println('hello web!');
}
void draw() {
  background(100); // clear the frame
  ellipse(abs(frameCount%400-200), 50, 25, 25);
}
</script>
<canvas id="pjs"> </canvas>

Alternative: Advanced JavaScript programming style

Here is a stand-alone JavaScript program example based on snippets from Processing.js Quick Start -- this draws (and animates) a small analog clock.

The available graphics functions are the same as above, but here they require the prefix processing -- the parameter to sketchProc() below. Notice, in particular, the call to processing.line().

The instructions for running this are the same as above -- just put the following .html file in a folder along with the file processing.js...

<!DOCTYPE html>
<html>
<head>
  <title>Hello Web - Processing.js Test</title>
  <script src="processing.js"></script>
</head>
<body>
  <h1>Processing.js Test</h1>
  <p>This is my first Processing.js web-based sketch:</p>
  <canvas id="canvas"></canvas>
   <script>
   function sketchProc(processing) {

      processing.draw = function() {
      var centerX = processing.width / 2, centerY = processing.height / 2;
      var maxArmLength = Math.min(centerX, centerY);
      function drawArm(position, lengthScale, weight) {
         processing.strokeWeight(weight);
         processing.line(centerX, centerY,
         centerX + Math.sin(position * 2 * Math.PI) * lengthScale * maxArmLength,
         centerY - Math.cos(position * 2 * Math.PI) * lengthScale * maxArmLength);
      }

      processing.background(224);
      var now = new Date();
      var hoursPosition = (now.getHours() % 12 + now.getMinutes() / 60) / 12;
      drawArm(hoursPosition, 0.5, 5);
      var minutesPosition = (now.getMinutes() + now.getSeconds() / 60) / 60;
      drawArm(minutesPosition, 0.80, 3);
      var secondsPosition = now.getSeconds() / 60;
      drawArm(secondsPosition, 0.90, 1);
      };
   }

   var canvas = document.getElementById("canvas");
   var processingInstance = new Processing(canvas, sketchProc);
   </script>
</body>
</html>
2 of 3
1

You don't have to be online to run JavaScript. JavaScript is a client-side language, meaning it runs in your web browser. Since you're at the JavaScript stage, I'm going to assume you know at least the basics of HTML and hopefully CSS.

You can include a JavaScript file in your HTML document by placing this tag in the section.

<html>
  <head>
  <script src="/path/relavite/to/htmlpage/your.js"></script>
  </head>
...
</html>

Then, you can either open your browser, then File > Open your html page, which now has the JavaScript linked to it, or you can right click the .html file in your file browser, and Open With > Chrome, FireFox, etc. to view the page locally.

Again, a connection to the web is not needed to run these files, since they are stored locally on your computer.

EDIT Might as well include the file structure. It may be easier to visualize that way.

Locally on your computer, you create a folder named "myjavascripttest". Inside this folder, you create three files: index.html, style.css and script.js

The content of the HTML file is:

<html>
  <head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script src="/path/relavite/to/htmlpage/your.js"></script>
  <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <p>This is a paragraph</p>
  </body>
</html>

The content of the CSS file is:

p {
  background-color: blue;
}

The content of the JavaScript file is: (Note: this is jQuery, an extension of JavaScript)

$(document).ready(function() {
    $(this).css('background-color', 'red');
});

Now, loading the HTML file in your browser will display a paragraph with a red background, though clearly the CSS says it should be blue. The JavaScript thus must be running!

๐ŸŒ
GitHub
github.com โ€บ AnyChart โ€บ GraphicsJS
GitHub - AnyChart/GraphicsJS: A lightweight JavaScript graphics library with the intuitive API, based on SVG/VML technology.
GraphicsJS is a JavaScript graphics library that allows you to draw absolutely anything, including any sort of interactive and animated graphics with any visual effects.
Starred by 996 users
Forked by 69 users
Languages ย  JavaScript 98.2% | Python 1.8% | JavaScript 98.2% | Python 1.8%
๐ŸŒ
Davebsoft
davebsoft.com โ€บ programming-for-kids โ€บ classes โ€บ p5js
Animated Graphics Programming with JavaScript and p5.js
JavaScript is a popular programming language, especially for programs that run in a web browser. p5.js is a JavaScript framework for combining animation, graphics, sound and art with programming.
๐ŸŒ
Reddit
reddit.com โ€บ r/graphicsprogramming โ€บ what is your experience with javascript libraries for 3d graphics?
r/GraphicsProgramming on Reddit: What is your experience with JavaScript libraries for 3D graphics?
June 8, 2023 -

I am part of the development of a new JavaScript library called utahpot.js, aimed at simplifying the usage of 3D graphics in web development. We are currently in the early stages and would like to gather information about your experience with similar libraries such as Three.js, Babylon.js, or p5.js.

What were the pros and cons of using these libraries? Were there any challenges that hindered the development process?

Thanks in advance for your answers.

Top answer
1 of 2
11
I haven't used a great deal of 3D JS libraries, but I've used a few, and here are my thoughts (as of several years ago): Most 'real' 3D renderers are setup from day 1 to run in an asynchronous, multithreaded environment. While JS doesn't have great support for multithreaded programming, it does have some (webworkers), and none of the libraries I've used even acknowledge that this is a thing, let alone have well thought-out APIs for doing things in a MT environment. They're slow as ****. Three.js in particular (when I used it ~5 years ago) started to roll over and die on nominally complex scenes; a few hundred static entities, and a handful of moving, animated ones. They seem like they weren't written by people who have worked on high quality commercial renderers. My experience overall suggests that the folks that have written the 3D JS libraries aren't people who have deep experience working on these types of systems. I get this read by observing features that are extremely basic, extremely important, but conspicuously missing. For example, last I checked, you could not load a texture asynchronously (on a separate thread) into a three.js texture object. That means, if you're loading textures over the network, your main thread blocks while it downloads textures. WTF!? This is a complete non-starter for anything but extremely basic projects. This was a common theme. Every 3D JS library I surveyed seemed like it was built with the idea in mind that the whole world would be constructed at load time, and subsequently almost never change. Maybe entities would move around or whatever.. but as soon as you try to start streaming assets they completely give up. As I mentioned earlier, these anecdotes are from several years ago, and the situation might be better now. That said, if I were to bite off a project like this, I would write the renderer in C (or C++, or Rust, or whatever), compile it to WASM, and expose a JS interface. From what I can tell, javascript is not the language to write a high-quality rendering/game framework in.
2 of 2
3
I used three.js for some games prototyping. It's pleasant to work with but very feature-light. The upshot is that the entire codebase is grokkable by one person (about 50k LOC) so you can change it as needed. But boy did I reach the point where I needed to quickly. Limitations I encountered within a few weeks: The default rendering order of translucent objects isn't very clever, so to avoid depth errors I'd need to manually manage rendering order The recommended approach to composing (combining) shaders is string operations There isn't a built-in way import assets of various formats; I wound up breaking out the Editor's asset loading tools, but that was a few days of work Speaking of which, the editor is very minimally featured in general and more of a proof of concept than a practical tool; it was while scoping out the required changes to the editor to create basic scenes that I opted to abandon JS for my project