Skip to content

Instantly share code, notes, and snippets.

View AnastasiaDunbar's full-sized avatar
🈚
­

Anastasia Dunbar AnastasiaDunbar

🈚
­
View GitHub Profile
import PIL
from PIL import Image
from PIL import ImageGrab
import os
while(True):
while(True):
imageName=input("Enter filename: ")
if(os.path.isfile(imageName)): #File exists?
image=Image.open(imageName)
break
{
"Drum machines":[
{"name":"Roland TR-606 Drumatix","description":"A programmable analog synthesis drum machine."},
{"name":"Roland TR-707 Rhythm Composer","description":"A programmable digital sample-based drum machine."},
{"name":"Roland TR-808 Rhythm Composer","description":"An analog subtractive synthesis drum machine."},
{"name":"Roland TR-909 Rhythm Composer","description":"A drum machine with samples alongside analog sounds."},
{"name":"Korg Volca Beats","description":"An analog drum machine."},
{"name":"Akai MPC60","description":"An electronic sampler."},
{"name":"Pearl Fightman Electronic Training Drum","description":"An analog FM drum synth module."}
],
// title: Perlin Noise
// author: Anastasia Dunbar
// script: js
var width=240,height=136;
function mix(a,b,t){return(t*(b-a))+a;}
function mod(a,b){return((a%b)+b)%b;}
function fract(x){return x-Math.floor(x);}
function clamp(a,b,c){return Math.min(Math.max(a,b),c);}
function dot(a,b){for(var s=0,i=0;i<a.length;i++){s+=a[i]*b[i];}return s;}
function sign(x){return x>0?1:x<0?-1:0;}
process.stdin.resume(); //Keep process from terminating.
const readline=require("readline"),
rl=readline.createInterface({
input:process.stdin,
output:process.stdout
});
function question(string){
return new Promise(resolve=>
rl.question(string+"\n",answer=>resolve(answer))
);
@AnastasiaDunbar
AnastasiaDunbar / Alphabet.js
Last active July 5, 2018 20:34
Just an alphabet.
var alphabet=[
{letter:"a",consonant:false},
{letter:"b",consonant:true},
{letter:"c",consonant:true},
{letter:"d",consonant:true},
{letter:"e",consonant:false},
{letter:"f",consonant:true},
{letter:"g",consonant:true},
{letter:"h",consonant:true},
{letter:"i",consonant:false},
@AnastasiaDunbar
AnastasiaDunbar / Sarven Desert.js
Last active July 15, 2018 00:27
Stopping right here.
//1-(The Mighty Sand Yak)
for(;;){var e=this.findNearest(this.findEnemies());if(this.distanceTo(e)<10){this.moveXY(this.pos.x+10,this.pos.y);}}
//2-(Oasis)
for(;;){var e=this.findNearest(this.findEnemies());if(e&&this.distanceTo(e)<10){this.moveXY(this.pos.x-10,this.pos.y);}else{this.moveXY(this.pos.x+10,this.pos.y);}}
//3-(Basin Stampede)
for(;;){var e=this.findNearest(this.findEnemies());var X=this.pos.x+5;var Y=17;if(e){if(e.pos.y>this.pos.y){Y-=10;}else if(e.pos.y<this.pos.y){Y+=10;}}this.moveXY(X,Y);}
//4-(Sarven Road)
for(;;){var e=this.findNearest(this.findEnemies());if(e){this.attack(e);}else{this.moveXY(this.pos.x+7,this.pos.y+9);}}
//5-(Crossroads)
var x=this.pos.x,y=this.pos.y;for(;;){var e=this.findNearestEnemy();if(e){if(e.pos.x<this.pos.x){this.buildXY("fire-trap",x-15,y);}else if(e.pos.x>this.pos.x){this.buildXY("fire-trap",x+15,y);}else if(e.pos.y<this.pos.y){this.buildXY("fire-trap",x,y-15);}else if(e.pos.y>this.pos.y){this.buildXY("fire-trap",x,y+15);}}this.moveXY(x,y);}
const LOWPASS=0,HIGHPASS=1,BANDPASS=2;
class Filter{
constructor(mode){
this.cutoff=.99;
this.resonance=0;
this.mode=mode;
this.b0=0;this.b1=0;this.b2=0;this.b3=0;
this.feedbackAmount=0;
this.cutoffMod=0;
@AnastasiaDunbar
AnastasiaDunbar / Interval timer without setInterval().js
Last active November 26, 2018 13:02
A reference for looping timers.
function mod(a,b){return((a%b)+b)%b;}
class Timer{
constructor(callback,delay,tickBy=1,...parameters){
this.callback=callback;
this.duration=delay;
this.timer=delay;
this.tickBy=tickBy;
this.parameters=parameters;
}
tick(){

JavaScript

Automatic semicolon insertion

I embrace semicolons myself and it's more readable too. But the automatic semicolon insertion just might be useful in code golfing scenarios? In this example:

return
something;

will be converted into:

@AnastasiaDunbar
AnastasiaDunbar / Real-time audio processing.js
Last active February 7, 2019 11:00
DIY and no more libraries.
function dsp(time){
var master=Math.sin(Math.PI*2*440*time)*Math.exp(-3*time);
return master;
}
var audioContext=new AudioContext(),
bufferSize=2048, //256,512,1024,2048,4096,8192,16384
node=audioContext.createScriptProcessor(bufferSize,0,2), //bufferSize,inputChannels,outputChannels
time=0;
node.onaudioprocess=event=>{
var L=event.outputBuffer.getChannelData(0),