drawing with pencil VIA code, slow?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
neo42
Posts: 83
Joined: Tue Mar 01, 2011 10:20 pm

drawing with pencil VIA code, slow?

Post by neo42 » Tue May 03, 2011 3:34 pm

Take the following code:

Code: Select all

   
repeat with x = 1 to 200
    if random(2) = 1 then
       click at x, 10
    else
       click at x, 40
    end if
end repeat

This actually takes a while to run. How can I make it faster? The slow part appears to be the drawing. I don't think lock screen and unlock screen will speed it up much this time. Don't worry about the random check. That's there to demonstrate that I am not just drawing lines on screen. My code is creating pixels based on specific logic. For example, imagine if you were coding the LIFE simulation in LiveCode.

Is there can offscreen image buffer or something?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: drawing with pencil VIA code, slow?

Post by dunbarx » Tue May 03, 2011 5:30 pm

Hi.

I see that clicking is slow.

I haven't tried this, but what if you set the templateGraphic to a single pixel widget, and instead of clicking with the pencil tool, you create a new grc at the loc of each of those iterations? You can name them as you go if you need to.

Maybe?

Craig Newman

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: drawing with pencil VIA code, slow?

Post by BvG » Tue May 03, 2011 6:03 pm

If you go the graphic route instead of the image manipulation one you will gain a lot of speed. You might want to use a single graphic, and set its points, for stuff to draw properly. Note that you can't have antialiased graphics that have a single pixel, and you need to enter single pixels twice to be shown at all:

Code: Select all

on mouseUp
   lock screen
   create graphic
   set the style of it to polygon 
   set the antialiased of it to false
   repeat with x = 1 to 200
      if random(2) = 1 then
         set the points of it to the points of it & return & return & x, 10 & return & x, 10
      else
         set the points of it to the points of it & return & return & x, 40 & return & x, 40
      end if
   end repeat
end mouseUp
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply