Skip to content

Instantly share code, notes, and snippets.

@codepediair
Created May 27, 2024 14:45
Show Gist options
  • Save codepediair/341566d246c98ceeb255419369e927b3 to your computer and use it in GitHub Desktop.
Save codepediair/341566d246c98ceeb255419369e927b3 to your computer and use it in GitHub Desktop.
Piano
<html>
<head>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<h3>
Play KeyBoard by pressing (A S D F G H J K L ;)<br> and (W E T Y U O P)
</h3>
<div class="floor"></div>
<!-- thank you: https://woot.co.uk/ -->
<!-- thank you: http://loopable.files.wordpress.com/ http://replygif.net/i/1310.gif -->
<img id= "meme" src="http://www.woot.co.uk/images/bitdance.gif" class="woot-dance" width="328" height="272" alt="8-bit dancing guy">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.1.2/howler.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.4/paper-full.min.js"></script>
<canvas style="position: absolute; margin-top: 20%;" class="squig" resize></canvas>
<canvas class="nowplaying" id="myCanvas" resize></canvas>
<section id="wrap">
<section id="main">
<h3 id="memeq">
Play MEMEBoard by pressing (A S D F G H J K L ;)<br> and (W E T Y U O P)
AND c# for quote
</h3>
<div class="keys">
<canvas id="myCanvasK" data-key="65" class="key" data-note="C">
<span class="hints">A</span>
</canvas>
<canvas id="myCanvasK" data-key="87" class="key sharp" data-note="C#">
<span class="hints">W</span>
</canvas>
<canvas id="myCanvasK" data-key="83" class="key" data-note="D">
<span class="hints">S</span>
</canvas>
<canvas id="myCanvasK" data-key="69" class="key sharp" data-note="D#">
<span class="hints">E</span>
</canvas>
<canvas id="myCanvasK" data-key="68" class="key" data-note="E">
<span class="hints">D</span>
</canvas>
<canvas id="myCanvasK" data-key="70" class="key" data-note="F">
<span class="hints">F</span>
</canvas>
<canvas id="myCanvasK" data-key="84" class="key sharp" data-note="F#">
<span class="hints">T</span>
</canvas>
<canvas id="myCanvasK" data-key="71" class="key" data-note="G">
<span class="hints">G</span>
</canvas>
<canvas id="myCanvasK" data-key="89" class="key sharp" data-note="G#">
<span class="hints">Y</span>
</canvas>
<canvas id="myCanvasK" data-key="72" class="key" data-note="A">
<span class="hints">H</span>
</canvas>
<canvas id="myCanvasK" data-key="85" class="key sharp" data-note="A#">
<span class="hints">U</span>
</canvas>
<canvas id="myCanvasK" data-key="74" class="key" data-note="B">
<span class="hints">J</span>
</canvas>
<canvas id="myCanvasK" data-key="75" class="key" data-note="C">
<span class="hints">K</span>
</canvas>
<canvas id="myCanvasK" data-key="79" class="key sharp" data-note="C#">
<span class="hints">O</span>
</canvas >
<canvas id="myCanvasK" data-key="76" class="key" data-note="D">
<span class="hints">L</span>
</canvas>
<canvas id="myCanvasK" data-key="80" class="key sharp" data-note="D#">
<span class="hints">P</span>
</canvas>
<canvas id="myCanvasK" data-key="186" class="key" data-note="E">
<span class="hints">;</span>
</canvas>
</div>
<audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
<audio data-key="87" src="http://carolinegabriel.com/demo/js-keyboard/sounds/041.wav"></audio>
<audio data-key="83" src="http://carolinegabriel.com/demo/js-keyboard/sounds/042.wav"></audio>
<audio data-key="69" src="http://carolinegabriel.com/demo/js-keyboard/sounds/043.wav"></audio>
<audio data-key="68" src="http://carolinegabriel.com/demo/js-keyboard/sounds/044.wav"></audio>
<audio data-key="70" src="http://carolinegabriel.com/demo/js-keyboard/sounds/045.wav"></audio>
<audio data-key="84" src="http://carolinegabriel.com/demo/js-keyboard/sounds/046.wav"></audio>
<audio data-key="71" src="http://carolinegabriel.com/demo/js-keyboard/sounds/047.wav"></audio>
<audio data-key="89" src="http://carolinegabriel.com/demo/js-keyboard/sounds/048.wav"></audio>
<audio data-key="72" src="http://carolinegabriel.com/demo/js-keyboard/sounds/049.wav"></audio>
<audio data-key="85" src="http://carolinegabriel.com/demo/js-keyboard/sounds/050.wav"></audio>
<audio data-key="74" src="http://carolinegabriel.com/demo/js-keyboard/sounds/051.wav"></audio>
<audio data-key="75" src="http://carolinegabriel.com/demo/js-keyboard/sounds/052.wav"></audio>
<audio data-key="79" src="http://carolinegabriel.com/demo/js-keyboard/sounds/053.wav"></audio>
<audio data-key="76" src="http://carolinegabriel.com/demo/js-keyboard/sounds/054.wav"></audio>
<audio data-key="80" src="http://carolinegabriel.com/demo/js-keyboard/sounds/055.wav"></audio>
<audio data-key="186" src="http://carolinegabriel.com/demo/js-keyboard/sounds/056.wav"></audio>
</section>
</section>
<script src="main.js"></script>
</body>
</html>
const keys = document.querySelectorAll(".key"),
note = document.querySelector(".nowplaying"),
hints = document.querySelectorAll(".hints");
function playNote(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`),
key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
if (!key) return;
var quoteSource=[
{
quote: "Start by doing what's necessary; then do what's possible; and suddenly you are doing the impossible.",
name:"Francis of Assisi"
},
{
quote:"Believe you can and you're halfway there.",
name:"Theodore Roosevelt"
},
{
quote:"It does not matter how slowly you go as long as you do not stop.",
name:"Confucius"
},
{
quote:"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.",
name:"Thomas A. Edison"
},
{
quote:"The will to win, the desire to succeed, the urge to reach your full potential... these are the keys that will unlock the door to personal excellence.",
name:"Confucius"
},
{
quote:"Don't watch the clock; do what it does. Keep going.",
name:"Sam Levenson"
},
{
quote:"A creative man is motivated by the desire to achieve, not by the desire to beat others.",
name:"Ayn Rand"
},
{
quote:"A creative man is motivated by the desire to achieve, not by the desire to beat others.",
name:"Ayn Rand"
},
{
quote:"Expect problems and eat them for breakfast.",
name:"Alfred A. Montapert"
},
{
quote:"Start where you are. Use what you have. Do what you can.",
name:"Arthur Ashe"
},
{
quote:"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.",
name:"Samuel Beckett"
},
{
quote:"Be yourself; everyone else is already taken.",
name:"Oscar Wilde"
},
{
quote:"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
name:"Albert Einstein"
},
{
quote:"Always remember that you are absolutely unique. Just like everyone else.",
name:"Margaret Mead"
},
{
quote:"Do not take life too seriously. You will never get out of it alive.",
name:"Elbert Hubbard"
},
{
quote:"People who think they know everything are a great annoyance to those of us who do.",
name:"Isaac Asimov"
},
{
quote:"Procrastination is the art of keeping up with yesterday.",
name:"Don Marquis"
},
{
quote:"Get your facts first, then you can distort them as you please.",
name:"Mark Twain"
},
{
quote:"A day without sunshine is like, you know, night.",
name:"Steve Martin"
},
{
quote:"My grandmother started walking five miles a day when she was sixty. She's ninety-seven now, and we don't know where the hell she is.",
name:"Ellen DeGeneres"
},
{
quote:"Don't sweat the petty things and don't pet the sweaty things.",
name:"George Carlin"
},
{
quote:"Always do whatever's next.",
name:"George Carlin"
},
{
quote:"Atheism is a non-prophet organization.",
name:"George Carlin"
},
{
quote:"Hapiness is not something ready made. It comes from your own actions.",
name:"Dalai Lama"
}
];
const keyNote = key.getAttribute("data-note");
document.getElementById("meme").src ='http://replygif.net/i/'+Math.floor((Math.random() * 10) + 1)*100;
key.classList.add("playing");
let obj = quoteSource[Math.floor((Math.random() * 24))];
document.getElementById("memeq").innerHTML = obj.quote +" BY "+obj.name;
note.innerHTML = keyNote;
audio.currentTime = 0;
audio.play();
}
function removeTransition(e) {
if (e.propertyName !== "transform") return;
this.classList.remove("playing");
}
function hintsOn(e, index) {
e.setAttribute("style", "transition-delay:" + index * 50 + "ms");
}
hints.forEach(hintsOn);
keys.forEach(key => key.addEventListener("transitionend", removeTransition));
window.addEventListener("keydown", playNote);
const { Path, Point } = paper;
const offset = 10;
const segments = 20;
const strokeWidth = 5;
const strokeColor = 'black';
const canvas = document.querySelector('.squig');
paper.setup(canvas);
const view = paper.view;
const path = new Path();
path.strokeColor = strokeColor;
path.strokeWidth = strokeWidth;
path.strokeCap = 'round';
for (let i = 0; i <= segments; i++) {
let width = view.size.width - (offset * 1);
path.add(new Point((i / segments * width + offset), view.size.height / 2));
}
path.onFrame = (e) => {
for (var i = 0; i <= segments; i++) {
let height = 10;
let sinus = Math.sin(e.time * 3 + i);
path.segments[i].point.y = sinus * height + 25;
path.smooth({
type: 'continuous'
});
}
};
paper.view.draw();
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
html,
body {
margin: 0;
padding: 0;
background-color: #e5e9f0;
}
.floor {
position: fixed;
bottom: 450;
width: 100%;
height: 1000px;
background-color: #e5e9f0;
}
.woot-dance {
position: fixed;
bottom: 450;
transform: translateX(-100px);
animation: dance linear 10s infinite alternate;
}
@keyframes dance {
0% {
transform: translateX(-100px);
}
100% {
transform: translateX(calc(100vw - (290px)));
}
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
background-color: #cf034a;
text-align: center;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
/*********
STYLES
*********/
canvas {
width: 100%;
height: 50%
}
h3{
text-align: center;
font-family: 'Lato', sans-serif;
font-size: 25px;
font-weight: bold;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-image: -webkit-radial-gradient( 110% 50%, circle, rgb(8, 1, 1) 0%,#d487e9 110%,rgb(0, 7, 5));
background-image: radial-gradient( circle at 110% 50%, rgb(5, 0, 1) 0%,#d487e9 110%,rgb(10, 0, 0));
text-decoration: underline;
animation-name: pan-gradient;
animation-iteration-count: infinite;
animation-duration: 5s;
}
@-webkit-keyframes pan-gradient {
0% {
background-position: 0 0;
}
25% {
background-position: -1200px -1200px;
}
50% {
background-position: -1200px 1200px;
}
100% {
background-position: 0 0;
}
}
header {
position: relative;
margin: 30px 0;
}
header:after {
content: '';
width: 460px;
height: 15px;
background: url(images/intro-div.svg) no-repeat center;
display: inline-block;
text-align: center;
background-size: 70%;
}
h1 {
color: #fff;
font-size: 50px;
font-weight: 400;
letter-spacing: 0.18em;
text-transform: uppercase;
margin: 0;
}
h2 {
color: #fff;
font-size: 24px;
font-style: italic;
font-weight: 400;
margin: 0 0 30px;
}
.nowplaying {
font-size: 120px;
line-height: 1;
color: #eee;
text-shadow: 0 0 5rem #028ae9;
transition: all .07s ease;
min-height: 120px;
}
.keys {
display: block;
width: 100%;
height: 350px;
max-width: 880px;
position: relative;
margin: 0px auto 30px;
cursor: none;
}
.key {
position: relative;
border: 4px solid black;
border-radius: .5rem;
transition: all .07s ease;
display: block;
box-sizing: border-box;
z-index: 2;
}
.key:not(.sharp) {
float: left;
width: 10%;
height: 100%;
background: rgba(255, 255, 255, .8);
}
.key.sharp {
position: absolute;
width: 6%;
height: 60%;
background: #000;
color: #eee;
top: 0;
z-index: 3;
}
.key[data-key="87"] {
left: 7%;
}
.key[data-key="69"] {
left: 17%;
}
.key[data-key="84"] {
left: 37%;
}
.key[data-key="89"] {
left: 47%;
}
.key[data-key="85"] {
left: 57%;
}
.key[data-key="79"] {
left: 77%;
}
.key[data-key="80"] {
left: 87%;
}
.playing {
transform: scale(.95);
border-color: #028ae9;
box-shadow: 0 0 1rem #028ae9;
}
.hints {
display: block;
width: 100%;
opacity: 0;
position: absolute;
bottom: 7px;
transition: opacity .3s ease-out;
font-size: 20px;
z-index: 100;
}
.keys:hover .hints {
opacity: 1;
}
.squig {
height: 80px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment