Created
June 23, 2011 20:57
-
-
Save OrigamiTech/1043610 to your computer and use it in GitHub Desktop.
Make a winforms program go trippy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* AcidTrip.cs (c) 2010 Will Kirkby. | |
* But frankly, I don't care if you share this around. | |
* It's a fun script. | |
*/ | |
using System; | |
using System.Drawing; | |
using System.Windows.Forms; | |
namespace WK | |
{ | |
class AcidTrip | |
{ | |
public bool IsActive { get { return _Timer.Enabled; } } | |
private Control _TargetControl; | |
private int _State = 0; | |
private Random _Random = new Random(); | |
private Timer _Timer = new Timer() { Interval = 10 }; | |
private const byte _MOVE = 10; | |
private Color _TargetControlBackColor; | |
private Point[] _TargetSubControlLocation; | |
private bool[] _TargetSubControlEnabled; | |
private Color[] _TripBackColors = new Color[]{ | |
Color.FromArgb(0xFF, 0x00, 0x00), | |
Color.FromArgb(0xFF, 0xFF, 0x00), | |
Color.FromArgb(0x00, 0xFF, 0x00), | |
Color.FromArgb(0x00, 0xFF, 0xFF), | |
Color.FromArgb(0x00, 0x00, 0xFF), | |
Color.FromArgb(0xFF, 0x00, 0xFF), | |
}; | |
public AcidTrip(Control targetControl) | |
{ | |
_TargetControl = targetControl; | |
_Timer.Tick += new EventHandler(AcidTick); | |
} | |
public void Start() | |
{ | |
_TargetControlBackColor = _TargetControl.BackColor; | |
_TargetSubControlLocation = new Point[_TargetControl.Controls.Count]; | |
_TargetSubControlEnabled = new bool[_TargetControl.Controls.Count]; | |
for(int i = 0; i < _TargetControl.Controls.Count; i++) | |
{ | |
_TargetSubControlLocation[i] = _TargetControl.Controls[i].Location; | |
_TargetSubControlEnabled[i] = _TargetControl.Controls[i].Enabled; | |
} | |
for(int i = 0; i < _TargetControl.Controls.Count; i++) | |
_TargetControl.Controls[i].Enabled = false; | |
_Timer.Start(); | |
} | |
public void Stop() | |
{ | |
for(int i = 0; i < _TargetControl.Controls.Count; i++) | |
{ | |
_TargetControl.Controls[i].Location = _TargetSubControlLocation[i]; | |
_TargetControl.Controls[i].Enabled = _TargetSubControlEnabled[i]; | |
} | |
_TargetControl.BackColor = _TargetControlBackColor; | |
_Timer.Stop(); | |
} | |
private void AcidTick(object sender, EventArgs e) | |
{ | |
_State++; | |
_State %= _TripBackColors.Length; | |
_TargetControl.BackColor = _TripBackColors[_State]; | |
for(int i = 0; i < _TargetControl.Controls.Count; i++) | |
_TargetControl.Controls[i].Location = new Point(_TargetControl.Controls[i].Left + (_Random.Next(0, _MOVE) * (_Random.Next(0, 2) == 0 ? -1 : 1)), _TargetControl.Controls[i].Top + (_Random.Next(0, _MOVE) * (_Random.Next(0, 2) == 0 ? -1 : 1))); | |
} | |
} | |
} | |
/* then just create an instance of this within your form, using the form (usually using the 'this' keyword) as the parameter. Use the Start/Stop methods to start and stop the trippiness. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment