public static Bitmap mkDef() { Bitmap def = new Bitmap(w, h); BitmapPlus bp = new BitmapPlus(def); bp.BeginAcces(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { bp.SetPixel(x, y, BackGround); } } for (int x = 0; x < w; x++) { bp.SetPixel(x, 100, Axiss); } for (int y = 75; y < 125; y++) { bp.SetPixel(100, y, Axiss); bp.SetPixel(200, y, Axiss); bp.SetPixel(300, y, Axiss); } bp.EndAccess(); return(def); }
static void mkPix() { pixelData = new byte[pict.Width, pict.Height, 3]; BitmapPlus bp = new BitmapPlus(pict); bp.BeginAccess(); for (int y = 0; y < pict.Height; y++) { for (int x = 0; x < pict.Width; x++) { Color cc = bp.GetPixel(x, y); pixelData[x, y, 0] = cc.R; pixelData[x, y, 1] = cc.G; pixelData[x, y, 2] = cc.B; } } bp.EndAccess(); }
public static Bitmap testSine() { int vmax = 99; Bitmap res = mkDef(); BitmapPlus bp = new BitmapPlus(res); bp.BeginAcces(); for (int x = 0; x < w; x++) { int val = (int)( (50.0 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) + (50.0 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) + (50.0 * Math.Sin(4.0 * Math.PI * (double)x / (double)w)) ); if (-vmax < val && val < vmax) { bp.SetPixel(x, val + 102, SubColor); bp.SetPixel(x, val + 101, SubColor); bp.SetPixel(x, val + 99, SubColor); bp.SetPixel(x, val + 98, SubColor); bp.SetPixel(x, val + 100, MainColor); } else if (val < -vmax) { val = -vmax; bp.SetPixel(x, val + 101, SubColor); bp.SetPixel(x, val + 100, MainColor); } else { val = vmax; bp.SetPixel(x, val + 99, SubColor); bp.SetPixel(x, val + 100, MainColor); } } bp.EndAccess(); return(res); }
public static Bitmap mkWave( float sin1, float sin2, float sin3, float sin4, float cos1, float cos2, float cos3, float cos4) { int vmax = Int16.MaxValue; Bitmap res = mkDef(); BitmapPlus bp = new BitmapPlus(res); bp.BeginAcces(); for (int x = 0; x < w; x++) { int val = (int)( (vmax * sin1 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) + (vmax * sin2 * Math.Sin(4.0 * Math.PI * (double)x / (double)w)) + (vmax * sin3 * Math.Sin(6.0 * Math.PI * (double)x / (double)w)) + (vmax * sin4 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) + (vmax * cos1 * Math.Cos(2.0 * Math.PI * (double)x / (double)w)) + (vmax * cos2 * Math.Cos(4.0 * Math.PI * (double)x / (double)w)) + (vmax * cos3 * Math.Cos(6.0 * Math.PI * (double)x / (double)w)) + (vmax * cos4 * Math.Cos(8.0 * Math.PI * (double)x / (double)w)) ); if (val < Int16.MinValue) { val = Int16.MinValue; } else if (Int16.MaxValue < val) { val = vmax; } int plotval = (-val * 99 / Int16.MaxValue) + 100; bp.SetPixel(x, plotval, MainColor); } bp.EndAccess(); return(res); }
public static Bitmap mkWave(SoundData sd) { int vmax = Int16.MaxValue; Bitmap res = mkDef(); BitmapPlus bp = new BitmapPlus(res); bp.BeginAcces(); for (int x = 0; x < w; x++) { int val = (int)( (vmax * sd.sin1 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.sin2 * Math.Sin(4.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.sin3 * Math.Sin(6.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.sin4 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.sin8 * Math.Sin(16.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.cos1 * Math.Cos(2.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.cos2 * Math.Cos(4.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.cos3 * Math.Cos(6.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.cos4 * Math.Cos(8.0 * Math.PI * (double)x / (double)w)) + (vmax * sd.cos8 * Math.Cos(16.0 * Math.PI * (double)x / (double)w)) ); #region ks1 if (x < 0.5 * w) { val += (int)(vmax * sd.ksin1); } else { val -= (int)(vmax * sd.ksin1); } #endregion #region ks2 if (x < 0.25 * w) { val += (int)(vmax * sd.ksin2); } else if (x < 0.5 * w) { val -= (int)(vmax * sd.ksin2); } else if (x < 0.75 * w) { val += (int)(vmax * sd.ksin2); } else { val -= (int)(vmax * sd.ksin2); } #endregion #region ks3 if (x < w / 6) { val += (int)(vmax * sd.ksin3); } else if (x < w / 3) { val -= (int)(vmax * sd.ksin3); } else if (x < w / 2) { val += (int)(vmax * sd.ksin3); } else if (x < 2 * w / 3) { val -= (int)(vmax * sd.ksin3); } else if (x < 5 * w / 6) { val += (int)(vmax * sd.ksin3); } else { val -= (int)(vmax * sd.ksin3); } #endregion #region ks4 if (x < w * 0.125) { val += (int)(vmax * sd.ksin4); } else if (x < w * 0.25) { val -= (int)(vmax * sd.ksin4); } else if (x < w * 0.375) { val += (int)(vmax * sd.ksin4); } else if (x < w * 0.5) { val -= (int)(vmax * sd.ksin4); } else if (x < w * 0.625) { val += (int)(vmax * sd.ksin4); } else if (x < w * 0.75) { val -= (int)(vmax * sd.ksin4); } else if (x < w * 0.875) { val += (int)(vmax * sd.ksin4); } else { val -= (int)(vmax * sd.ksin4); } #endregion if (val < Int16.MinValue) { val = Int16.MinValue; } else if (Int16.MaxValue < val) { val = vmax; } int plotval = (-val * 99 / Int16.MaxValue) + 100; bp.SetPixel(x, plotval, MainColor); } bp.EndAccess(); return(res); }
private async void processing() { CancellationTokenSource cancelsource = new CancellationTokenSource(); Point mine2000_pos = new Point(); Rectangle mine2000_rect = new Rectangle(); Point mine2000_offset = new Point(2, 34); mine2000_find(ref mine2000_pos, ref mine2000_rect); int counter_of_image = 0; var progress1 = new Progress <int>((hoge) => { if (is_running) { Bitmap img_bit = copy_from_screen(new Point(mine2000_pos.X + mine2000_offset.X, mine2000_pos.Y + mine2000_offset.Y), cell_width * map_width, cell_height * map_height); img_bit.Save(counter_of_image.ToString() + ".jpg"); counter_of_image++; BitmapPlus img_bit_p = new BitmapPlus(img_bit); img_bit_p.BeginAccess(); for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { map_field[x, y] = RGBsum_to_number(img_bit_p, x, y, cell_width, cell_height); } } img_bit_p.EndAccess(); img_bit.Dispose(); // 操作をしたか bool is_exist = false; // 旗を立てる for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map_field[x, y] > 0) { int count = 0; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height) { if (map_field[x + dx, y + dy] < 0) { count++; } } } } if (count == map_field[x, y]) { for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height) { if (map_field[x + dx, y + dy] < 0) { map_bomb[x + dx, y + dy] = true; } } } } } /* * else if (count < map_field[x, y]) // 操作ミス用(?) * { * for (int dx = -1; dx <= 1; dx++) * { * for (int dy = -1; dy <= 1; dy++) * { * if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height) * { * if (map_field[x + dx, y + dy] < 0) * { * map_bomb[x + dx, y + dy] = false; * } * } * } * } * } */ } } } if (MouseButtons == MouseButtons.None) { Point mouse_pos = Cursor.Position; for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map_bomb[x, y] && map_field[x, y] != -10 && !map_flag[x, y]) { Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y); mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); map_flag[x, y] = true; is_exist = true; } } } Cursor.Position = mouse_pos; } // マスを拓く if (MouseButtons == MouseButtons.None) { Point mouse_pos = Cursor.Position; for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map_field[x, y] > 0) { int count = 0; bool valid = false; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height) { if (map_field[x + dx, y + dy] == -10) { count++; } else if (map_field[x + dx, y + dy] == -1) { valid = true; } } } } if (count == map_field[x, y] && valid) { Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y); mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); is_exist = true; } } } } Cursor.Position = mouse_pos; } if (!is_exist) { label1.Text = "Nothing"; Point mouse_pos = Cursor.Position; for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map_field[x, y] == -1) { Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y); mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); is_exist = true; break; } } if (is_exist) { break; } } is_exist = false; Cursor.Position = mouse_pos; } } if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = copy_from_screen(new Point(mine2000_pos.X + mine2000_offset.X, mine2000_pos.Y + mine2000_offset.Y), cell_width * map_width, cell_height * map_height); if (!is_running) { label1.Text = "stop"; } if (restart_) { Initializing(); restart_ = false; } }); bool ret = await Span1(progress1, cancelsource.Token, process_span); }