Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head></head>
<body style="background: black;">
<canvas id="canvas" width="500" height="500"></canvas>
<script>
const el = document.getElementById("canvas");
// ctx.fillRect(0, 0, 500, 500);
const vertexes = [
{x: 100, y: 100, c: [0, 0, 1]},
@carrotflakes
carrotflakes / main.rs
Last active October 8, 2023 07:53
great-circular distance and its derivative
fn distance_on_sphere(lat1: f32, lon1: f32, lat2: f32, lon2: f32) -> f32 {
let dlat = (lat2 - lat1).abs();
let dlon = (lon2 - lon1).abs();
let a = (dlat * 0.5).sin().powi(2) + lat1.cos() * lat2.cos() * (dlon * 0.5).sin().powi(2);
2.0 * a.sqrt().asin()
}
fn differential_distance_on_sphere(lat1: f32, lon1: f32, lat2: f32, lon2: f32) -> [f32; 2] {
let diff = 1.0;
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="output"></div>
<input type="range" id="kp" min="-1" max="2" value="0" step="0.1" />
<input type="range" id="ki" min="-1" max="2" value="0" step="0.1" />
<input type="range" id="kd" min="-1" max="2" value="0" step="0.1" />
<body>
<canvas id="canvas" width="800" height="800" />
<script>
const el = document.getElementById("canvas")
const ctx = el.getContext("2d")
ctx.lineWidth = 2
function line(x1, y1, x2, y2) {
ctx.beginPath()
ctx.moveTo(x1, y1)
@carrotflakes
carrotflakes / main.rs
Created August 13, 2020 18:28
Rust function that takes mut ref and returns FnMut
fn f<'a>(i: &'a mut i32) -> impl FnMut() -> i32 + 'a {
move|| {*i = *i + 1; *i}
}
fn main() {
let mut i = 0;
{
let mut ff = f(&mut i);
dbg!(ff());
dbg!(ff());
@carrotflakes
carrotflakes / main.rs
Last active November 29, 2019 16:37
[WIP] A Lisp implementation in Rust =>https://github.com/carrotflakes/gluten
use std::rc::Rc;
use std::cell::RefCell;
use std::str::Chars;
type R<T> = Rc<RefCell<T>>;
#[derive(Debug, Clone)]
enum V {
Symbol(String),
Int(i64),
nextto(X, Y, List) :- iright(X, Y, List).
nextto(X, Y, List) :- iright(Y, X, List).
iright(Left, Right, [Left, Right | _]).
iright(Left, Right, [_ | Rest]) :- iright(Left, Right, Rest).
zebra(H, W, Z) :-
H = [house(norwegian, _, _, _, _), _, house(_, _, _, milk, _), _, _],
member(house(englishman, _, _, _, red), H),
member(house(spaniard, dog, _, _, _), H),
member(house(_, _, _, coffee, green), H),
member(house(ukrainian, _, _, tea, _), H),
% 知識
food("中華料理").
food("フランス料理").
food("イタリア料理").
place("新宿").
place("渋谷").
place("池袋").
restaurant("川香苑 本店", "中華料理", "新宿", 3000).
@carrotflakes
carrotflakes / 28.js
Created August 27, 2019 13:22
28 the virtual machine
// Basic instructions
const NOP = 0;
const MOVE = 5;
const MOVE_2_1 = 6;
const STORE_TO_M0 = 10;
const STORE_TO_M1 = 11;
const STORE_TO_C1 = 12;
const SET_MC1_ROOT = 15;
const SET_C1_ROOT = 16;
const RESOLVE = 20;
@carrotflakes
carrotflakes / make_movie.rs
Last active August 25, 2023 09:01
Generate a movie by Rust with FFmpeg.
use std::io::Write;
use std::process::{Command, Stdio};
fn make_frame(width: usize, height: usize, time: usize) -> Vec<u8> {
let mut frame = Vec::with_capacity(4 * width * height);
for y in 0..height {
for x in 0..width {
frame.push((x % 256) as u8);
frame.push((y % 256) as u8);
frame.push((time % 256) as u8);