Skip to content

Instantly share code, notes, and snippets.

@kistaaa
kistaaa / colision.js
Created April 14, 2024 16:19
Circle Colision in JS
const checkCollision = (p1x, p1y, r1, p2x, p2y, r2) => ((r1 + r2) ** 2 > (p1x - p2x) ** 2 + (p1y - p2y) ** 2)
var collision = checkCollision(5, 500, 10, 1000, 1500, 1500);
console.log(collision);
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
public GameObject enemyPrefab;
public Transform[] spawnPoints;
public float spawnInterval = 2.0f;
private float spawnTimer = 0.0f;
@kistaaa
kistaaa / obj-to-css-and-back.js
Last active April 29, 2023 22:20
Object and CSS conversion, for using on "style=" in html elements
// object to css
Object.prototype.css = function() {return Object.entries(this).map(([k, v]) => `${k}:${v}`).join(';')}
// css to object
String.prototype.obj = function() {
let obj = {}
let parts = this.split(";")
for(let part of parts){
let prop = part.split(':')
obj[prop[0]] = prop[1]
// Is x really array?
Array.isArray(x)
// Add array y to the end of x
x.concat(y)
// Is y in x?
x.includes(y)
// Which index is y?
{
"keys": {
"0": "C-1",
"1": "C#-1",
"2": "D-1",
"3": "D#-1",
"4": "E-1",
"5": "F-1",
"6": "F#-1",
"7": "G-1",
@kistaaa
kistaaa / randomcolor.svelte
Created February 27, 2023 20:20
Svelte Random Color Generator
<script>
const hex = (d) => Number(d).toString(16).padStart(2, '0')
const rnd = () => Math.floor(Math.random() * 256)
let color = hex(rnd()) + hex(rnd()) + hex(rnd())
const gen = () => color = hex(rnd()) + hex(rnd()) + hex(rnd())
</script>
<style>
.color{display:inline-block; padding:24px; border-radius:50px; vertical-align: middle;}
.text{display:inline-block; font-size:24px; vertical-align: middle;}
@kistaaa
kistaaa / hexnum.js
Last active April 29, 2023 22:07
JS numbers to HEX and reverse
const hex = (num) => num.toString(16).padStart(2, '0')
const num = (hex) => parseInt(hex, 16)
@kistaaa
kistaaa / apply_central_impulse_2d.gd
Last active November 12, 2022 17:58
Godot Impulse 2D of "f" amount in a random direction
extends RigidBody2D
var f = 500
func _ready():
apply_central_impulse(Vector2(rand_range(-f, f),rand_range(-f,f)))
@kistaaa
kistaaa / exponentialRampToValueAtTime.js
Last active November 12, 2022 17:59
Fix Web Audio "click" sound
var context = new AudioContext();
var oscillator = context.createOscillator();
var gainNode = context.createGain();
oscillator.connect(gainNode);
gainNode.connect(context.destination)
oscillator.start();
stopButton.addEventListener('click', function() {
@kistaaa
kistaaa / midi_python_blender.py
Last active November 12, 2022 17:56
Convert midi events to a list for importing in Blender
from mido import MidiFile
tempo=0
noteons = []
notas = []
mid = MidiFile('C:/scripts-python/meow.mid')
for evt in mid:
if not evt.is_meta:
tempo += evt.time
if evt.type == 'note_on':