Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 whatdotcolor is terrible. Here's a better one.
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ttm




PostPosted: Sun Nov 27, 2011 9:14 pm   Post subject: whatdotcolor is terrible. Here's a better one.

Turing's built in whatdotcolor function is terrible. It gives the approximate color of a pixel instead of the exact red, green, and blue values. That means you can't apply special effects to photos. Bleh.

Therefore I rewrote a new whatdotcolor function. It works by taking a picture of the screen using the takepic function, which returns an integer array containing the raw picture information, and then directly fetching the red, green, and blue values from the array. Its syntax is the exact same as the original whatdotcolor, but instead of a color number, it returns a pixel class with R, G, and B values.

Here's a demo: http://dl.dropbox.com/u/17181264/better%20what%20dot%20color.zip. It first screenloads a picture, and then repeatedly inverts the picture over and over, using up a LOT of memory in the process.

Here it is:
code:

class _Color
    export ~.*Color, var r, var g, var b, use
    type Color : ^_Color
    var r, g, b : real := 0
    proc use
        RGB.SetColor (255, r, g, b)
    end use
end _Color
fcn newColor (r, g, b : real) : Color
    var n : Color
    new n
    n -> r := r
    n -> g := g
    n -> b := b
    result n
end newColor

fcn tonyswhatdotcolor (x, y : int) : Color
    var bleh : array 1 .. sizepic (1, 1, 2, 2) of int
    for i : 1 .. upper (bleh)
        bleh (i) := 9999
    end for
    takepic (x, y, x + 1, y + 1, bleh)
    var p, q: int
    var w, r, g, b : real
    if (bleh (19) ~= 9999) then
        p := bleh (19)
    else
        p := bleh (21)
        assert false
    end if
    b := bits (p, 24 .. 31) / 256
    r := bits (p, 16 .. 23) / 256
    g := bits (p, 8 .. 15) / 256
    w := bits (p, 0 .. 7) / 256
    result newColor (r, g, b)
end tonyswhatdotcolor


and here is the demo in action:
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Sun Nov 27, 2011 11:19 pm   Post subject: RE:whatdotcolor is terrible. Here\'s a better one.

Useful.
[Gandalf]




PostPosted: Mon Nov 28, 2011 1:43 am   Post subject: RE:whatdotcolor is terrible. Here\'s a better one.

whatdotcolor is terrible? 7 years ago you would be slaughtered by a certain moderator for such sacrilege! But times have changed - good work, you seem to have a good grasp of the language. Smile My main critisism would be that your variable naming needs work... bleh (and n) are horrible variable names, use something more descriptive!
dannyboy8899




PostPosted: Mon Feb 20, 2012 4:07 am   Post subject: RE:whatdotcolor is terrible. Here\'s a better one.

THE CAKE IS A LIE!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: