c# - Select cells (buttons) on diagonals of a square matrix -


i'm writing wpf music pad application, have 16 button (here example of real music pad https://www.youtube.com/watch?v=3vc5tssynju).

each button plays different music sample. works well. when user in idle, want create simple animation shown in image below.

enter image description here

animation starts button 1 (animates it's background color white, goes original color).

here steps of animation:

  • step 1: animate buttons: 1
  • step 2: animate buttons: 2, q
  • step 3: animate buttons: 3, w,
  • step 4: animate buttons: 4, e, s, z
  • step 5: animate buttons: r, d, x
  • step 6: animate buttons: f, c
  • step 7: animate buttons: v

i created function animatepad takes button , starts background color animation after specified time. function works expected.

to implement steps described above, i'm calling animatepad function each button. here code i'm using , want improve. have hard coded steps. if buttons count changes, must go , change code, bad idea.

        double beginms = 0;         var spd = 300;         var interval = 40;         var tocolor = color.fromrgb(255, 255, 255);         animatepad(ref beginms, spd, pads[0], tocolor);          beginms += interval;         animatepad(ref beginms, spd, pads[1], tocolor);         animatepad(ref beginms, spd, pads[4], tocolor);          beginms += interval;                         animatepad(ref beginms, spd, pads[2], tocolor);         animatepad(ref beginms, spd, pads[5], tocolor);         animatepad(ref beginms, spd, pads[8], tocolor);          beginms += interval;                         animatepad(ref beginms, spd, pads[3], tocolor);         animatepad(ref beginms, spd, pads[6], tocolor);         animatepad(ref beginms, spd, pads[9], tocolor);         animatepad(ref beginms, spd, pads[12], tocolor);          beginms += interval;                          animatepad(ref beginms, spd, pads[7], tocolor);         animatepad(ref beginms, spd, pads[10], tocolor);         animatepad(ref beginms, spd, pads[13], tocolor);          beginms += interval;                          animatepad(ref beginms, spd, pads[11], tocolor);         animatepad(ref beginms, spd, pads[14], tocolor);          beginms += interval;                         animatepad(ref beginms, spd, pads[15], tocolor); 

so want more generic way choose buttons animation.

i'm sure there must algorithm. thank you!

try this:

var n = (int) math.sqrt(pads.length); int = 0, j = 0, k = 0; for(i = 0; < n; i++){    k = i;    animatepad(ref beginms, spd, pads[k], tocolor);    for(j = 0; j < i; j++){       k += n-1;                 animatepad(ref beginms, spd, pads[k], tocolor);    }    beginms += interval; } for(i = n-2; >= 0; i--){           k = (n-i)*n - 1;    animatepad(ref beginms, spd, pads[k], tocolor);    for(j = 0; j < i; j++){       k += n-1;       animatepad(ref beginms, spd, pads[k], tocolor);    }    beginms += interval; } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -