Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: to-offset

From: greggirwin:mindspring at: 12-Apr-2002 11:32

Hi Romano, << What is the best way to find the offset of a pixel in an image given a pair? to-offet: func [image [image!] pos [pair!]][ ??? ]>> I wrote an article for the latest 'zine on REBOLForces that deals with this. Here are some relevant snippets. to-index: func [pos [pair!] cols [integer!] ] [ pos/y - 1 * cols + pos/x ] pick-xy: func [data [series!] pos [pair!] cols [integer!] ] [ pick data to-index pos cols ] poke-xy: func [data [series!] pos [pair!] cols [integer!] value ] [ poke data to-index pos cols value ] These wrappers just reduce the number of parameters we have to pass, and make it clear exactly what we're doing. I.e. working with images and pixels. pick-pixel: func [img [image!] pos [pair!]] [ pick-xy img pos img/size/x ] poke-pixel: func [img [image!] pos [pair!] value [tuple!]] [ poke-xy img pos img/size/x value ] HTH! --Gregg