最近の収穫
Ising模型 Monte Carloシミュレーション
ランダムであるスピンを取り出してきて、そのスピンが反転したときのエネルギー変化を計算し、
の確率で転移させる。これをずっと繰り返す。
一回ずつ画面更新していたのでは遅いので、何回かの転移をさせた後に画面更新をするようにした。
壁紙
COMというのを使うと壁紙を変更することができることがわかった。
[STAThread]が意外と重要
[STAThread] static void Main(string[] args) { IActiveDesktop pActiveDesktop = new ActiveDesktop() as IActiveDesktop; if (pActiveDesktop == null) throw new NullReferenceException("ActiveDesktop COM Object Not Created."); int Capacity = 1024; StringBuilder GetWallpaperStringBuilder = new StringBuilder(Capacity); pActiveDesktop.GetWallpaper(GetWallpaperStringBuilder, Capacity, 0); WPOptions GetWallpaperOptionsStruct = WPOptions.Center; pActiveDesktop.GetWallpaperOptions(ref GetWallpaperOptionsStruct, 0); string SetWallpaperString = "D:\\My Documents\\My Pictures\\deviant\\Gift_for_dallas_dustin_by_fyredrago.jpg"; pActiveDesktop.SetWallpaper(SetWallpaperString, 0); var SetWallpaperOptionsStruct = WPOptions.Stretch; pActiveDesktop.SetWallpaperOptions(ref SetWallpaperOptionsStruct, 0); pActiveDesktop.ApplyChanges(AD_APPLY.FORCE | AD_APPLY.SAVE | AD_APPLY.REFRESH); Marshal.ReleaseComObject(pActiveDesktop); } [ComImport(), Guid("f490eb00-1240-11d1-9888-006097deacf9"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IActiveDesktop { void ApplyChanges(AD_APPLY dwFlags); void GetWallpaper(StringBuilder pwszWallpaper, int cchWallpaper, int dwReserved); void SetWallpaper(string pwszWallpaper, int dwReserved); void GetWallpaperOptions(ref WPOptions pwpo, int dwReserved); void SetWallpaperOptions(ref WPOptions pwpo, int dwReserved); } [ComImport(), Guid("75048700-EF1F-11D0-9888-006097DEACF9")] class ActiveDesktop { } [Flags] enum AD_APPLY { SAVE = 0x00000001, HTMLGEN = 0x00000002, REFRESH = 0x00000004, ALL = SAVE | HTMLGEN | REFRESH, FORCE = 0x00000008, BUFFERED_REFRESH = 0x00000010, DYNAMICREFRESH = 0x00000020 } struct WPOptions { static readonly int SizeOf = Marshal.SizeOf(typeof(WPOptions)); int dwSize; int dwStyle; public static WPOptions Center { get { return new WPOptions() { dwSize = SizeOf, dwStyle = 0 }; } } public static WPOptions Tile { get { return new WPOptions() { dwSize = SizeOf, dwStyle = 1 }; } } public static WPOptions Stretch { get { return new WPOptions() { dwSize = SizeOf, dwStyle = 2 }; } } public static WPOptions Max { get { return new WPOptions() { dwSize = SizeOf, dwStyle = 3 }; } } }