|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Illusion of moving LEDsI've put 8 round shapes on a form and I'm trying to use the Timer to
make them flash on and off in sequence by changing the fillcolor from green to red,to give the illusion of movement.I can easily do one, but can't for the life of me figure out how to do a sequence.any pointers? The Timer interval is set by user input, to adjust the "speed". thanks SteveC > I've put 8 round shapes on a form and I'm trying to use the Timer to Stick away from shapes they're too inefficient and will flicker like crazy when lots are on the same parent control.> make them flash on and off in sequence by changing the fillcolor from > green to red,to give the illusion of movement.I can easily do one, but > can't for the life of me figure out how to do a sequence.any pointers? > The Timer interval is set by user input, to adjust the "speed". thanks See if this does what you're after: http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/4fcd37a4e394bed3 Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ Mike D Sutton wrote:
>> I've put 8 round shapes on a form and I'm trying to use the Timer to http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/>> make them flash on and off in sequence by changing the fillcolor from >> green to red,to give the illusion of movement.I can easily do one, >> but can't for the life of me figure out how to do a sequence.any >> pointers? The Timer interval is set by user input, to adjust the >> "speed". thanks > > Stick away from shapes they're too inefficient and will flicker like > crazy when lots are on the same parent control. See if this does what > you're after: > 4fcd37a4e394bed3 > Hope this helps, Have to say that that was really, really cute. :-)-- Regards, Michael Cole > Have to say that that was really, really cute. :-) *g*As a quick and cheesy way of getting rid of the flicker, replace the Paint() routine with this: '*** Private Sub Picture1_Paint() ' Draw LEDs on paint Picture1.AutoRedraw = True Call DrawLEDs(Picture1, 200, 200, 50, 50, 200, MyLEDs()) Call Picture1.Refresh Picture1.AutoRedraw = False End Sub '*** Now increase the grid size and timer frequency - Even cooler! Of course if you were doing this properly then the LED's should be pre-rendered and simply blit rather than re-calculated each frame but ah well, it's a demo :) Cheers, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ "Mike D Sutton" <ED***@mvps.org> wrote There is such a demo, in that same thread....> Of course if you were doing this properly then the LED's should > be pre-rendered and simply blit rather than re-calculated each frame > but ah well, it's a demo :) http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/853cb2c6db9d178a <g> LFS on this matter, you and mike are both disgustingly awesome.
Show quoteHide quote "Larry Serflaten" <serfla***@usinternet.com> wrote in message news:eevPs$RYFHA.3572@TK2MSFTNGP12.phx.gbl... > > "Mike D Sutton" <ED***@mvps.org> wrote > >> Of course if you were doing this properly then the LED's should >> be pre-rendered and simply blit rather than re-calculated each frame >> but ah well, it's a demo :) > > There is such a demo, in that same thread.... > > http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/853cb2c6db9d178a > > <g> > LFS I am assuming you are using GDI to draw the "round shapes"... if this is the
case the only way I have found to achieve such an affect is to redraw each shape every time a colour change is made... Step 1 For instance led1 starts drawn red led2 through n are drawn green... Step 2 Clear the picture box, form, etc... Redraw them with changes led1 = green led2 = red led3 through n = green etc... Hope that helps... Show quoteHide quote "SteveC" wrote: > I've put 8 round shapes on a form and I'm trying to use the Timer to > make them flash on and off in sequence by changing the fillcolor from > green to red,to give the illusion of movement.I can easily do one, but > can't for the life of me figure out how to do a sequence.any pointers? > The Timer interval is set by user input, to adjust the "speed". thanks > SteveC > > It was my perception that he was using the Shape control
and just trying to set the back color to simulate the movement, hence Mike's suggestion of using another strategy to accomplish this. Saga Show quoteHide quote "Jason McKee" <JasonMc***@discussions.microsoft.com> wrote in message news:848EF87C-C6C2-441F-9D6E-C1F66B4B880E@microsoft.com... >I am assuming you are using GDI to draw the "round shapes"... if this >is the > case the only way I have found to achieve such an affect is to redraw > each > shape every time a colour change is made... > > Step 1 > For instance led1 starts drawn red > led2 through n are drawn green... > > Step 2 > Clear the picture box, form, etc... > Redraw them with changes > led1 = green > led2 = red > led3 through n = green > etc... > > Hope that helps... > > "SteveC" wrote: > >> I've put 8 round shapes on a form and I'm trying to use the Timer to >> make them flash on and off in sequence by changing the fillcolor from >> green to red,to give the illusion of movement.I can easily do one, >> but >> can't for the life of me figure out how to do a sequence.any >> pointers? >> The Timer interval is set by user input, to adjust the "speed". >> thanks >> SteveC >> >> Try this out...
I paced a control array of shapes, back color vbGreen, Opaque style, one text box, one command button and one timer and added this code: Option Explicit Private Sub Command1_Click() 'Timer interval in seconds. Timer1.Interval = Val(Text1.Text) * 1000 'Toggle timer to start/stop the "flashing" Timer1.Enabled = Not Timer1.Enabled End Sub Private Sub Timer1_Timer() Static intLEDIdx As Integer 'Set green present LED Shape1(intLEDIdx).BackColor = vbGreen 'Next LED intLEDIdx = IIf(intLEDIdx + 1 > 7, 0, intLEDIdx + 1) 'Set to red. Shape1(intLEDIdx).BackColor = vbRed End Sub I hope it helps <g> Good luck! Saga Show quoteHide quote "SteveC" <adm***@yahoo.com> wrote in message news:1116959403.799513.8230@g43g2000cwa.googlegroups.com... > I've put 8 round shapes on a form and I'm trying to use the Timer to > make them flash on and off in sequence by changing the fillcolor from > green to red,to give the illusion of movement.I can easily do one, but > can't for the life of me figure out how to do a sequence.any pointers? > The Timer interval is set by user input, to adjust the "speed". thanks > SteveC > > 'Next LED You can dump the inefficient IIf function call and use this instead> intLEDIdx = IIf(intLEDIdx + 1 > 7, 0, intLEDIdx + 1) intLEDIdx = (9 + intLEDIdx) mod 8 Rick - MVP Cool!
Saga Show quoteHide quote "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message news:uxKotVJYFHA.3220@TK2MSFTNGP14.phx.gbl... >> 'Next LED >> intLEDIdx = IIf(intLEDIdx + 1 > 7, 0, intLEDIdx + 1) > > You can dump the inefficient IIf function call and use this instead > > intLEDIdx = (9 + intLEDIdx) mod 8 > > Rick - MVP "SteveC" <adm***@yahoo.com> wrote in message If it's a linear sequence you're after, you might be better off using anews:1116959403.799513.8230@g43g2000cwa.googlegroups.com... > I've put 8 round shapes on a form and I'm trying to use the Timer to > make them flash on and off in sequence by changing the fillcolor from > green to red,to give the illusion of movement. [single] PictureBox and load a series of images into it (held in, say, an ImageList) to give the illusion of movement. If you're after something more complicated like, say, a binary counter, you'll need to stick with the individual controls and have the Timer do some bit-twiddling to work out which ones should be on or off with each iteration. HTH, Phill W. |
|||||||||||||||||||||||