Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Character String example from Processing to Processing.js #1152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/data/examples/en/02_Data/05_Characters_Strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @name Charaters & Strings
* @arialabel A black background with characters and strings.
* @frame 720,400
* @description The character datatype, abbreviated as char, stores letters and
* symbols in the Unicode format, a coding system developed to support
* a variety of world languages. Characters are distinguished from other
* symbols by putting them between single quotes ('P').<br />
* <br />
* A string is a sequence of characters. A string is noted by surrounding
* a group of letters with double quotes ("Processing").
* Chars and strings are most often used with the keyboard methods,
* to display text to the screen, and to load images or files.<br />
* <br />
* The String datatype must be capitalized because it is a complex datatype.
* A String is actually a class with its own methods, some of which are
* featured below.
*/
let letter = "";
let words = "Begin...";
let key = "";

function setup() {
createCanvas(640, 360);
// Create the font
textFont(createFont("SourceCodePro-Regular.ttf", 36));
}

function draw() {
background(0); // Set background to black

// Draw the letter to the center of the screen
textSize(14);
text("Click on the program, then type to add to the String", 50, 50);
text("Current key: " + letter, 50, 70);
text("The String is " + words.length() + " characters long", 50, 90);
textSize(36);
text(words, 50, 120, 540, 300);
}

function keyTyped() {
// The variable "key" always contains the value
// of the most recent key pressed.
if ((key >= "A" && key <= "z") || key === " ") {
letter = key;
words = words + key;
// Write the letter to the console
console.log(key);
}
}