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
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 |
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
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, |
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
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) | |
{ |
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
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); |
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
public partial class MainForm : Form | |
{ | |
private NodeCollection nodes; | |
public MainForm() | |
{ | |
InitializeComponent(); | |
// ダブルバッファリングのおまじない | |
this.SetStyle(ControlStyles.DoubleBuffer, true); |
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
using System; | |
using System.Diagnostics; | |
namespace Debuggee | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Debugger.Log(1, "category", "test debugger log\r\n"); |
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
using System; | |
using System.Diagnostics; | |
namespace Dice | |
{ | |
class Program | |
{ | |
// 20枚の100円玉を放り投げて全部が表だったら、誰だって心臓が止まるくらい驚くでしょうけど、 | |
// でも、これは確率的には約100万分の1(2の20乗は104万8676)だから、 | |
// 日本人全員が一斉に振ったら、100人くらいは全部表になりますから、別に奇跡でも何でもない。 |
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
public struct Trivalent | |
{ | |
public enum TrivalentValue { Null, True, False }; | |
public TrivalentValue Value; | |
public static bool operator true(Trivalent t) | |
{ | |
return (t.Value == TrivalentValue.True); | |
} |
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
using System; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var ex = new Exception("outer", new MyException("inner")); | |
Console.WriteLine(ex); | |
} | |
} |
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
notifyCPS: function(cont){ | |
var waiting = this.observers.length; | |
if (waiting == 0) { | |
cont(); | |
return; | |
} | |
var waitAll = function(){ | |
if (--waiting > 0) return; | |
cont(); | |
}; |