|
| 1 | +import React, {useState, useEffect} from 'react'; |
| 2 | +import {Link} from 'react-router-dom'; |
| 3 | +import {ArrowLeftIcon, CirclesFourIcon} from '@phosphor-icons/react'; |
| 4 | +import colors from '../../config/colors'; |
| 5 | +import useSeo from '../../hooks/useSeo'; |
| 6 | + |
| 7 | +const BUBBLE_COUNT = 100; // Number of bubbles |
| 8 | + |
| 9 | +const BubbleWrapPage = () => { |
| 10 | + useSeo({ |
| 11 | + title: 'Bubble Wrap | Fezcodex', |
| 12 | + description: 'Pop some virtual bubble wrap to relieve stress.', |
| 13 | + keywords: ['Fezcodex', 'bubble wrap', 'stress relief', 'pop', 'game'], |
| 14 | + ogTitle: 'Bubble Wrap | Fezcodex', |
| 15 | + ogDescription: 'Pop some virtual bubble wrap to relieve stress.', |
| 16 | + ogImage: 'https://fezcode.github.io/logo512.png', |
| 17 | + twitterCard: 'summary_large_image', |
| 18 | + twitterTitle: 'Bubble Wrap | Fezcodex', |
| 19 | + twitterDescription: 'Pop some virtual bubble wrap to relieve stress.', |
| 20 | + twitterImage: 'https://fezcode.github.io/logo512.png', |
| 21 | + }); |
| 22 | + |
| 23 | + const [bubbles, setBubbles] = useState(Array(BUBBLE_COUNT).fill(false)); |
| 24 | + const [popCount, setPopCount] = useState(0); |
| 25 | + |
| 26 | + // Audio context for simple pop sound |
| 27 | + const [audioContext, setAudioContext] = useState(null); |
| 28 | + |
| 29 | + useEffect(() => { |
| 30 | + setAudioContext(new (window.AudioContext || window.webkitAudioContext)()); |
| 31 | + }, []); |
| 32 | + |
| 33 | + const playPopSound = () => { |
| 34 | + if (!audioContext) return; |
| 35 | + |
| 36 | + const oscillator = audioContext.createOscillator(); |
| 37 | + const gainNode = audioContext.createGain(); |
| 38 | + |
| 39 | + oscillator.connect(gainNode); |
| 40 | + gainNode.connect(audioContext.destination); |
| 41 | + |
| 42 | + oscillator.type = 'square'; // Change to square wave for a harsher sound |
| 43 | + oscillator.frequency.value = 100 + Math.random() * 200; // Lower frequency for more bass |
| 44 | + |
| 45 | + const now = audioContext.currentTime; |
| 46 | + gainNode.gain.setValueAtTime(0.5, now); // Start louder |
| 47 | + gainNode.gain.exponentialRampToValueAtTime(0.001, now + 0.08); // Faster and shorter decay |
| 48 | + |
| 49 | + oscillator.start(now); |
| 50 | + oscillator.stop(now + 0.08); // Very short duration |
| 51 | + }; |
| 52 | + |
| 53 | + const popBubble = (index) => { |
| 54 | + if (bubbles[index]) return; // Already popped |
| 55 | + |
| 56 | + const newBubbles = [...bubbles]; |
| 57 | + newBubbles[index] = true; |
| 58 | + setBubbles(newBubbles); |
| 59 | + setPopCount((prev) => prev + 1); |
| 60 | + playPopSound(); |
| 61 | + }; |
| 62 | + |
| 63 | + const resetBubbles = () => { |
| 64 | + setBubbles(Array(BUBBLE_COUNT).fill(false)); |
| 65 | + setPopCount(0); |
| 66 | + }; |
| 67 | + |
| 68 | + const cardStyle = { |
| 69 | + backgroundColor: colors['app-alpha-10'], |
| 70 | + borderColor: colors['app-alpha-50'], |
| 71 | + color: colors.app, |
| 72 | + }; |
| 73 | + |
| 74 | + return ( |
| 75 | + <div className="py-16 sm:py-24"> |
| 76 | + <div className="mx-auto max-w-7xl px-6 lg:px-8 text-gray-300"> |
| 77 | + <Link |
| 78 | + to="/apps" |
| 79 | + className="text-article hover:underline flex items-center justify-center gap-2 text-lg mb-4" |
| 80 | + > |
| 81 | + <ArrowLeftIcon size={24}/> Back to Apps |
| 82 | + </Link> |
| 83 | + <h1 className="text-4xl font-bold tracking-tight sm:text-6xl mb-4 flex items-center justify-center"> |
| 84 | + <span className="codex-color">fc</span> |
| 85 | + <span className="separator-color">::</span> |
| 86 | + <span className="apps-color">apps</span> |
| 87 | + <span className="separator-color">::</span> |
| 88 | + <span className="single-app-color">pop</span> |
| 89 | + </h1> |
| 90 | + <hr className="border-gray-700"/> |
| 91 | + <div className="flex justify-center items-center mt-16"> |
| 92 | + <div |
| 93 | + className="group bg-transparent border rounded-lg shadow-2xl p-6 flex flex-col justify-between relative transform overflow-hidden h-full w-full max-w-3xl" |
| 94 | + style={cardStyle} |
| 95 | + > |
| 96 | + <div |
| 97 | + className="absolute top-0 left-0 w-full h-full opacity-10" |
| 98 | + style={{ |
| 99 | + backgroundImage: |
| 100 | + 'radial-gradient(circle, white 1px, transparent 1px)', |
| 101 | + backgroundSize: '10px 10px', |
| 102 | + }} |
| 103 | + ></div> |
| 104 | + <div className="relative z-10 p-1 text-center"> |
| 105 | + <h1 className="text-3xl font-arvo font-normal mb-4 text-app flex items-center justify-center gap-2"> |
| 106 | + <CirclesFourIcon size={32}/> Bubble Wrap |
| 107 | + </h1> |
| 108 | + <hr className="border-gray-700 mb-6"/> |
| 109 | + |
| 110 | + <div className="flex justify-between items-center mb-6 px-4"> |
| 111 | + <div className="text-xl font-bold">Popped: {popCount}</div> |
| 112 | + <button |
| 113 | + onClick={resetBubbles} |
| 114 | + className="px-4 py-2 rounded-md text-sm font-arvo font-normal border transition-colors duration-300 hover:bg-white/10" |
| 115 | + style={{borderColor: cardStyle.color, color: cardStyle.color}} |
| 116 | + > |
| 117 | + Get a fresh sheet |
| 118 | + </button> |
| 119 | + </div> |
| 120 | + |
| 121 | + <div className="grid grid-cols-5 sm:grid-cols-10 gap-2 justify-items-center"> |
| 122 | + {bubbles.map((isPopped, index) => ( |
| 123 | + <button |
| 124 | + key={index} |
| 125 | + onClick={() => popBubble(index)} |
| 126 | + className={`w-12 h-12 rounded-full border-2 transition-all duration-100 relative overflow-hidden focus:outline-none |
| 127 | + ${isPopped |
| 128 | + ? 'bg-transparent scale-95 opacity-50 border-gray-600' |
| 129 | + : 'bg-white/10 hover:bg-white/20 scale-100 cursor-pointer' |
| 130 | + }`} |
| 131 | + style={{ |
| 132 | + borderColor: isPopped ? 'gray' : cardStyle.color, |
| 133 | + boxShadow: isPopped ? 'inset 0 0 5px rgba(0,0,0,0.5)' : '0 4px 6px rgba(0,0,0,0.3)' |
| 134 | + }} |
| 135 | + > |
| 136 | + {!isPopped && ( |
| 137 | + <div className="absolute top-2 left-2 w-3 h-3 bg-white rounded-full opacity-30 blur-[1px]"></div> |
| 138 | + )} |
| 139 | + </button> |
| 140 | + ))} |
| 141 | + </div> |
| 142 | + |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + ); |
| 149 | +}; |
| 150 | + |
| 151 | +export default BubbleWrapPage; |
0 commit comments