A visual, animated exploration of recursive palindrome detection
...loading...
Canvas:
Grid:
🔤 Word / Phrase
🌐 Environment
💡 About This Example — Palindrome Checker
This is a standalone SketchWave example that visually
demonstrates how a recursive isPalindrome() function
works, using animated SWCharacter objects to bring each step
of the recursion to life on a live canvas.
💡 How This Example Works
Type a word or phrase — or use the preloaded classic
"Never odd or even!" — and press
🔍 Analyze. The app strips spaces and punctuation with a
pop animation, slides the remaining letters to their new centered positions,
then begins the animated palindrome analysis.
Each letter is drawn as a colored SWCharacter on the grid.
Spaces and punctuation are removed with a pop-and-shrink animation before analysis starts.
The algorithm works from the outside in, flying each outer pair upward to compare them.
Matched pairs scatter off screen; mismatches shake and dim the whole word.
A successful palindrome triggers a celebration wave.
Press G to toggle the grid on or off at any time.
🔍 Analyze / ⏸ Pause — runs or pauses the animation.
↺ Reset — clears the animation and restores all letters.
💾 Save Image — captures a snapshot of the canvas.
Use the Letter size, Letter spacing, and Animation speed sliders to customize the display.
🧑💻 Developer Notes
Developer
klp
Date
March 28, 2026
Commentary
Stage 1: word input with preloaded phrase
"Never odd or even!", animated
isPalindrome() visualization with strip/slide
preprocessing, pair-comparison state machine, and
adjustable size, spacing, and speed controls.
📄 isPalindrome() Source Code
The animation visualizes the following recursive function.
Each comparison of the outer pair corresponds to one
FLY_UP → TAP → FLY_AWAY animation cycle.
JavaScript
/**
* Returns true if str is a palindrome (reads the same
* forwards and backwards), ignoring case.
*
* Preprocessing: strip all non-alphanumeric characters
* and convert to lowercase before calling.
*
* @param {string} str - cleaned, lowercase input string
* @returns {boolean}
*/
function isPalindrome(str) {
// Base cases — empty string or single character
if (str.length <= 1) return true;
// Mismatch on the outer pair → not a palindrome
if (str[0] !== str[str.length - 1]) return false;
// Recurse on the inner substring (strip one char from each end)
return isPalindrome(str.slice(1, str.length - 1));
}
Java
/**
* Returns true if s is a palindrome (reads the same
* forwards and backwards), ignoring case.
*
* Preprocessing: strip all non-alphanumeric characters
* and convert to lowercase before calling.
*
* @param s cleaned, lowercase input string
* @return true if s is a palindrome
*/
public static boolean isPalindrome(String s) {
// Base cases — empty string or single character
if (s.length() <= 1) return true;
// Mismatch on the outer pair → not a palindrome
if (s.charAt(0) != s.charAt(s.length() - 1)) return false;
// Recurse on the inner substring (strip one char from each end)
return isPalindrome(s.substring(1, s.length() - 1));
}
Python 3
def is_palindrome(s: str) -> bool:
"""
Returns True if s is a palindrome (reads the same
forwards and backwards), ignoring case.
Preprocessing: strip all non-alphanumeric characters
and convert to lowercase before calling.
Args:
s: cleaned, lowercase input string
Returns:
True if s is a palindrome
"""
# Base cases — empty string or single character
if len(s) <= 1:
return True
# Mismatch on the outer pair → not a palindrome
if s[0] != s[-1]:
return False
# Recurse on the inner substring (strip one char from each end)
return is_palindrome(s[1:-1])