Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Matrix4
- {
- public partial class Form2 : Form
- {
- Timer _spawnTimer = new Timer();
- Timer _checkTimers = new Timer();
- List<Spawn> _spawnList = new List<Spawn>();
- List<Timer> _timerList = new List<Timer>();
- private Graphics _myGrpahics;
- public Form2()
- {
- InitializeComponent();
- _spawnTimer.Interval = 500;
- _spawnTimer.Tick += _spawnTimer_Tick;
- _checkTimers.Interval = 100;
- _checkTimers.Tick += _checkTimers_Tick;
- this.Paint += Form2_Paint;
- }
- private void _checkTimers_Tick(object sender, EventArgs e)
- {
- if (!_spawnTimer.Enabled)
- {
- int _result = 0;
- foreach (Timer timer in _timerList)
- {
- if (timer.Enabled)
- {
- _result += 1;
- }
- }
- if (_result > 0)
- {
- Console.WriteLine(_result + " Timers left for " + _spawnList.Count + " Spawns");
- }
- }
- }
- private void _spawnTimer_Tick(object sender, EventArgs e)
- {
- for (int i = 0; i < 3; i+=1)
- {
- Spawn _spawn = new Spawn(this);
- _spawn._onSpawn = true;
- _spawn._spawned = true;
- _spawn._waitTo = false;
- _spawn._onDespawn = false;
- Random _theRandom = new Random();
- int _Size = _theRandom.Next(10, 30);
- _spawn._width = _Size;
- _spawn._height = _Size;
- _spawn._waitValue = 50;
- int _speedIntervalSetting = (_Size * 20) / 3;
- if (_speedIntervalSetting < 1)
- {
- _speedIntervalSetting = 1;
- }
- _spawn._speedInterval = _speedIntervalSetting;
- _spawn._x = _theRandom.Next(this.Width);
- _spawn._y = _theRandom.Next(-(this.Height / 2), this.Height / 2);
- _spawn._colorValue = _theRandom.Next(90, 200);
- _spawn._currColorValue = 10;
- _spawn._colorStepValue = 35;
- _spawn._startSpawn();
- _spawnList.Add(_spawn);
- //Console.WriteLine("there is " + _spawnList.Count + " Spawn for now");
- }
- }
- private void Form2_Paint(object sender, PaintEventArgs e)
- {
- _myGrpahics = Graphics.FromHwnd(this.Handle);
- _checkTimers.Start();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- }
- private void label1_Click(object sender, EventArgs e)
- {
- if (_spawnTimer.Enabled)
- {
- _spawnTimer.Stop();
- label1.Text = "Start";
- Timer _waitT = new Timer();
- _waitT.Interval = 2000;
- _waitT.Tick += delegate(object o, EventArgs args)
- {
- try
- {
- foreach (var timer in _timerList)
- {
- timer.Stop();
- }
- }
- catch (Exception)
- {
- }
- Console.WriteLine("All timers cleared");
- this.Invalidate();
- _waitT.Stop();
- };
- _waitT.Start();
- }
- else
- {
- _spawnTimer.Start();
- label1.Text = "Stop";
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- try
- {
- _spawnTimer.Interval = Int32.Parse(textBox1.Text);
- textBox1.BackColor = Color.White;
- }
- catch (Exception)
- {
- textBox1.BackColor = Color.Pink;
- }
- }
- public void addTimerToList(Timer _timer)
- {
- _timerList.Add(_timer);
- }
- }
- public class Spawn
- {
- Timer mainTimer = new Timer();
- Graphics _myGraphics;
- private List<char> _charList = new List<char>();
- public bool _onSpawn = false;
- public bool _spawned = false;
- public bool _waitTo = false;
- public bool _onDespawn = false;
- private bool _isDespawing = false;
- private bool _deSpawnFinished = false;
- public int _width;
- public int _height;
- public int _x;
- public int _startY;
- private int _endY;
- public int _y;
- public int _colorValue;
- public int _currColorValue;
- public int _waitValue;
- private int _currWaitValue;
- public int _colorStepValue;
- public int _speedInterval = 1;
- private int _maxColorValue = 0;
- private int _previousColorValue = 0;
- private char _theChooserChar;
- private int _maxHeightValue;
- private int _currRepeatCount = 0;
- private int _currLocation;// = _startY - 10;
- private int _curr2 = 0;
- Form2 _currForm;
- public Spawn(Form2 form1)
- {
- _currForm = form1;
- _currForm.addTimerToList(mainTimer);
- _maxHeightValue = _currForm.Height;// + _height*2;//_currForm.Height/2;
- _myGraphics = Graphics.FromHwnd(_currForm.Handle);
- _charList = getCharList();
- mainTimer.Interval = _speedInterval;
- mainTimer.Tick += MainTimer_Tick;
- }
- private List<char> getCharList()
- {
- var _result = new List<char>();
- foreach (char c in Properties.Resources.charList.ToCharArray())
- {
- _result.Add(c);
- }
- return _result;
- }
- private int getIndex()
- {
- int _result = 0;
- Random _getIndexRandom = new Random();
- _result = _getIndexRandom.Next(_charList.Count - 1);
- if (_result < 0)
- {
- _result = 0;
- }
- return _result;
- }
- private void MainTimer_Tick(object sender, EventArgs e)
- {
- if (_previousColorValue < _currColorValue)
- {
- _maxColorValue = _currColorValue;
- }
- _previousColorValue = _currColorValue;
- if (_deSpawnFinished)
- {
- mainTimer.Stop();
- }
- if (_isDespawing)
- {
- int _pathToTrace = _endY - _startY;
- int _repeatCount = 2;
- if (_currRepeatCount < _repeatCount)
- {
- if (_currLocation < _endY)
- {
- for (int i = 1; i < _repeatCount; i+=1)
- {
- _currLocation += (_height / 4) * 3;
- Rectangle _main = new Rectangle(_x, _y, _width, _height);
- Rectangle _shadow = new Rectangle(_x, _currLocation, _width + (_width+0), _height+0);
- Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular,
- System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- Color _selectedColor = new Color();
- int _currCharIndex = getIndex();
- if (_currColorValue - ((_currForm.Height / _height) * _height) > 0)
- {
- _currColorValue = _currColorValue - (((_currForm.Height / _height) * _height) / 2);
- }
- else
- {
- _currColorValue = 0;
- }
- _selectedColor = Color.FromArgb(150, 0, _currColorValue, 0);
- //_myGraphics.FillRectangle(Brushes.Black, _main);
- _myGraphics.FillRectangle(new SolidBrush(Color.FromArgb(new Random().Next(100, 200), 0, 0, 0)), _shadow);
- //_myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.White), _main);
- //_myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont,new SolidBrush(_selectedColor), _shadow);
- }
- _curr2 += 1;
- }
- else
- {
- _currLocation = _startY-100;
- _currRepeatCount += 1;
- _curr2 = 0;
- }
- }
- else
- {
- _deSpawnFinished = true;
- }
- }
- else
- {
- if (_y < _maxHeightValue)//+ _height*2)
- {
- _y += (_height/4)*3;
- Rectangle _main = new Rectangle(_x, _y, _width, _height);
- Rectangle _shadow = new Rectangle(_x, _y - _height, _width, _height);
- Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- Color _selectedColor = new Color();
- int _currCharIndex = getIndex();
- if (_currColorValue - 10 > 0 && _currColorValue + 10 < 255)
- {
- _selectedColor = Color.FromArgb(0,
- new Random().Next(_currColorValue - 10, _currColorValue + 10), 0);
- }
- else
- {
- if (_currColorValue > 100)
- {
- _currColorValue = 255;
- }
- else
- {
- _currColorValue = 0;
- }
- }
- _myGraphics.FillRectangle(Brushes.Black, _main);
- _myGraphics.FillRectangle(Brushes.Black, _shadow);
- _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.White), _main);
- _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(_selectedColor), _shadow);
- }
- else
- {
- }
- if (_onSpawn)
- {
- if (_currColorValue < _colorValue)
- {
- _currColorValue += _colorStepValue;
- Rectangle _main = new Rectangle(_x, _y, _width, _height);
- Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- _myGraphics.FillRectangle(Brushes.Black, _main);
- _myGraphics.DrawString(_theChooserChar.ToString(), _mainFont, new SolidBrush(Color.FromArgb(0, _currColorValue, 0)), _main);
- }
- else
- {
- _onSpawn = false;
- //_spawned = true;
- _waitTo = true;
- _currWaitValue = 0;
- }
- }
- else
- {
- if (_spawned)
- {
- if (_waitTo)
- {
- if (_currWaitValue < _waitValue)
- {
- //Console.WriteLine("Started wait to = " + _currWaitValue + " / " + _waitValue);
- _currWaitValue += 1;
- }
- else
- {
- //Console.WriteLine("Finished wait to");
- _waitTo = false;
- _endY = _y;
- _currLocation = _startY - 100;
- _isDespawing = true;
- mainTimer.Interval = 1;
- //_onDespawn = true;
- }
- }
- else
- {
- if (_onDespawn)
- {
- if (!(_currColorValue - _colorStepValue < 0))
- {
- _currColorValue -= _colorStepValue;
- /*int _xVar = _currForm.Height / _height;
- int _xFunc = _xVar * _height;
- for (int i = 1; i < _xFunc + 1; i += 1)
- {
- //System.Threading.Thread.Sleep(1);
- Rectangle _despawnShadow = new Rectangle(_x, _y + 100 - _height * i, _width, _height);
- Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- int _colorDespawnValue = (_maxColorValue / i);
- int _currCharIndex = getIndex();
- if (!((_currColorValue - _colorDespawnValue) > 0))
- {
- _currColorValue = 0;
- }
- _myGraphics.FillRectangle(Brushes.Black, _despawnShadow);
- _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.FromArgb(0, _currColorValue, 0)), _despawnShadow);
- }*/
- }
- else
- {
- _currColorValue = 0;
- _onSpawn = false;
- _spawned = false;
- _waitTo = false;
- _onDespawn = false;
- }
- }
- else
- {
- mainTimer.Stop();
- }
- }
- }
- else
- {
- }
- }
- }
- }
- public void _startSpawn()
- {
- _startY = _y;
- mainTimer.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement