Advertisement
Chronos_Ouroboros

Styff 2

Jun 7th, 2015
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using ModdingUtils.GFX;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace Testing {
  14. public partial class Form1 : Form {
  15. #region Variables
  16. System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer ();
  17.  
  18. ThreadStart threadStart;
  19. Thread thread;
  20.  
  21. short framesPerSecond = 0;
  22.  
  23. bool started = false;
  24. bool closed = false;
  25.  
  26. public IMG256Colours image;
  27.  
  28. #endregion
  29.  
  30. public Form1 () {
  31. InitializeComponent ();
  32.  
  33. Color [] array = new Color [256];
  34. Random randomizer = new Random ();
  35.  
  36. array [1] = Color.Black;
  37.  
  38. for (int i = 1; i < 256; i++)
  39. array [i] = Color.FromArgb (randomizer.Next (255), randomizer.Next (255), randomizer.Next (255));
  40.  
  41. Palette256Colours pal = new Palette256Colours (array);
  42. image = new IMG256Colours (1, 1, pal);
  43. }
  44.  
  45. public void timer_Tick (object sender, EventArgs e) {
  46. labelFPS.Text = framesPerSecond.ToString ();
  47. framesPerSecond = 0;
  48. }
  49.  
  50. public void MakeImage () {
  51. Random randomizer = new Random ();
  52.  
  53. while (true) {
  54. if (closed == true)
  55. return;
  56.  
  57. if (image.width != pictureBox1.Width)
  58. image.width = pictureBox1.Width;
  59. if (image.height != pictureBox1.Height)
  60. image.height = pictureBox1.Height;
  61.  
  62. image.Erase ();
  63.  
  64. thread = new Thread (threadStart);
  65. thread.Name = "MakeImage ()";
  66.  
  67. int imageSize = image.width * image.height;
  68.  
  69. for (int i = 0; i < imageSize; i++)
  70. image [i] = (byte) randomizer.Next (0, 256);
  71.  
  72. pictureBox1.Image = image.ToBitmap ();
  73.  
  74. framesPerSecond++;
  75. }
  76. }
  77.  
  78. private void pictureBox1_Click (object sender, EventArgs e) {
  79. if (started == true)
  80. return;
  81.  
  82. started = true;
  83. timer.Interval = 1000;
  84. timer.Start ();
  85. timer.Tick += timer_Tick;
  86.  
  87. threadStart = new ThreadStart (MakeImage);
  88. thread = new Thread (threadStart);
  89. thread.Name = "MakeImage ()";
  90. thread.Start ();
  91. }
  92.  
  93. private void Form1_FormClosed (object sender, FormClosedEventArgs e) {
  94. closed = true;
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement