跳至主要內容

era.js

我建立了一個可在 JavaScript 中使用的日本年號(和暦)函式庫。

https://himeyama.github.io/era.js/era.js

let date = new Era()
date.getWareki() // "令和X年X月X日" (今日的日期)

date = new Era("2020-1-1")
date.getWareki() // "令和2年1月1日"

date.getWareki("西暦") // "2020/01/01"

date.getDateAry() // ["令和", 2, 1, 1]

Era.date2wareki(id) // 指定 id 將元素轉換為日本年號

getWareki() 的參數

calshorttype顯示
"和暦"true0
1
2
3
4
5
false0
1
2
3
"西暦"true0
1
2
3
4
5
false0
1
2
3
4

JavaScript 筆記

帶索引的 for 迴圈

for([i, e] of ["a", "b", "c"].entries()){
console.log(i, e)
}

也可以用 forEach

["a", "b", "c"].forEach((e, i) => {
console.log(e, i)
})

建立長度為 n 的陣列

const n = 10
let ary = [...Array(n)].map((_, i) => i)
// 或者
ary = Array.from({length: n}).map((_, i)=> i)

陣列求和

let ary = [1, 2, 3, 4, 5]
ary.reduce((_, v) => _ + v)

如何製作圖示(.ico)

  1. 建立圖示。

    如何建立圖示

  2. 準備七張尺寸分別為 1624324864128256 的 PNG 圖片。 如何建立圖示

  3. 使用 convert 指令建立圖示。 如何建立圖示

convert *.png favicon.ico

建立 Electron 應用程式

建立工作目錄

mkdir test-electron-app
cd test-electron-app

建立 package.json

npm init -y

安裝 electron

npm i --save-dev electron

建立 index.js

const { app, BrowserWindow } = require("electron")
const path = require("path")

function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js")
}
})

win.loadFile("index.html")
}

app.whenReady().then(() => {
createWindow()

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit()
}
})

建立 index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
<h1>Hello World!</h1>
<p>
We are using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
</p>
</body>
</html>

修改 package.json

修改 scripts 部分。

"scripts": {
"start": "electron ."
}

執行應用程式

npm start

如何製作 Ruby 擴充功能

這是一個以傳回 3 為範例的程式。

首先,用 C 語言撰寫原始碼。

// three.c
#include <ruby.h>

static VALUE int_three(void){
return INT2NUM(3);
}

void Init_three(void){
rb_define_singleton_method(rb_cInteger, "three", int_three, 0);
}

建立用於生成 Makefile 的腳本。

# extcof.rb
require 'mkmf'
create_makefile "three"

執行 Make

$ make

撰寫 Ruby 腳本來呼叫建立好的程式。

# main.rb
require "./three"
p Integer.three

執行

$ ruby main.rb
3

建立 DLL 並編譯 C

建立 DLL 並編譯 C 的備忘錄

函式庫

原始碼檔案

// gcd.c
int gcd(int a, int b){
return !b ? a : gcd(b, a % b);
}

標頭檔

// gcd.h
#ifndef TEST_H
#define TEST_H

int gcd(int a, int b);

#endif

程式碼

#include <stdio.h>
#include "gcd.h"

int main(void){
printf("%d
", gcd(24, 36));
}

編譯

建立 DLL

gcc gcd.c -shared -o gcd.dll

編譯

gcc main.c -lgcd -L.
標籤:

在 Unity 中生成逼真地形

我嘗試在 Unity 中建立逼真的地形。

以日本國土地理院的衛星影像和高程資料為基礎製作。

Unity 島原半島

接下來,我想製作九州的地形。

使用丙酮轉印製作印刷電路板

我為開發自製測量儀器製作了一塊印刷電路板。

丙酮轉印

用雷射印表機列印在普通紙上,將列印好的紙放在銅板上,用水沾濕後將紙緊壓在銅板上。 接著滴少量丙酮,透過透明文件夾從上方用指甲將碳粉摩擦到銅板上,以丙酮進行轉印。 第一次因為用了太多丙酮而失敗了。 整張均勻浸透的程度是恰當的。 我使用的是 100% 純丙酮去光水。

印刷電路板丙酮轉印

用水清洗並搓揉以去除紙張。

蝕刻

將蝕刻液倒入適當的容器中,用裝有熱水的冷凍袋將溶液加熱至體溫左右再進行蝕刻。 大約 40 到 45℃ 似乎比較適合,但因為溫度計會生鏽所以沒有使用,只是目測估計。 目視確認未遮蔽區域的銅已溶解後,停止蝕刻。

印刷電路板蝕刻

溶解塗層部分

用丙酮溶解以碳粉或油性筆遮蔽的部分。 這樣就只剩下遮蔽區域的銅,從而形成電路。

印刷電路板蝕刻

製作小型電路

打孔並焊接以製作小型電路。 焊接時像是將其鋪放在銅上面一樣進行,會比較容易焊接。

印刷電路板蝕刻