Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ModdingUtils.GFX;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Testing {
- public partial class Form1 : Form {
- #region Variables
- System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer ();
- ThreadStart threadStart;
- Thread thread;
- short framesPerSecond = 0;
- bool started = false;
- bool closed = false;
- public IMG256Colours image;
- #endregion
- public Form1 () {
- InitializeComponent ();
- Color [] array = new Color [256];
- Random randomizer = new Random ();
- array [1] = Color.Black;
- for (int i = 1; i < 256; i++)
- array [i] = Color.FromArgb (randomizer.Next (255), randomizer.Next (255), randomizer.Next (255));
- Palette256Colours pal = new Palette256Colours (array);
- image = new IMG256Colours (1, 1, pal);
- }
- public void timer_Tick (object sender, EventArgs e) {
- labelFPS.Text = framesPerSecond.ToString ();
- framesPerSecond = 0;
- }
- public void MakeImage () {
- Random randomizer = new Random ();
- while (true) {
- if (closed == true)
- return;
- if (image.width != pictureBox1.Width)
- image.width = pictureBox1.Width;
- if (image.height != pictureBox1.Height)
- image.height = pictureBox1.Height;
- image.Erase ();
- thread = new Thread (threadStart);
- thread.Name = "MakeImage ()";
- int imageSize = image.width * image.height;
- for (int i = 0; i < imageSize; i++)
- image [i] = (byte) randomizer.Next (0, 256);
- pictureBox1.Image = image.ToBitmap ();
- framesPerSecond++;
- }
- }
- private void pictureBox1_Click (object sender, EventArgs e) {
- if (started == true)
- return;
- started = true;
- timer.Interval = 1000;
- timer.Start ();
- timer.Tick += timer_Tick;
- threadStart = new ThreadStart (MakeImage);
- thread = new Thread (threadStart);
- thread.Name = "MakeImage ()";
- thread.Start ();
- }
- private void Form1_FormClosed (object sender, FormClosedEventArgs e) {
- closed = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement