BLACKHOLE - A Canvas Experiment
How do I make an blackhole - a canvas experiment?
This is a canvas experiment. To make it have a "Blackhole" effect, tap the fancy blue button. . What is a blackhole - a canvas experiment? How do you make a blackhole - a canvas experiment? This script and codes were developed by Darryl Huffman on 07 January 2023, Saturday.
BLACKHOLE - A Canvas Experiment - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>BLACKHOLE - A Canvas Experiment</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="bg"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
BLACKHOLE - A Canvas Experiment - Script Codes CSS Codes
.bg{ background-image: url(https://i.imgur.com/NI5wtj5.jpg); background-position: center; background-repeat: no-repeat; background-size: init; height: 100%; width: 100%; position: absolute; top: 0px; left: 0px;
}
.button{ width: 130px; border-radius: 5px; text-align: center; line-height: 40px; height: 40px; margin: 100px auto; background-color: #3C3C3C; font-weight: bold; font-size: 12px; cursor: pointer; transition: all 200ms; color: #FFF;
}
.button:hover{ background-color: #515151;
}
body,html{ display: flex; margin: 0; padding: 0; overflow: hidden; background: #191919; min-height: 100%; width: 100%; background-image: url(https://s24.postimg.org/4j23xsrjl/TILE.png);
}
body:before { content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgb(33,33,33); /* Old browsers */
background: -moz-radial-gradient(center, ellipse cover, rgba(33,33,33,1) 0%, rgba(18,18,18,1) 100%); /* FF3.6+ */
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(33,33,33,1)), color-stop(100%,rgba(18,18,18,1))); /* Chrome,Safari4+ */
background: -webkit-radial-gradient(center, ellipse cover, rgba(33,33,33,1) 0%,rgba(18,18,18,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-radial-gradient(center, ellipse cover, rgba(33,33,33,1) 0%,rgba(18,18,18,1) 100%); /* Opera 12+ */
background: -ms-radial-gradient(center, ellipse cover, rgba(33,33,33,1) 0%,rgba(18,18,18,1) 100%); /* IE10+ */
background: radial-gradient(ellipse at center, rgba(33,33,33,1) 0%,rgba(18,18,18,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#212121', endColorstr='#121212',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ opacity: .6;
}
canvas#apparatus{ z-index:1; position: absolute; top: 0px; left: 0px;
}
*{ position: relative; z-index: 2;
}
BLACKHOLE - A Canvas Experiment - Script Codes JS Codes
var go = true;
if(window.location.hash == '#demo'){ setTimeout(function(){ go = false; }, 9500);
}
$('#apparatus').click(function() { $(this).toggleClass('open_blackhole'); $(this).toggleClass('close_blackhole');
});
$('.bg').css('display','none');
// Define Apparatus Variables.
var cw = window.innerWidth, ch = window.innerHeight, blackhole_entities = {}, blackhole_entitiesIndex = 0, blackhole_entitieAmount = 12000, //6000 blackhole_button = $('#apparatus'), canvas = $('<canvas/>').attr({ width: cw, height: ch, id: "apparatus" }).appendTo('body'), context = canvas.get(0).getContext("2d");
var requestframe = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || // IE Fallback, you can even fallback to onscroll function(callback) { window.setTimeout(callback, 1000 / 60) };
// Default Entity "Class"
apparatus.blackhole = function(orbit) { blackhole_entitiesIndex++; this.id = blackhole_entitiesIndex; blackhole_entities[blackhole_entitiesIndex] = this; this.width = .5; this.height = .5; this.orbit = orbit; this.velocity = Math.floor((Math.random() * 3200) + 2500); this.angle = (Math.PI * 2 / this.width) * Math.floor((Math.random() * cw*4) + 10);; var choice = Math.random() * 5; var rands = []; rands.push(Math.random() * 100 + 1); rands.push(Math.random() * 10 + 241); var choice2 = Math.random() * 4; var rands2 = []; rands2.push(Math.random() * 100 + 1); rands2.push(Math.random() * 180 + 211); this.distance = (rands.reduce(function(p, c) { return p + c; }, 0) / rands.length); this.distance2 = (rands2.reduce(function(p, c) { return p + c; }, 0) / rands2.length); this.increase = Math.PI * 2 / this.width; this.distancefix = this.distance; this.distance2fix = this.distance2; this.color = "255,255,255"; this.alpha = 0.6 this.bx = Math.random() * 20 + 1; this.by = Math.random() * 20 + 1; this.inplace = true;
}
apparatus.blackhole.prototype.draw = function() { //context.clearRect(this.y, this.x, this.width, this.height); if (this.orbit >= 3) { this.x = this.bx + this.distance * Math.cos(this.angle / this.velocity) + cw / 2; this.y = this.by + this.distance * Math.sin(this.angle / this.velocity) + ch / 2; this.alpha = 0.6; } else { this.x = this.bx + this.distance2 * Math.cos(this.angle / this.velocity) + cw / 2; this.y = this.by + this.distance2 * Math.sin(this.angle / this.velocity) + ch / 2; this.alpha = 0.4; } if (blackhole_button.hasClass('open_blackhole')) { blackhole_button.removeClass('close_blackhole'); if (this.distance >= 171) { this.distance = this.distance - 4; } else if (this.distance <= 161) { this.distance= this.distance + 8; } if (this.distance2 >= 201) { this.distance2 = this.distance2 - 6; } else if (this.distance2 <= 161) { this.distance2 = this.distance2 + 6; } } if(blackhole_button.hasClass('close_blackhole')){ if (this.distance >= this.distancefix + 4) { this.distance = this.distance - 4; } else if (this.distance <= this.distancefix - 5) { this.distance= this.distance + 5; } if (this.distance2 >= this.distance2fix + 10) { this.distance2 = this.distance2 - 4; } else if (this.distance2 <= this.distance2fix - 10) { this.distance2 = this.distance2 + 4; } } this.angle += this.increase; context.fillStyle = "rgba(" + this.color + "," + this.alpha + ")"; context.fillRect(this.x, this.y, this.width, this.height);
}
for (var i = 0; i < blackhole_entitieAmount; i++) { new apparatus.blackhole((Math.random() * 5));
}
var mode;
apparatus.spawn_blackhole = function(){ for (i in blackhole_entities) { blackhole_entities[i].draw(); }
}
function apparatus() { if(go == true){ requestframe(function() { context.clearRect(0, 0, cw, ch); apparatus.spawn_blackhole(); apparatus(); }); }
}
apparatus();
Developer | Darryl Huffman |
Username | darrylhuffman |
Uploaded | January 07, 2023 |
Rating | 3.5 |
Size | 3,676 Kb |
Views | 8,096 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Orbit | 3,173 Kb |
Hot Arrrr Balloon. | 2,755 Kb |
Spilled Paint | 3,894 Kb |
Followers Solar System | 6,724 Kb |
Math | 2,495 Kb |
Simple SVG Charts | 6,694 Kb |
Spilled Galaxy | 2,163 Kb |
Let it snow, let it snow, code the snow. | 2,884 Kb |
Blackhole | 4,946 Kb |
Pixelot | 3,080 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Atom | Bhlaird | 1,932 Kb |
Animated rainbow wave on canvas | Icodeforlove | 2,777 Kb |
VerbalExpressions Converter | Cmalven | 2,607 Kb |
Awesome Full Page Menu Nav | Ey_intuitive | 4,194 Kb |
AngularJS Datalist Directive | M-e-conroy | 2,366 Kb |
Fun form with currentColor | Bnthor | 2,713 Kb |
CSS3 Form Page Design | Rssatnam | 3,613 Kb |
Vue.js Lazy Loading | Kjbrum | 3,620 Kb |
Two tables and header with jspdf-autotable | Someatoms | 2,245 Kb |
React Recipe Box | Krokodill | 5,347 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!