Skip to content

Instantly share code, notes, and snippets.

function initCanvas(w, h) {
var canvas = document.getElementById("myCanvas");
canvas.width = w;
canvas.height = h;
canvas.style.width = w + "px";
canvas.style.height = h + "px";
return canvas.getContext('2d');
}
function main() {
@dev001hajipro
dev001hajipro / 1.5.1.montecalro.html
Created March 20, 2017 02:35
JavaScriptとCanvasでモンテカルロ法で円周率を求める
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>モンテカルロ法</title>
<style>
canvas {
width :200px;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CodingChallenge40_WordCounter</title>
</head>
<body>
<h1>Word Counter</h1>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>pixel sort</title>
</head>
<body>
<h1>Pixel sort</h1>
<canvas id="c" width="640" height="320"></canvas>
@dev001hajipro
dev001hajipro / Xresources
Created April 15, 2017 03:53
xtermでVLGothicフォントを大きくして、Molokaiテーマ。.Xresourcesに保存して、xrdb -merge ~/.Xresourcesで反映
! Molokai theme
*xterm*background: #101010
*xterm*foreground: #d0d0d0
*xterm*cursorColor: #d0d0d0
*xterm*color0: #101010
*xterm*color1: #960050
*xterm*color2: #66aa11
*xterm*color3: #c47f2c
*xterm*color4: #30309b
*xterm*color5: #7e40a5
@dev001hajipro
dev001hajipro / Main.cpp
Created June 18, 2017 22:29
Attractor and Repeller with OpenSiv3D library.
# include <Siv3D.hpp>
#include <iostream>
#include <string>
#include <random>
using namespace std;
inline double myrand(double min, double max)
{
@dev001hajipro
dev001hajipro / openSiv3D_vehicle
Created June 25, 2017 03:57
Vehicles implement by OpenSiv3D from The Nature of Code.
#include "stdafx.h"
inline void _limit(Vec2& v, double a)
{
double b = v.lengthSq();
if (b > a*a) {
v /= sqrt((float)b);
}
v *= a;
}
inline double heading(Vec2 v)
@dev001hajipro
dev001hajipro / Main.cpp
Last active June 28, 2017 07:42
flowfield with OpenSive3D
#include <Siv3D.hpp>
#define _USE_MATH_DEFINES
#include <math.h>
// p5.js helper functions for OpenSiv3D
namespace p5h {
template <typename T>
inline T map(T n, T start1, T stop1, T start2, T stop2) noexcept {
return ((n - start1) / (stop1 - start1)) * (stop2 - start2) + start2;
}
inline void limit(Vec2& v, double a) noexcept {
@dev001hajipro
dev001hajipro / openSiv3D_simple_polygon
Created July 23, 2017 10:52
OpenSiv3Dで簡単なポリゴンを表示。
# include <Siv3D.hpp> // OpenSiv3D v0.1.5
// Polygonクラスを使った描画例と、
// 頂点配列とPolygonクラスを組み合わせた例。
void Main()
{
Window::Resize(1280, 720);
const Font font(30);
// OpenSiv3Dにはポリゴンクラスが用意されているので多角形を作れます。
@dev001hajipro
dev001hajipro / sketch.js
Created August 1, 2017 21:09
nature of code chapter.9 exercise 9.6 implements like a functional.
/// <reference path="../../p5.global-mode.d.ts" />
// Excercise_9.6
// ok 各世代でターゲットに最も近い句を表示
// ok 世代数表示
// ok 平均適応度(fitness)
function newChar() {
let c = floor(random(64, 122)); // ascii code.
c = (c === 64) ? 32 : c; // @ mark to space.
return String.fromCharCode(c);
}