Page 1 of 1

drawing with pencil VIA code, slow?

Posted: Tue May 03, 2011 3:34 pm
by neo42
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?

Re: drawing with pencil VIA code, slow?

Posted: Tue May 03, 2011 5:30 pm
by dunbarx
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

Re: drawing with pencil VIA code, slow?

Posted: Tue May 03, 2011 6:03 pm
by BvG
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