Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
pgtwitter / morse.py
Last active March 21, 2025 15:38
モール信号をツリー表示(dotファイル)にするpythonスクリプトをGrok3に書かせてみた.morse.txtを読み込んでmorse_tree.dotを作成する.
# %%
def read_morse_file(filename):
"""モールス信号データをファイルから読み込む"""
morse_data = {}
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
char, code = line.strip().split('\t')
morse_data[char] = code
return morse_data
@pgtwitter
pgtwitter / morse.dot
Last active March 20, 2025 15:48
欧文モールス信号のツリーをGrok3に考えさせて延々とやりとりした成果(?)
digraph MorseTree {
rankdir=TB;
bgcolor="white";
nodesep=0.5; // 左右間隔を維持
pad=0.2; // 余白を維持
// ノード定義
START [shape=rectangle];
E [shape=rectangle]; A [shape=rectangle]; W [shape=rectangle]; J [shape=rectangle];
I [shape=rectangle]; S [shape=rectangle]; H [shape=rectangle]; V [shape=rectangle];
@pgtwitter
pgtwitter / .py
Last active February 6, 2025 22:21
停止点のあるsin(cos)を用いたモーションをつけるコード
# %%
import bpy
import numpy as np
def modified_sin(frames, target_fs, delta, amp, freq, shift, fn):
hold_fs = [f for fs in [list(range(v-delta, v+delta)) for v in target_fs] for f in fs]
cycle = frames - len(hold_fs)
ny = [amp*fn(freq*2*np.pi/cycle*t)-shift for t in range(cycle)]
result = []
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
<div class="mermaid">
flowchart TB
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[Not OK]
</div>
@pgtwitter
pgtwitter / .m
Last active November 20, 2024 05:34
Open a URL with an application ( Objective-C / Cocoa )
[[NSWorkspace sharedWorkspace] openURLs:@[url]
withApplicationAtURL:[NSURL fileURLWithPath:@"/Applications/Safari.app"]
configuration:nil
completionHandler:^(NSRunningApplication * _Nullable app, NSError * _Nullable error) {
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}];
@pgtwitter
pgtwitter / .r
Last active November 19, 2024 13:27
Find the distance between any point and a Bézier curve (find the parameter t that is the closest point on the Bézier curve). reference: https://shikitenkai.blogspot.com/2024/11/bezier.html
# %%
colors <- rainbow(length(1:5))
bezier_poly <- function(a, b, c, d, t) {
return((1 - t)^3 * a
+ 3 * (1 - t)^2 * t * b
+ 3 * (1 - t) * t^2 * c
+ t^3 * d)
}
bezier_point <- function(ps, t) {
x <- bezier_poly(ps[1, 1], ps[2, 1], ps[3, 1], ps[4, 1], t)
@pgtwitter
pgtwitter / AppDelegate.h
Last active November 29, 2024 06:04
Find the distance between any point and a Bézier curve (find the parameter t that is the closest point on the Bézier curve). reference: https://shikitenkai.blogspot.com/2024/11/bezier.html
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
@pgtwitter
pgtwitter / .py
Created November 4, 2024 05:24
ポアンカレの円板(参考 https://qiita.com/hibit/items/5a49bedaa826fddf0a33 を 縦横比を1にしたもの)
# %%
# reference https://qiita.com/hibit/items/5a49bedaa826fddf0a33
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set(aspect=1)
theta = np.linspace(0, 2*np.pi, 100)
colorlist = ["r", "g", "b", "c", "m", "y"]
@pgtwitter
pgtwitter / .py
Last active October 14, 2024 02:45
greatest common divisor
# %%
def gcd(a, b):
a, b = (a, b % a) if a < b else (b, a % b)
return (a, b) if b == 0 else gcd(a, b)
gcd(3525, 4794)
@pgtwitter
pgtwitter / MyView.m
Created October 9, 2024 20:09
Circumscribed Circle
#import <Cocoa/Cocoa.h>
@interface MyView : NSView
@end
@implementation MyView
double len(NSPoint p){return sqrt(p.x*p.x+p.y*p.y);}
NSRect bboxOfCircumscribedCircle(NSPoint p0, NSPoint p1, NSPoint p2) {
double a= len(NSMakePoint(p2.x-p1.x, p2.y-p1.y));
double b= len(NSMakePoint(p2.x-p0.x, p2.y-p0.y));
double c= len(NSMakePoint(p1.x-p0.x, p1.y-p0.y));
double Ca=a*a*(b*b+c*c-a*a);