p5.js fill() Function Last Updated : 03 Apr, 2023 Comments Improve Suggest changes Like Article Like Report p5.js fill() function is used to fill the color of the shapes. This function supports all types of color objects. For example RGB, RGBA, Hex CSS color, and all named color strings. The color object can also be set as a string in terms of RGB, RGBA, Hex CSS color, or a named color string. Syntax: fill( v1, v2, v3, alpha ) or fill( value ) or fill( gray, alpha ) or fill( values ) or fill( color ) Parameters: v1: It is used to set the red or hue value relative to the current color range.v2: It is used to set the green or saturation value relative to current color range.v3: It is used to set the blue or brightness value relative to current color range.alpha: It is used to set the transparency of the drawing.value: It is used to set the value of a color string.gray: It is used to set the gray value.values: It is an array containing the red, green, blue, and alpha values.color: It is used to set the stroke color. Below examples illustrate the fill() function in p5.js: Example 1: javascript function setup() { // Create Canvas of given size createCanvas(400, 300); } function draw() { // Set the background color background(220); // Use fill() function to fill color fill('green') // Draw a line rect(50, 50, 150, 150); // Use noFill() function noFill(); // Draw a line rect(100, 100, 150, 150); } Output: Example 2: javascript function setup() { // Create Canvas of given size createCanvas(400, 300); } function draw() { // Set the background color background(220); // Use noFill() function noFill(); // Draw a circle circle(140, 100, 150); // Use fill() function to fill color fill('green'); // Draw a circle circle(240, 100, 150); } Output: Reference: https://p5js.org/reference/#/p5/fill Comment More info J jit_t Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like