This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use image::{ImageBuffer, Rgb}; | |
fn main() { | |
let (sx, sy) = (1280, 720); | |
let (cx, cy, _zoom) = (0.2713912051561837, 0.005142969158296763, 1.4210854715202004e-14); | |
let fps = 24; | |
let image_count = fps * 30; | |
let mut zoom = 4.0; | |
for i in 0..image_count { | |
println!("{:04}/{} - m{:04}.png - zoom*{:.8}", i, image_count, i, zoom); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn hsl_to_rgb(h: f64, s: f64, l: f64) -> (u8, u8, u8) { | |
let (mut r, mut g, mut b) = (l, l, l); | |
if s != 0.0 { | |
let hue2rgb = |p: f64, q: f64, t: f64| -> f64 { | |
let mut t = t; | |
if t < 0.0 { t += 1.0; } | |
if t > 1.0 { t -= 1.0; } | |
if t < 1.0 / 6.0 { return p + (q - p) * 6.0 * t; } | |
if t < 1.0 / 2.0 { return q; } | |
if t < 2.0 / 3.0 { return p + (q - p) * (2.0 / 3.0 - t) * 6.0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html><head><meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>マンデルブロ集合</title> | |
</head> | |
<body> | |
<canvas id="cnavas" width="800" height="800"></canvas> | |
</body> | |
<script> | |
// キャンバスと描画用のコンテキストを取得 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html><html><head><meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>マンデルブロ集合</title> | |
</head> | |
<body><canvas id="cnavas" width="800" height="800"></canvas></body> | |
<script> | |
// キャンバスと描画用のコンテキストを取得 --- (*1) | |
const canvas = document.getElementById('cnavas'); | |
const ctx = canvas.getContext('2d'); | |
// 描画の為のパラメータを指定 --- (*2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ライフゲームのプログラム | |
use lazyrand::rand_usize; | |
use std::thread; | |
use std::io::{stdout, Result}; | |
use crossterm::{cursor, execute, terminal, | |
style::{Color, Print, SetBackgroundColor, SetForegroundColor}}; | |
// 定数の宣言 | |
const WIDTH: usize = 80; // グリッドの列数 | |
const HEIGHT: usize = 35; // グリッドの行数 | |
const MAX_TERN: usize = 1000; // 最大世代数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::prelude::*; | |
use std::net::TcpListener; | |
// サーバアドレスを指定 | |
const SERVER_ADDRESS: &str = "127.0.0.1:8888"; | |
fn main() { | |
// HTTPサーバを起動 | |
println!("[HTTPサーバを起動] http://{}", SERVER_ADDRESS); | |
let listener = TcpListener::bind(SERVER_ADDRESS).unwrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// k近傍法(k-nn)によるアヤメの分類プログラム | |
use rand::seq::SliceRandom; | |
// データとラベルを持つ構造体を定義 --- (*1) | |
#[derive(Debug, Clone)] | |
struct KnnItem { | |
data: Vec<f64>, | |
label: String, | |
} | |
// k近傍法でデータを予測する --- (*2) | |
fn knn_predict(items: &[KnnItem], test: &[f64], k: usize) -> String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sepal_length | sepal_width | petal_length | petal_width | class | |
---|---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | Iris-setosa | |
4.9 | 3.0 | 1.4 | 0.2 | Iris-setosa | |
4.7 | 3.2 | 1.3 | 0.2 | Iris-setosa | |
4.6 | 3.1 | 1.5 | 0.2 | Iris-setosa | |
5.0 | 3.6 | 1.4 | 0.2 | Iris-setosa | |
5.4 | 3.9 | 1.7 | 0.4 | Iris-setosa | |
4.6 | 3.4 | 1.4 | 0.3 | Iris-setosa | |
5.0 | 3.4 | 1.5 | 0.2 | Iris-setosa | |
4.4 | 2.9 | 1.4 | 0.2 | Iris-setosa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ライブラリを読み込む --- (*1) | |
const express = require('express'); | |
const OpenAI = require('openai') | |
const path = require('path') | |
// APIキーを設定する(以下は書き換えが必要です★★★) --- (*2) | |
const API_KEY = 'xxx' | |
// const API_KEY = process.env['OPENAI_API_KEY'] | |
// APIキーを設定したオブジェクトを生成 | |
const openai = new OpenAI({ apiKey: API_KEY }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CRC-32のためのキャッシュテーブルを作成する関数 --- (*1) | |
fn crc32_table() -> [u32; 256] { | |
// テーブルを0で初期化 | |
let mut table: [u32; 256] = [0; 256]; | |
let crc32poly:u32 = 0xEDB88320; | |
// 0-255の各値について繰り返し計算を行う --- (*2) | |
for i in 0..256 { | |
let mut crc:u32 = i as u32; // 値を初期化 | |
// 8回(8ビット分)繰り返す --- (*4) | |
for _ in 0..8 { |
NewerOlder