Skip to content

Instantly share code, notes, and snippets.

@YerlinMatu
Created June 26, 2017 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YerlinMatu/d4fb1321bdaf2b83b6aa410dd1233f60 to your computer and use it in GitHub Desktop.
Save YerlinMatu/d4fb1321bdaf2b83b6aa410dd1233f60 to your computer and use it in GitHub Desktop.
Ondas Canvas
<center>
<div class="container">
<h1>Ondalab Audition</h1>
<canvas id="pizarra"></canvas>
<button class="btn btn-large" id="btn">Cambiar color</button>
<input type="range" step="1" min="0" max="10" id="rango"/>
</div>
</center>
const lienzo = document.getElementById('pizarra');
const contexto = lienzo.getContext('2d');
let rango = document.getElementById('rango').value;
let ancho = lienzo.width = 600;
let alto = lienzo.height = 300;
let listaColor = ['#43d996', '#f1c40f', '#9b59b6'];
let GeneratorColor = ()=>{
let random = Math.floor(Math.random() * listaColor.length);
return listaColor[random];
}
let trazar = (u)=>{
contexto.lineWidth = 1;
contexto.fillStyle = 'rgb(0,0,0)';
contexto.fillRect(0, 0 , ancho, alto);
for(let i = -60; i < 60; i+=1){
contexto.beginPath();
contexto.moveTo(0, alto / 2);
// dibujar lineas.
for(let j = 0; j < ancho; j+=10){
contexto.lineTo(10 * Math.cos(i) +
j + (0.008 * j * j),
Math.floor(alto / 2 + j / rango *
Math.sin(j / 50 - z / 50 - i / 118) +
(i * rango / 10) * Math.random(j / 25 - (i + z) / 65)));
}
contexto.stroke();
}
}
contexto.strokeStyle = 'white';
let btn = document.getElementById('btn');
btn.addEventListener('click',()=>{
contexto.strokeStyle = GeneratorColor();
})
let z = 0;
let setup = ()=> {
window.requestAnimationFrame(setup);
z += 5;
trazar(z);
}
setup();
.container {
margin: 0 auto;
display: block;
justify-content:center;
h1 { color: white}
}
html {
background-color:#404040;
}
button {
width:200px;
display: block;
margin: 0 auto;
margin-top:20px;
color: #bdbd8c;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css" rel="stylesheet" />
@YerlinMatu
Copy link
Author

Ondalab Audition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment