-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickRippler.cs
More file actions
198 lines (169 loc) · 6.52 KB
/
ClickRippler.cs
File metadata and controls
198 lines (169 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
//TODO
// Add customizable
// | Radius
// | Optional Corners
// | Color selection or random color
// | Customizable background color
namespace ClickRippler
{
class ClickRipple
{
const int GRID_SIZE = 50;
const int START_X = 10;
const int START_Y = 10;
const int BUTTON_HEIGHT = 20;
const int BUTTON_WIDTH = 20;
const int RIPPLE_DELAY = 500;
int rippleRadius;
int currentColorIndex; // Consider defaulting to some value?
Button[] grid;
Color[] colors = { Color.Red, Color.Pink, Color.Violet, Color.DarkBlue, Color.Blue, Color.LightBlue, Color.Green, Color.LightGreen, Color.Yellow, Color.Orange, Color.DarkOrange, Color.OrangeRed };
Color originColor;
Random rand;
static void Main(string[] args)
{
ClickRipple rippler = new ClickRipple();
}
public ClickRipple()
{
rand = new Random();
grid = new Button[GRID_SIZE*GRID_SIZE];
rippleRadius = 5;
setupForm();
}
void setupForm()
{
Form mainForm = new Form();
int counter = 0;
for(int i = 0; i < GRID_SIZE; i++)
{
for(int j = 0; j < GRID_SIZE; j++)
{
Button b = new Button();
b.Top = START_X + (i * BUTTON_HEIGHT);
b.Left = START_Y + (j * BUTTON_WIDTH);
b.Width = BUTTON_WIDTH;
b.Height = BUTTON_HEIGHT;
b.Click += buttonClick;
b.BackColor = Color.Black; // Consider making this customizable
grid[counter] = b;
mainForm.Controls.Add(b);
counter++;
}
}
mainForm.Size = new Size(BUTTON_WIDTH * GRID_SIZE + 40, BUTTON_HEIGHT * GRID_SIZE + 60); // 60 = An additional 20 for the menu bar, 20 + 20 = 40 for the margin
mainForm.ShowDialog();
}
async void buttonClick(object sender, EventArgs args)
{
originColor = colors[rand.Next(colors.Length)];
ripple(Array.IndexOf(grid, (Button)sender), originColor);
await Task.Delay(RIPPLE_DELAY);
}
// ring1 from origin | oIndex-GRID_SIZE, oIndex-(GRID_SIZE-1), oIndex-(GRID_SIZE+1), oIndex-1, oIndex+1, oIndex+(GRID_SIZE-1), oIndex+GRID_SIZE, oIndex+(GRID_SIZE+1)
//
// if cell != null, paint, delay, revert to default
async void ripple(int origin, Color originColor)
{
for (int i = 0; i <= rippleRadius; i++)
{
paintRing(i, origin, colorGradient());
await Task.Delay(RIPPLE_DELAY);
paintRing(i, origin, Color.Black);
}
}
void paintRing(int ringDegree, int origin, Color color)
{
// corners - TL, TR, BR, BL
// directionals - up,right,down,left
// gaps between corner and directionals
// always 4 corners, 4 directionals, 8 sections of gaps each with a length of (ringDegree - 1 gaps)
//paintCorners(ringDegree, origin, color);
paintDirectionals(ringDegree, origin, color);
paintGaps(ringDegree, origin, color);
}
void paintCorners(int ringDegree, int origin, Color color)
{
// top corners
grid[origin - (ringDegree * GRID_SIZE - ringDegree)].BackColor = color;
grid[origin - (ringDegree * GRID_SIZE + ringDegree)].BackColor = color;
//bottom corners
grid[origin + (ringDegree * GRID_SIZE - ringDegree)].BackColor = color;
grid[origin + (ringDegree * GRID_SIZE + ringDegree)].BackColor = color;
}
void paintDirectionals(int ringDegree, int origin, Color color)
{
// top
grid[origin - (ringDegree * GRID_SIZE)].BackColor = color;
// right
grid[origin - ringDegree].BackColor = color;
// bottom
grid[origin + (ringDegree * GRID_SIZE)].BackColor = color;
// left
grid[origin + ringDegree].BackColor = color;
}
void paintGaps(int ringDegree, int origin, Color color)
{
for(int i = 1; i < ringDegree; i++)
{
// TR gap
grid[origin - (ringDegree * GRID_SIZE + i)].BackColor = color;
// TL gap
grid[origin - (ringDegree * GRID_SIZE - i)].BackColor = color;
// RT gap
grid[origin - (i * GRID_SIZE - ringDegree)].BackColor = color;
// RB gap
grid[origin + (i * GRID_SIZE + ringDegree)].BackColor = color;
// BR gap
grid[origin + (ringDegree * GRID_SIZE + i)].BackColor = color;
// BL gap
grid[origin + (ringDegree * GRID_SIZE - i)].BackColor = color;
// LB gap
grid[origin - (i * GRID_SIZE + ringDegree)].BackColor = color;
// LT gap
grid[origin + (i * GRID_SIZE - ringDegree)].BackColor = color;
}
}
Color colorGradient()
{
int direction = rand.Next(1);
if(direction == 1)
{
// cycle to 'left' of array
if(currentColorIndex - 1 < 0)
{
currentColorIndex = colors.Length - 1;
} else
{
currentColorIndex -= 1;
}
originColor = colors[currentColorIndex];
return originColor;
} else
{
// cycle to 'right' of array
if (currentColorIndex + 1 >= colors.Length)
{
currentColorIndex = 0;
}
else
{
currentColorIndex += 1;
}
originColor = colors[currentColorIndex];
return originColor;
}
// pick random from array, choose direction (L or R), iterate through
// cycle to next color in order, if last color go forwards or backwards
// SHOULD NEVER RETURN HERE!
return originColor;
}
}
}