Manuel Wong

unread,
Jan 23, 2017, 12:09:24 PM1/23/17
to mitappinv...@googlegroups.com
Hi Everyone,

I just started playing with AI2 and am running into a wall with the speed of drawing onto the canvas.  If I want to draw over 3000 line segments incrementally, what's the trick to have a smooth, quick experience?  Akin to watching someone draw.

Any advice greatly appreciated,

Manny

PS.  I am on Windows 10 if that makes a difference (I think not).  It wasn't one of the options.

Italo

unread,
Jan 23, 2017, 1:06:43 PM1/23/17
to MIT App Inventor Forum
App Inventor 2 canvas although is very easy to control and to come up with cool thing, it is slow compared to more advanced programming platforms, like Android Studio.
3000 lines will take some time to draw and the general user who is not aware of the limitations of App Inventor might find it annoying or even think the app has crashed.
Any special requirement why you need 3000 lines? Are you sure you need that? Post your project requirements and may be we can help you find a workaround or a way to optimize it.

Manuel Wong

unread,
Jan 23, 2017, 1:21:22 PM1/23/17
to MIT App Inventor Forum
Hi Italo,
I just want to draw smooth curves in "real time".  Again, like watching someone draw.  I have everything working.  But it's just SO SLOW.  I have the clock set at "0".  It's just painful.

Italo

unread,
Jan 23, 2017, 1:25:02 PM1/23/17
to MIT App Inventor Forum
How about you set the clock to draw 10 or 20 lines each timer event instead of just one? I don't know if that works, It's just an idea I never tried.

Italo

unread,
Jan 23, 2017, 1:33:20 PM1/23/17
to MIT App Inventor Forum
Another thing that slows down the drawing must be the calculations. You said you are drawing curves. How much math happens every time each line is drawn?

Manuel Wong

unread,
Jan 23, 2017, 2:34:50 PM1/23/17
to MIT App Inventor Forum
A bit of trig is performed.  I am already only doing every 5th point.  So would storing all point positions before drawing speed things up?  Do the point calculations, then start the clock to only draw the lines?

Manuel Wong

unread,
Jan 23, 2017, 2:36:01 PM1/23/17
to MIT App Inventor Forum
This brings up the next question...how long will it take to calculate all the points?

SteveJG

unread,
Jan 23, 2017, 2:58:56 PM1/23/17
to MIT App Inventor Forum
A part of your issue may be "I have the clock set at "0""   ...Try a 'reasonable' refresh, at the moment your app is refreshing constantly, not really giving AI2 an opportunity to do the calculation and post the graphic segment.  Consider, AI2 graphics are s l o w compared to apps created with 100% Java compilers and AI2's Math routines are not especially fast.   Try refreshing every 100 ms and decrease or increase the interval and see how your app performs.  The Clock is not meant to set the Interval at 0.   AI2 code is processed asynchronously .  That means that a succeeding operation has to wait until the previous activity concludes (a little more complicated then that but that is essentially what happens). You got to provide time for code to execute and draw.

Wow, "long will it take to calculate all the points"   ...the answer is write the code then try it and see.  Be aware your graphics will run generally faster using the compiled app on the device than when using WIFI and certainly faster than when using the emulator.?  You graphics will never render at lightning speed.

Manuel Wong

unread,
Jan 23, 2017, 3:50:30 PM1/23/17
to MIT App Inventor Forum
Hi Steve,
I tried various values for the clock setting.  Started at 1000.  Decreased through 100, 10, 1.  Ended at 0.  I will try compiling the app and see how the "final" version performs on my phone.

Thanks

SteveJG

unread,
Jan 23, 2017, 6:27:11 PM1/23/17
to MIT App Inventor Forum
You might want to review the following Manuel.

I slightly modified his code (orbitModified.aia).   The app draws a circle, one degree of arc at a time.  To graph in real time 360 degrees, drawing one cord at a time, this App takes about 16 seconds more or less on an emulator on my PC.to draw the entire circle.

The demo (a clone of Scott's original post) provides a reasonable estimate of how long it might take AI2 to draw your 3000 line segments on an Canvas with an emulator    3000/360 * 16 = 133 seconds.   Is this your experience?



.and the links about drawing a line on a Canvas ...https://groups.google.com/forum/#!searchin/mitappinventortest/draw$20canvas   and smooth drawing https://groups.google.com/forum/#!searchin/mitappinventortest/smooth$20drawing  provide a wealth of information about drawing using AI2 and user's experiences.

--Steve


orbitModified.aia

Manuel Wong

unread,
Jan 23, 2017, 7:37:11 PM1/23/17
to MIT App Inventor Forum
Thank you very much Steve.  I will check this out the next chance I get to play with this.
Reply all
Reply to author
Forward
0 new messages