Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Last active November 3, 2019 09:18
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 Dobby233Liu/157e2438dcfb7a31209616404b301759 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/157e2438dcfb7a31209616404b301759 to your computer and use it in GitHub Desktop.
42.js - quickjs bytebeat isolated loader stub, named after the famous 42 melody
/**
* 42.js - quickjs bytebeat isolated loader stub, named after the famous 42 melody
* code: @Dobby233Liu
* WTFPL
* fill up the code(t) section, build using qjsc https://bellard.org/quickjs/ then pipe to anything eg. aplay
* i recommend use node.js more than quickjs, its better, and quickjs is in beta.
* example program using node.js: bytebeat.jsV2.0 https://pastebin.com/xwtRgcfV
* gist: https://gist.github.com/Dobby233Liu/157e2438dcfb7a31209616404b301759
**/
import * as std from 'std'
"use math"
Object.getOwnPropertyNames(Math).forEach((e)=>{std.evalScript("var "+e+"=Math."+e)}) // dirty globalize
function Bytebeat(){
// place reuseable var above function code(t){, below function Bytebeat(){.
function code(t){ // then there.
return t // stub
}
/* -- example (delete in final)
var a = 0; var b = 0; var c = 0; // place reuseable var above function code(t){, below function Bytebeat(){.
function code_rain_example(t){
// quickjs's nature is you must use var blah=blahblahblah format to define var
// always don't forget to return final value.
// qjs normally in strict mode, octal lit can't work.
var fin=0;
if (t<2){
a = (a*0.999)+(random()*0.001);
(b<0)?(b = random()*0.7,c = random()):(b = b-(1/44100));
fin = abs((a*256*(sin(t/50000)*5+10))%256-128) + ((t/300*((c*10)+200))&2)*255*pow(b,random()/5+4)
}
return fin;
}
fin example -- */
var t=0
var r=0
while(true){
r=code(t)
std.out.putByte(r) // originally i think for String.fromCharCode, but it does shit. putByte is better.
std.out.flush() // then flush the toliet!
t++
}
}
new Bytebeat() // lets go!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment