Hi all,
I am trying to cover the screen with horizontal lines, where each line is a random color selected from an array. I have everything working well, except that instead of each line having a static random color, they are all one color that cycles through I guess random numbers that are continually picked. Is there a way to "lock" in a number each time I cycle through my loop?
code:
using Toybox.WatchUi; using Toybox.Graphics; using Toybox.System; using Toybox.Lang; using Toybox.Math; class test3View extends WatchUi.WatchFace { function initialize() { WatchFace.initialize(); } // Load your resources here function onLayout(dc) { setLayout(Rez.Layouts.WatchFace(dc)); } // Called when this View is brought to the foreground. Restore // the state of this View and prepare it to be shown. This includes // loading resources into memory. function onShow() { } // Update the view function onUpdate(dc) { var randomNumber = Math.floor(Math.rand() % 6 + 0); var lineColors = [Graphics.COLOR_RED, Graphics.COLOR_ORANGE, Graphics.COLOR_YELLOW, Graphics.COLOR_GREEN, Graphics.COLOR_BLUE, Graphics.COLOR_PINK]; var randomColor = lineColors[randomNumber]; var yPos = 0; View.onUpdate(dc); dc.setPenWidth(1); dc.setColor(randomColor, Graphics.COLOR_WHITE); for (var i = 0; i < 120; i++) { dc.drawLine(0, yPos, 240, yPos); yPos = yPos + 5; } } // Called when this View is removed from the screen. Save the // state of this View here. This includes freeing resources from // memory. function onHide() { } // The user has just looked at their watch. Timers and animations may be started here. function onExitSleep() { } // Terminate any active timers and prepare for slow updates. function onEnterSleep() { } }
Thanks for any help!