Cosmic
Cosmic is a simple Javascript and WASM runtime for developing Desktop, Gaming, Backend, and Web applications. Our approach is to start with V8 (the fastest script engine) and design a rich API and tools around it. To get a gauge of what Cosmic can do now, check out the docs for each API module as well as the Tools section.
NOTE: Although the docs and public showcase present everything to be working, Cosmic is still considered experimental software since it's still in its infancy.
Native API
One of the goals of Cosmic is to provide a cross platform Js/Wasm API to do all the neat things your computer can do. This means having a window API, a 2D/3D graphics API, a multimedia API, a networking API, a file system API, and more. On top of these basic layers, Cosmic will also provide higher level constructs like a UI framework, an animation API, and more.
Supporting the Web/Node API is a non goal, but Cosmic will have similar features. For example, "fetch" is implemented as making http requests from the cs.http module. Once the Cosmic API is fleshed out more, it shouldn't be hard for one to create a Web polyfill in pure JS.
Conventions
If you've come from Web or Node development you might be wondering how different it is to code in Cosmic:
- Importing: Code/dependencies will be imported as ES modules from local and the web. Support for node npm packages is a non goal and will only be considered depending on demand.
- Async: All API functions that have an async alternative are synchronous by default. For example, cs.http.get() is synchronous and the async version will be cs.http.getAsync(). Code having clear intentions is a goal for Cosmic. One should feel that they can accomplish anything synchronously and only reach for async when they are ready to or planned to.
- Errors: Synchronous API functions won't throw exceptions for expected errors. null will be returned instead and a follow up errCode() or errString() will get you info about the error. Async promises will be rejected with the errString() as the message and errCode() in Error.code.
Cosmic is aiming to make coding accessible, unrestrictive, productive, fast, and fun! Like what you see? Join our community and voice your opinions!
Install
Download links can be found here: Downloads.
One liner cli install commands will make it here eventually.
Getting Started
Hello World
First make sure you have downloaded Cosmic for your platform. Open up your text editor and create hello.js:
const Color = cs.graphics.Color
puts('Hello World!')
const w = cs.window.create(1200, 720, 'Demo')
w.onUpdate(g => {
g.fontSize(52)
g.fillColor(Color.blue)
g.text(400, 300, 'Hello World!')
})
Then run this in the terminal:
cosmic hello.js
Try out more examples:
git clone https://github.com/fubark/cosmic.git
cosmic cosmic/examples/paddleball.js
cosmic cosmic/examples/demo.js
You can find more examples here!
Tools
One of the goals for Cosmic is to provide useful tools to help you develop software.
This runs your script with the cosmic runtime. You can also run foo.js with "cosmic foo.js".
This runs your script but also watches it for changes to do hot reloading. This feature is not implemented yet.
Runs tests in foo.test.js.
Creates a single binary executable for your app at foo.js. This feature is not implemented yet.
You'll also be able to target the Web as a platform and it will generate the html/js bundle you'll need.
Eventually you'll be able to create an executable for a foreign target platform!
Starts hosting a HTTP web server over your static files in the public directory.
Like `cosmic http` but secure. You'll need to supply your public and private keys.
Starts a shell where you can perform quick calculations or experiment with the API before creating a script. Note: The window API does not work in the shell currently.
Do you think we're missing something? Voice your opinion on Discord or open an issue on Github!
Tutorials
Tutorials and learning material will be posted up when they are available.
Windowing
2D Graphics
UI and Widgets
3D Graphics
Input
Sound
Importing
Error handling
Async
Dev Mode
IntelliSense
Testing
WASM
Exporting
Community
Contributing
Head on over to the github repo to learn how to contribute!