Last active
December 18, 2015 08:39
-
-
Save piroor/5755448 to your computer and use it in GitHub Desktop.
Stress test with one-time gradients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); | |
canvas.width = 100; | |
canvas.height = 100; | |
canvas.setAttribute('style', 'width:100px;height:100px;position:fixed;top:0;right:0;z-index:10000;'); | |
document.documentElement.appendChild(canvas); | |
var context = canvas.getContext('2d'); | |
function random(max) { | |
return parseInt(Math.random() * max); | |
} | |
function createGradient() { | |
var gradient = context.createLinearGradient(0, 0, 100, 100); | |
gradient.addColorStop(0, 'rgba(0,0,0,0)'); | |
gradient.addColorStop(1, 'rgba(' + random(255) + ',' + random(255) + ',' + random(255) + ',255)'); | |
return gradient; | |
} | |
function drawGradien() { | |
context.save(); | |
context.strokeStyle = createGradient(); | |
context.beginPath(); | |
context.lineWidth = 10; | |
context.lineCap = 'square'; | |
context.moveTo(random(100), 0); | |
context.lineTo(random(100), 100); | |
context.closePath(); | |
context.stroke(); | |
context.restore(); | |
} | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); | |
canvas.width = 100; | |
canvas.height = 100; | |
canvas.setAttribute('style', 'width:100px;height:100px;position:fixed;top:0;right:0;z-index:10000;'); | |
document.documentElement.appendChild(canvas); | |
var context = canvas.getContext('2d'); | |
function random(max) { | |
return parseInt(Math.random() * max); | |
} | |
function createGradient() { | |
var gradient = context.createLinearGradient(0, 0, 100, 100); | |
gradient.addColorStop(0, 'rgba(0,0,0,0)'); | |
gradient.addColorStop(1, 'rgba(' + random(255) + ',' + random(255) + ',' + random(255) + ',255)'); | |
return gradient; | |
} | |
var gradient = createGradient(); | |
function drawGradien() { | |
context.save(); | |
context.strokeStyle = gradient; | |
context.beginPath(); | |
context.lineWidth = 10; | |
context.lineCap = 'square'; | |
context.moveTo(random(100), 0); | |
context.lineTo(random(100), 100); | |
context.closePath(); | |
context.stroke(); | |
context.restore(); | |
} | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); | |
window.setInterval(drawGradien, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment