Skip to content
Related Articles

Related Articles

How to Design Flat Shading Graphics using p5.js ?

Improve Article
Save Article
  • Last Updated : 12 Jan, 2021
Improve Article
Save Article

Flat shading is a lighting technique used in 3D computer graphics to shade each polygon of an object based on the angle between the polygon’s surface normal and the direction of the light source, their respective colors and the intensity of the light source.

  • Color is computed once for each face of the polygon.
  • All pixels in a polygon are set to the same color
  • Works for objects made of flat faces.



// Store the angle value in a variable
var angle = 0.1;
// Set the canvas size
function setup() {
    createCanvas(500, 500, WEBGL);
// Function to draw the Flat 
// Shading Graphics
function draw() {
    // Create a directional light with 
    // specified color and direction
    directionalLight(25, 250, 50, 101, 0, 0);
    // Set the background color
    background(50, 50, 200);
    // Set the rotation angle
    rotateY(angle * 0.3);
    rotateZ(angle * 1.2);
    // Set the fill color
    fill(0, 0, 205);
    angle += 0.03;


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!