Skip to content

Instantly share code, notes, and snippets.

@yoya
yoya / im_checkboard.sh
Last active January 6, 2024 15:37
checkboard maker powered by ImageMagick
#! /bin/bash
set -euo pipefail
# ImageMagick7 を使う時は convert を magick に書き換えた方が良いです。
IM_CONVERT=convert
if [ $# -ne 7 ];then
echo "Usage: im_checkboard.sh <width> <height> <unitx> <unity> <color1> <color2> <outputfile>"
echo "ex) im_checkboard.sh 100 100 50 70 red green output.png
exit 1
@yoya
yoya / iframe.html
Last active October 24, 2023 08:29
iframe postmessage bidirect
<html>
<body>
<div>
This is iframe
</div>
<script>
const origin = location.origin;
window.onload = () => {
window.addEventListener("message", (resp) => {
console.log("iframe", resp)
@yoya
yoya / wx.TextCtrl-EVT_KILK_FOCUS.py
Created October 7, 2023 05:42
wx.TextCtrl に EVT_KILK_FOCUS をセットするサンプル
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, size=wx.Size(300, 200))
panel = wx.Panel(self, wx.ID_ANY)
self.text = "ABC..."
textCtrl = wx.TextCtrl(panel, wx.ID_ANY, self.text,
size=wx.Size(90, -1), style=wx.TE_PROCESS_ENTER)
for evt in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
@yoya
yoya / sepia-palette-making.sh
Last active March 1, 2023 05:43
sepia-palette-making.sh
#! /bin/sh
magick -size 64x64 xc:"srgb( 30, 5, 3)" sepia-01.png
magick -size 64x64 xc:"srgb( 55, 23, 13)" sepia-02.png
magick -size 64x64 xc:"srgb( 80, 41, 23)" sepia-03.png
magick -size 64x64 xc:"srgb(102, 60, 37)" sepia-04.png
magick -size 64x64 xc:"srgb(122, 82, 58)" sepia-05.png
magick -size 64x64 xc:"srgb(142,107, 84)" sepia-06.png
magick -size 64x64 xc:"srgb(162,135,114)" sepia-07.png
magick -size 64x64 xc:"srgb(181,158,137)" sepia-08.png
@yoya
yoya / magick-asm-test.html
Last active December 16, 2022 05:00
sample for magick-asm without build tool.
<html>
<body>
<canvas id="canvasId"> </canvas>
<script type="module">
import { ImageMagick, initializeImageMagick } from './node_modules/@imagemagick/magick-wasm/dist/index.mjs';
const canvas = document.getElementById('canvasId')
initializeImageMagick().then(() => {
ImageMagick.read("logo:", (image) => image.writeToCanvas(canvas));
ImageMagick.readFromCanvas(canvas, (image) => {
const degrees = 90
@yoya
yoya / CMYKrectangle.sh
Last active June 21, 2022 11:18
CMYK rectangle by ImageMagick
convert -size 1024x1024 -background transparent xc: -compose darken \
\( xc: -draw "fill Cyan rectangle 100,100,600,650" \) -composite \
\( xc: -draw "fill Magenta rectangle 200,400,750,900" \) -composite \
\( xc: -draw "fill Yellow rectangle 350,250,1000,650" \) -composite \
-font KaiseiDecol-Regular.ttf +gravity -pointsize 256 -fill black -stroke black -strokewidth 18 \
-draw "rotate 15 text 190,270 C" \
-draw "rotate 0 text 350,870 M" \
-draw "rotate -10 text 700,650 Y" \
-draw "rotate 0 fill white stroke white text 390,620 K" \
CMYK.png ;
@yoya
yoya / RGBcircle.sh
Last active June 21, 2022 14:41
RGB circle by ImageMagick
convert -size 1024x1024 -background transparent xc: -compose lighten \
\( xc: -draw "fill red circle 512,350,512,650" \) -composite \
\( xc: -draw "fill green2 circle 324,650,324,950" \) -composite \
\( xc: -draw "fill blue1 circle 676,650,676,950" \) -composite \
-font KaiseiDecol-Regular.ttf +gravity -pointsize 256 -fill black -stroke black -strokewidth 18 \
-draw "text 420,320 R" \
-draw "rotate -10 text -20,850 G" \
-draw "fill white stroke white rotate 25 text 940,410 B" \
RGB.png ;
@yoya
yoya / dropcanvas.html
Last active June 6, 2022 13:20
file drop & canvas draw with petite-vue
<head>
<meta charset="utf-8">
<meta name="copyright" content="Copyright &copy; 2022/06/06- yoya@awm.jp . All Rights Reserved.">
<style>
.drop_area { min-width:300px; min-height:300px; border:thick solid red; }
.drop_area:hover { background-color:#FF000040; }
</style>
</head>
<body>
<div v-scope="App()" @vue:mounted="mounted">
@yoya
yoya / convolveRepeatedEdge.py
Last active January 30, 2022 14:40
convolve repeated edge
import math
import numpy as np
def convolveRepeatedEdge(arr, kernel):
arrLen = len(arr)
kernelLen = len(kernel)
kernelLen_harf = math.floor((kernelLen - 1) / 2)
if type(arr) is list:
arr2 = [0] * arrLen
else:
@yoya
yoya / typedarray_concat.js
Last active October 14, 2021 03:28
typedarray concat polyfill
(function() {
for (typedarr of [Int8Array, Uint8Array, Uint8ClampedArray,
Int16Array, Uint16Array, Int32Array, Uint32Array,
Float32Array, Float64Array]) {
if (!typedarr.prototype.concat) {
Object.defineProperty(typedarr.prototype, 'concat', {
value: function(b) {
const a = this;
if (!b || !b.length) return a.slice(0);
const c = new a.constructor(a.length + b.length);