Dear Developers,
we made the running line in our app and want to share our way of solving this problem:
// Variables for moving line of today events
var initialString = "What we planned for today?.... Nothing?! Pls rest:)))";
var initialShortString = "";
var transformString = "";
var stringFromEnd = "";
function OnStart() {
// First horizontal lines for Title text
layHoriz = app.CreateLayout( "Linear", "Horizontal");
const today = new Date();
movingLineString( today.getDate() );
// Calendar title with running text line
txtTodayEvents = app.CreateText( initialString );
txtTodayEvents.SetMargins(0.01, 0.03);
txtTodayEvents.SetTextSize( 14 );
txtTodayEvents.SetTextColor( "black" );
layHoriz.AddChild(txtTodayEvents);
app.AddLayout( layHoriz );
accelerometerInitializing();
}
function accelerometerInitializing() {
// Create and start accelerometer sensor
snsAcc = app.CreateSensor( "Accelerometer", "Fast" );
snsAcc.Start();
// Get data
var vals = snsAcc.GetValues();
var series = GetSeries( sampleCount, [vals[1],vals[2],vals[3]] );
app.HideProgress();
// Start updating the graph
Update();
}
// Updating accelerometer readings
function Update() {
// Get more data
var vals = snsAcc.GetValues();
var series = GetSeries( sampleCount, [vals[1],vals[2],vals[3]] );
txtDateInfo.SetText( "Gyroscope Data:\n" +
"X: " + vals[1] + "\n" +
"Y: " + vals[2] + "\n" +
"Z: " + vals[3] + "\n");
// Reading new sensors data
let newX=Math.round(vals[1]);
let newY=Math.round(vals[2]);
let newZ=Math.round(vals[3]);
animationPlus++;
if( animationPlus % 10 == 0) {
movingLineEffect();
}
// Call this function again
setTimeout( Update, updateInterval );
}
function movingLineEffect() {
let strLength = initialShortString.length;
if(strLength!=0) {
stringFromEnd = stringFromEnd + initialShortString.slice(0, 1);
initialShortString = initialShortString.slice(1);
} else {
initialShortString = initialString;
stringFromEnd = "";
}
transformString = initialShortString+" " + stringFromEnd;
txtTodayEvents.SetText( transformString );
}
It is the simple algorithm with removing the first character of the string and immediately adding that character at the end. All of this are tied to updating the accelerometer readings, and in the future, e.g. we can link the direction of the running line depending on where our smartphone is directed.
Have a nice day. We hope this info can help to somebody in their projects.
Best regards
Dmitry
вторник, 7 апреля 2026 г. в 13:00:19 UTC+3, DogPlanner GSS: