p5.js specularMaterial() Function Last Updated : 23 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The specularMaterial() function in p5.js is used to create a specular material for a geometry with the given color. The specular material is a shiny reflective material. It also defines the color that the object would reflect. If the specular material is set to reflect only red, then it would reflect only the red color, else the object would not reflect any light of any other color. Syntax: specularMaterial( v1, [v2], [v3] ) OR specularMaterial( color ) Parameters: This function accept four parameters as mentioned above and described below: v1: It is a number which determines the gray value, or the red or hue value relative to the current color range. v2: It is a number which determines the green or saturation value relative to the current color range. It is an optional parameter. v3: It is a number which determines the blue or brightness value relative to the current color range. It is an optional parameter. color: It is a p5.Color or color string which defines the color of the specular material. Below example illustrates the directionalLight() function in p5.js: Example: javascript let newFont; let currentLightColor = "red"; let currentSpecularColor = "red"; function preload() { newFont = loadFont('fonts/Montserrat.otf'); } function setup() { createCanvas(600, 300, WEBGL); textFont(newFont, 16); materialColorSel = createSelect(); materialColorSel.position(30, 70); materialColorSel.option('red'); materialColorSel.option('green'); materialColorSel.option('blue'); materialColorSel.changed(() => { currentSpecularColor = materialColorSel.value(); }); lightColorSel = createSelect(); lightColorSel.position(30, 120); lightColorSel.option('red'); lightColorSel.option('green'); lightColorSel.option('blue'); lightColorSel.changed(() => { currentLightColor = lightColorSel.value(); }); } function draw() { background('white'); fill('black'); text("Select an option below to set the light" + " and specular material color", -285, -125); text("Select directional light color", -285, -100); text("Select specular material color", -285, -50); shininess(10); noStroke(); // Set the specular material to the selected color specularMaterial(currentSpecularColor); // Set the directional to the selected color directionalLight(color(currentLightColor), height / 2, width / 2, -250); // Draw the sphere translate(100, 0, 0); sphere(100); translate(-100, 0, 0); } Output: Online editor: https://editor.p5js.org/ Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/ Reference: https://p5js.org/reference/#/p5/specularMaterial Comment More infoAdvertise with us Next Article p5.js specularMaterial() Function sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js specularColor() Function The specularColor() function in p5.js is used to set the color of the specular highlight when it is used with the specular material and highlight. This method is usually used with the specularMaterial() and shininess() functions to define the specular highlights. There would be no effect of this fun 2 min read p5.js sphere() function The sphere() function in p5.js is used to draw a sphere with given radius. Syntax: sphere( radius ) Parameters: This function accepts single parameter radius which stores the radius of the sphere. Below programs illustrate the sphere() function in p5.js: Example 1: This example uses sphere() functio 1 min read p5.js square() Function The square() function is an inbuilt function in p5.js which is used to draw the square on the screen. A square contains four equal sides and four angles each of 90 degrees. It is the special case of a rectangle where width and height are equal. Syntax: square( x, y, s, tl, tr, br, bl ) Parameters: T 2 min read p5.js saturation() function The saturation() function in p5.js is used to extract the HSL and HSB saturation value from a color or pixel array. Syntax: saturation(c) Parameters: ThIS function accepts single parameter c which stores the p5.Color object, color components, or CSS color. Below programs illustrate the saturation() 2 min read p5.js triangle() Function The triangle() function is an inbuilt function in p5.js which is used to draw a triangle in a plane. This function accepts three vertices of triangle.Syntax:Â Â triangle(x1, y1, x2, y2, x3, y3) Parameters: This function accepts six parameters as mentioned above and described below:Â Â x1: This paramet 1 min read Like