p5.js unchar() function
Last Updated :
22 Aug, 2023
The unchar() function in p5.js is used to convert a single-character string into its corresponding integer representation. This function is just opposite to the char() function.
Syntax:
unchar(value)
Parameters: This function accepts single parameter value which is to be converted into its corresponding integer representation. This value will be any single-character string or an array of single-characters.
Return Value: It returns the converted integer representation of single-character string.
Below program illustrates the unchar() function in p5.js:
Example 1: This example uses unchar() function to converts a single-character string into its corresponding integer representation.
function setup() {
createCanvas(600, 230);
}
function draw() {
background(220);
let Value1 = "A" ;
let Value2 = "a" ;
let Value3 = "B" ;
let Value4 = "C" ;
let Value5 = "z" ;
let A = unchar(Value1);
let B = unchar(Value2);
let C = unchar(Value3);
let D = unchar(Value4);
let E = unchar(Value5);
textSize(16);
fill(color( 'red' ));
text( "Integer representation of alphabet A is: " + A, 50, 30);
text( "Integer representation of alphabet a is: " + B, 50, 60);
text( "Integer representation of alphabet B is: " + C, 50, 90);
text( "Integer representation of alphabet C is: " + D, 50, 110);
text( "Integer representation of alphabet z is: " + E, 50, 140);
}
|
Output:
Example 2: This example uses unchar() function to converts a single-character string into its corresponding integer representation.
function setup() {
createCanvas(600, 200);
}
function draw() {
background(220);
let A = unchar( "A" );
let B = unchar( "b" );
let C = unchar( "y" );
let D = unchar( "Y" );
let E = unchar( "P" );
textSize(16);
fill(color( 'red' ));
text( "Integer representation of alphabet A is: " + A, 50, 30);
text( "Integer representation of alphabet b is: " + B, 50, 60);
text( "Integer representation of alphabet y is: " + C, 50, 90);
text( "Integer representation of alphabet Y is: " + D, 50, 110);
text( "Integer representation of alphabet P is: " + E, 50, 140);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/unchar
Share your thoughts in the comments
Please Login to comment...