Skip to content

Instantly share code, notes, and snippets.

public class Node
{
public Vector GetFrictionalForce()
{
// 摩擦力は速度に比例 (比例定数 -m)
const double m = 0.3d;
return new Vector()
{
X = -m * this.V.X,
Y = -m * this.V.Y
public struct Vector
{
public double X;
public double Y;
public static Vector operator +(Vector v1, Vector v2)
{
return new Vector()
{
X = v1.X + v2.X,
public class NodeCollection : Dictionary<string, Node>
{
public void MoveAll()
{
const double dt = 0.1d;
foreach (Node n in this.Values)
{
Vector f = new Vector();
foreach (Node nn in n.Neighbors)
{
private void MainForm_Paint(object sender, PaintEventArgs e)
{
const int r = 15;
e.Graphics.Clear(SystemColors.Control);
foreach (Node n in this.nodes.Values)
{
// ノードは、n.R を中心とする半径 r の円で表す
e.Graphics.FillEllipse(Brushes.Green,
ToScreenX(n.R.X) - r, ToScreenY(n.R.Y) - r,
2 * r, 2 * r);
public partial class MainForm : Form
{
private NodeCollection nodes;
public MainForm()
{
InitializeComponent();
// ダブルバッファリングのおまじない
this.SetStyle(ControlStyles.DoubleBuffer, true);
using System;
using System.Diagnostics;
namespace Debuggee
{
class Program
{
static void Main(string[] args)
{
Debugger.Log(1, "category", "test debugger log\r\n");
using System;
using System.Diagnostics;
namespace Dice
{
class Program
{
// 20枚の100円玉を放り投げて全部が表だったら、誰だって心臓が止まるくらい驚くでしょうけど、
// でも、これは確率的には約100万分の1(2の20乗は104万8676)だから、
// 日本人全員が一斉に振ったら、100人くらいは全部表になりますから、別に奇跡でも何でもない。
public struct Trivalent
{
public enum TrivalentValue { Null, True, False };
public TrivalentValue Value;
public static bool operator true(Trivalent t)
{
return (t.Value == TrivalentValue.True);
}
using System;
class Program
{
static void Main(string[] args)
{
var ex = new Exception("outer", new MyException("inner"));
Console.WriteLine(ex);
}
}
@matarillo
matarillo / lameCPS_model1.js
Created November 5, 2010 11:33
model: CPS observer pattern
notifyCPS: function(cont){
var waiting = this.observers.length;
if (waiting == 0) {
cont();
return;
}
var waitAll = function(){
if (--waiting > 0) return;
cont();
};