Whatdotcolor

From Compsci.ca Wiki

(Difference between revisions)
Jump to: navigation, search
(Added more links)
 
(3 intermediate revisions not shown)
Line 1: Line 1:
-
Also spelled whatdotcolour (Canadian spelling of colour), it is a Turing function which returns the colour of a specific pixel.  Often used for collision detection, it is an easy solution when creating something using Turing graphics alone without external images being involved.
+
Also spelled whatdotcolour (Canadian spelling of colour), it is a [[Turing]] function which returns the colour of a specific pixel.  Often used for [[collision detection]], it is an easy solution when creating something using Turing graphics alone without external images being involved.
It's actually so important that there's a [[whatdotcolor Warrior]] mod.
It's actually so important that there's a [[whatdotcolor Warrior]] mod.
Here's a quick example of a few basic graphics functions which uses whatdotcolour to check if the mouse is above a red circle.
Here's a quick example of a few basic graphics functions which uses whatdotcolour to check if the mouse is above a red circle.
-
<code>%%Example of whatdotcolour collision detection
+
<code>
 +
    %%Created By: [[Gandalf]]
 +
    %%Example of whatdotcolour collision detection
 +
    setscreen ("graphics,offscreenonly")
 +
    var cx, cy, mx, my, mb : int
 +
    cx := maxx div 2
 +
    cy := maxy div 2
 +
    var circleColour : int := red
 +
    loop
 +
        cls
 +
        Draw.FillOval (cx, cy, 40, 40, circleColour)
 +
        Mouse.Where (mx, my, mb)
 +
        if whatdotcolour (mx, my) = circleColour and mb > 0 then
 +
            cx := mx
 +
            cy := my
 +
        end if
 +
        View.Update
 +
    end loop
 +
</code>
-
%%By: Gandalf
+
An alternative of whatdotcolour collision detection in Turing is using [[Math.Distance]].
-
 
+
-
setscreen ("graphics,offscreenonly")
+
-
 
+
-
var cx, cy, mx, my, mb : int
+
-
 
+
-
cx := maxx div 2
+
-
 
+
-
cy := maxy div 2
+
-
 
+
-
var circleColour : int := red
+
-
 
+
-
loop
+
-
 
+
-
    cls
+
-
 
+
-
    Draw.FillOval (cx, cy, 40, 40, circleColour)
+
-
 
+
-
    Mouse.Where (mx, my, mb)
+
-
 
+
-
    %if your mouse is above the circle and you click
+
-
 
+
-
    if whatdotcolour (mx, my) = circleColour and mb > 0 then
+
-
 
+
-
        %move the circle to the mouse coordinates
+
-
 
+
-
        cx := mx
+
-
 
+
-
        cy := my
+
-
 
+
-
    end if
+
-
 
+
-
 
+
-
    View.Update
+
-
 
+
-
end loop</code>
+
-
 
+
-
An alternative of whatdotcolour collision detection in Turing is using Math.Distance.
+

Latest revision as of 23:51, 15 December 2005

Also spelled whatdotcolour (Canadian spelling of colour), it is a Turing function which returns the colour of a specific pixel. Often used for collision detection, it is an easy solution when creating something using Turing graphics alone without external images being involved.

It's actually so important that there's a whatdotcolor Warrior mod.

Here's a quick example of a few basic graphics functions which uses whatdotcolour to check if the mouse is above a red circle.

   %%Created By: Gandalf
   %%Example of whatdotcolour collision detection
   setscreen ("graphics,offscreenonly")
   var cx, cy, mx, my, mb : int
   cx := maxx div 2
   cy := maxy div 2
   var circleColour : int := red
   loop
       cls
       Draw.FillOval (cx, cy, 40, 40, circleColour)
       Mouse.Where (mx, my, mb)
       if whatdotcolour (mx, my) = circleColour and mb > 0 then
           cx := mx 
           cy := my
       end if
       View.Update
   end loop

An alternative of whatdotcolour collision detection in Turing is using Math.Distance.

Personal tools