wwwtyro / space-2d Goto Github PK
View Code? Open in Web Editor NEWFast procedural 2D space scene generation on the GPU.
License: The Unlicense
Fast procedural 2D space scene generation on the GPU.
License: The Unlicense
It could be good to have the white dots of the stars and the nebulae and everything to be generated on a transparent bachground, instead of a black background. That way, you can generate two starscapes and make them move at different speeds, to create a parallax effect.
Not really an issue. But not sure where else I could write this.
I wanted to use your script to create space wallpapers for myself.
Since the canvas context is webgl I needed to preserve the drawing buffer. Otherwise the canvas blob will be blank.
//addition to the canvas settings in bundle.js
var canvas = document.getElementById('render-canvas');
var glContextAttributes = { preserveDrawingBuffer: true };
var gl = canvas.getContext("experimental-webgl", glContextAttributes);
canvas.width = 2560; //window.innerWidth - (300 + 16 + 16 + 16);
canvas.height = 1440; //window.innerHeight - (16 + 16);
I rerender the image by reloading the browser. Maybe you find a better solution that makes the preserveDrawingBuffer work with the gui redraw.
//download img as png on canvas click
(function() {
var canvas = document.querySelector("#render-canvas");
var uri;
canvas.onclick = function(evt) {
evt.preventDefault();
canvas.toBlob(function(blob) {
if(uri)
(window.URL||window.webkitURL).revokeObjectURL(uri);
uri = (window.URL||window.webkitURL).createObjectURL(blob);
var a = document.createElement('a');
a.href = uri;
a.download="stars.png";
document.body.appendChild(a);
a.onclick = function(evt) { this.parentNode.removeChild(this); }
a.click();
});
}
})();
I don't really have a GPU, I played around with the 'height' scroller and my screen went full black for some seconds. I thought that was it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.