Computer Science Canada

[Tutorial] whatdotcolor

Author:  Andy [ Sun Nov 30, 2003 10:48 pm ]
Post subject:  [Tutorial] whatdotcolor

ok peeps, i know you all've waited a long time for the infamous whatdotcolor man [that's me incase you're wondering] to share the secret behind my powers so here it is.

what is whatdotcolor?
whatdotcolor is the nicest, prettiest, smartest, and the most unefficent way to solve a problem.

the general form for whatdotcolor is whatdotcolor(x,y), where x and y are integers. what the command does is check the color of a pixel.

code:

drawdot(2,2,blue)
if whatdotcolor(2,2)=blue then
    put "I know how to use whatdotcolor
end if


the whatdotcolor in this case does return blue since pixel 2,2 is blue

now you're probably going wtf do i need this? and i dont blame you, it took me a while to realize the real use of whatdotcolor too. whatdotcolor is usually used with drawfill since you cant "drawfill" text. take a moment to think about it. when asked to do a problem involving a maze, what is the first thing that comes to you? double for loop? WRONG Snooty recursion? WRONG again:snooty:, whats with you ppl... Naughty whatdotcolor!!! if we were to solve a maze, recursion would work, but its no fun. you'd have to pass along which way you came from, and go seperate paths each time. however, with whatdotcolr, you simply plot the text maze they give you draw it out using for loops, then find the path and use drawfill! and you instantly solve the maze.

to help sink it in, i took the liberty to solve the J5 of last year of CCC using whatdotcolor... actualy i do these for fun with whatdotcolor cuz its cool Dance

the question gives you a floor plan using "I" s and "."s. I being a wall and . being a floor. the first three inputs gives you the number of tiles, and how many rows and colums of input there are. the questions asks you to put the maximum number of rooms you can cover filling in the smallest first and then outputting how much tiles you have left over. if you were to do this quesiton using recursion, its not that hard, but i being so enriched used whatdot color.

code:

%open the window so i can close it later
var window := Window.Open ("graphics:100,100,nobuttonbar,position: 1000;-1000")
var file, rows, columns, wood, colorcount, temp, roomscovered := 2
open : file, "floor.in", get
get : file, wood
get : file, rows
get : file, columns
% my grid
var grid : array 1 .. rows, 1 .. columns of string (1)

%this basicly gets the data and draws it out using color 1 for wall and color 2 for floor
for i : 1 .. rows
    for j : 1 .. columns
        get : file, grid (i, j) : 1
        if grid (i, j) = "I" then
            drawdot (j, maxy - i, 1)
        else
            drawdot (j, maxy - i, 2)
        end if
    end for
    drawdot (columns + 1, maxy - i, 1)
    drawdot (0, maxy - i, 1)
    get : file, skip
end for

for i : 1 .. columns
    drawdot (i, maxy - rows - 1, 1)
    drawdot (i, maxy, 1)
end for

%now i check if the program can find color two anywhere within my boundry
%if it does, i drawfill it with a different color so i dont count it again
for i : 0 .. rows + 1
    for j : maxy - columns - 1 .. maxy
        if whatdotcolor (i, j) = 2 then
            colorcount += 1
            drawfill (i, j, colorcount, 1)
        end if
    end for
end for

%and now i create the size of each room with the upper boundry of array the number of times i drawfilled
var roomsize : array 3 .. colorcount of int

for i : 3 .. colorcount
    roomsize (i) := 0
end for

% now i just check the number of times each color occured
for x : 3 .. colorcount
    for i : 1 .. rows
        for j : 1 .. columns
            if whatdotcolor (j, maxy - i) = x then
                roomsize (x) += 1
            end if
        end for
    end for
end for
Window.Close (window)

%and now that i'm done with the window, i close it and do the rest of my calculations
for i : 3 .. colorcount - 1
    for j : i .. colorcount
        if roomsize (j) > roomsize (i) then
            temp := roomsize (i)
            roomsize (i) := roomsize (j)
            roomsize (j) := temp
        end if
    end for
end for

roomscovered := 0

for i : 3 .. colorcount
    exit when roomsize (i) > wood
    roomscovered += 1
    wood -= roomsize (i)
end for
close (file)

open : file, "floor.out", put
put : file, roomscovered, " rooms, ", wood, " square meter(s) left over"
close (file)


as you can see, its done very easily with whatdotcolor. when i have some time, i'll post a recursive solution too.
well thats all you need to know for whatdotcolor. Claping
you too can become a whatdotcolor master, simply practice using it for program you do. trust me, every program can be done using whatdotcolor. if there isnt one, pm me, and i'll show you how to do it. except for ofcourse playing an mp3...



now bring on the bits mods... lol

Author:  Andy [ Sun Nov 30, 2003 10:51 pm ]
Post subject: 

ok mods, this thing took 3500 characters, 859 words, 4 pages on ms word font times new roman, and 30 min of my time! i better get something worthy... you know, a bit for every 50 characters would make me a very very happy Laughing

[mod:7af3b9f15d]
well that was a intresting way of doing that CCC question so i think you deserve some bits for aleast that Razz

+ a random amout of bits
[/mod:7af3b9f15d]

Author:  rizzix [ Sun Nov 30, 2003 10:58 pm ]
Post subject: 

Razz +1 bit

jkz u got 10 on top of dan's

Author:  AsianSensation [ Sun Nov 30, 2003 11:00 pm ]
Post subject:  Re: [Tutorial] whatdotcolor

dodge_tomahawk wrote:
...trust me, every program can be done using whatdotcolor. if there isnt one, pm me, and i'll show you how to do it. except for ofcourse playing an mp3...


sure you could

code:
var ans : string

process Song
    loop
        Music.PlayFile ("Got Rice.mp3")
    end loop
end Song

put "Do you want to play a song?"
get ans
if whatdotcolor (18, maxy - 24) = 7 then %because "yes" is longer than "no"
    fork Song
end if


hehehe

Author:  Andy [ Mon Dec 01, 2003 11:38 am ]
Post subject: 

ok azn, u got skillz, i give you that... so you can do any problem using whatdotcolor. if you find one that i cant, i'll give you all my bits... lol

Author:  bugzpodder [ Mon Dec 01, 2003 5:12 pm ]
Post subject: 

Make a program that draws a circle whenever it encounters whatdotcolor, and make it output "I cant dont this whis whatdotcolor"

Author:  Andy [ Mon Dec 01, 2003 6:29 pm ]
Post subject: 

bugzpodder wrote:
"I cant dont this whis whatdotcolor"

umm that made no sense to me... what do you mean? if you'll tell me i'll use whatdotcolor to do it...

Author:  Martin [ Tue Feb 24, 2004 3:44 pm ]
Post subject: 

Make a program that takes a line of text from a file and puts it below the line in reverse order, using whatdotcolour.

ex.
File.txt:
Hello

then you get this and file.txt becomes
Hello
olleH

Author:  Cervantes [ Thu Feb 26, 2004 7:11 pm ]
Post subject: 

not hard darkness
code:

colourback (0)
cls
if whatdotcolour (1, 1) = 0 then
%whatever the code is to do your text thingy
end if


muhahaha whatdotcolour can be used for everything!

Author:  Andy [ Thu Feb 26, 2004 8:03 pm ]
Post subject: 

dude, that wuz lame

code:

var fid : int
open : fid, "text.txt", get
var ch : string (1)
var count := 0
loop
    exit when eof (fid)
    get : fid, ch : 1
    count += 1
    drawdot (count, 0, ord (ch))
end loop
close : fid
open : fid, "text.txt", put
for decreasing i : count .. 1
    put : fid, chr (whatdotcolor (i, 0)) ..
end for

Author:  programer007 [ Sun Mar 07, 2004 4:38 pm ]
Post subject: 

how did you get the title: Whatdotcolor warrior??is it because you use it the most???? and taht program you posted.,... it wont wokr.. IO error for the files....cool deal tho.. i could use it in the future

Author:  Cervantes [ Sun Mar 07, 2004 4:55 pm ]
Post subject: 

He got the whatdotcolour warrior title cuz he's a mod.
your post is spam. Try to keep the spam to the spam section alone. I advise you to look at the rules
Read em all, not just the part on spam.

Author:  AsianSensation [ Sun Mar 07, 2004 6:54 pm ]
Post subject: 

programer007 wrote:
how did you get the title: Whatdotcolor warrior??is it because you use it the most???? and taht program you posted.,... it wont wokr.. IO error for the files....cool deal tho.. i could use it in the future


he got the title for whatdotcolor warrior because dodge is obsessed with it, and tries to do every single question with whatdotcolor.

As for the error, read up on File input and output, because the program he wrote deals with input and output from file. If you don't have a file with a specific name, of course you would get an error.

Author:  xmen [ Mon Mar 29, 2004 10:07 pm ]
Post subject: 

ok i got a problem

u see i was using whatdotcolour for my screensaver, which happend to be few balls (or happy faces) flying and bouncing around the screen........i used a program from Cervantes n kinda modify....

anyway i also hav these 2 obstacles in the middle of screen......so the balls also bounce away once contact with those obstacles=>by using whatdotcolour

PROBLEM IS, the whatdotcolour only works for the x-axis n y-axis for each balls, therefore only four contact testing points........SO, if the ball was to hit the obstacle on the upperleft,upperrite,lowerleft,loweright corner, the balls will go straight into the obstacles n weird things happen

here is a copy of my program, anyone plzz take a look at it (let it run a while then u'll see what i mean)

code:

setscreen ("graphics:800;600")
View.Set ("offscreenonly")
colourback (grey)
var totalballs : int := 3 %NOTE : to increase how many balls will spawn this number must be at least equal to the max number of balls
var x, y, dx, dy : array 1 .. totalballs of int
var dx_temp, dy_temp : array 1 .. totalballs of real
var movedist1, movedist2, collangle, mass, a1, a2, nX, nY, optimisedP : real

var px, py, abc1, abc2 : int
px := maxx div 2
py := maxy div 2
const ballradius := 10
const ballcollidedistance := ballradius * 2
const eye : int := ballradius div 6
const eyes : int := ballradius div 9
const glasses : int := ballradius div 3

const r := 60
const eye2 := r div 5
const x2 := (maxx div 2) div 2
const x3 := (maxx div 4) * 3
const y2 := maxy div 2

mass := 1

for i : 1 .. totalballs
    %%%%%%%%%%%%%%%%Random starting position of each ball%%%%%%%%%%%%%%%%%%%%
    x (i) := Rand.Int (20 + ballradius, maxx - 20 - ballradius)
    y (i) := Rand.Int (20 + ballradius, maxy - 20 - ballradius)
    loop
        if x (i) >= (maxx div 2) div 2 - 60 and x (i) <= (maxx div 4) * 3 + 60 then
            x (i) := Rand.Int (20 + ballradius, maxx - 20 - ballradius)
        elsif y (i) >= maxy div 2 - 80 and y (i) <= maxy div 2 + 80 then
            y (i) := Rand.Int (20 + ballradius, maxy - 20 - ballradius)
        elsif x (i) < maxx div 2 - 80 or x (i) > maxx div 2 + 80 then
            exit
        elsif y (i) < maxy div 2 - 80 or y (i) > maxy div 2 + 80 then
            exit
        end if
    end loop
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%Speed and Direction%%%%%%
    randint (abc1, 1, 2)
    if abc1 = 1 then
        dx (i) := 3
    else
        dx (i) := -3
    end if
    randint (abc2, 1, 2)
    if abc2 = 1 then
        dy (i) := 3
    else
        dy (i) := -3
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end for
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Staring layout%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc drawscreen
    %drawfillbox (20, 20, maxx - 20, maxy - 20, black)

    drawfilloval (x2, y2, r, r, 20)
    drawfilloval (x2 + r div 3, y2 + r div 3, eye2 div 2, eye2, black)
    drawfilloval (x2 - r div 3, y2 + r div 3, eye2 div 2, eye2, black)
    drawarc (x2, y2 - r div 4, r div 2, r div 3, 180, 360, black)

    drawfilloval (x3, y2, r, r, 20)
    drawfilloval (x3 + r div 3, y2 + r div 3, eye2 div 2, eye2, black)
    drawfilloval (x3 - r div 3, y2 + r div 3, eye2 div 2, eye2, black)
    drawarc (x3, y2 - r div 4, r div 2, r div 3, 180, 360, black)

end drawscreen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Ball Faces and Boundaries%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc ball_movement
    for i : 1 .. totalballs
        %wall bouncing
        if x (i) > maxx - ballradius or x (i) < ballradius or whatdotcolour (x (i) + ballradius, y (i)) = 20 or whatdotcolour (x (i) - ballradius, y (i)) = 20 or whatdotcolour (x (i),
                y (i)) = 20 then
            dx (i) := -dx (i)
            x (i) += dx (i)
        elsif y (i) > maxy - ballradius or y (i) < ballradius or whatdotcolour (x (i), y (i) + ballradius) = 20 or whatdotcolour (x (i), y (i) - ballradius) = 20 then
            dy (i) := -dy (i)
            y (i) += dy (i)
        end if

        x (i) += dx (i)
        y (i) += dy (i)
        drawfilloval (x (i), y (i), ballradius, ballradius, yellow) %face
        drawfilloval (x (i), y (i) - (ballradius div 5) * 3, ballradius div 4, ballradius div 3, brightred) %tongue border
        drawfilloval (x (i), y (i), ballradius div 2, ballradius div 2, yellow) %yellow tongue cover
        drawfilloval (x (i) + ballradius div 3, y (i) + ballradius div 3 - ballradius div 10, eyes, eye, black) %left eye
        drawfilloval (x (i) - ballradius div 3, y (i) + ballradius div 3 - ballradius div 10, eyes, eye, black) %right eye
        drawarc (x (i), y (i) - ballradius div 4, ballradius div 2, ballradius div 3, 180, 360, black) %mouth
        drawfillarc (x (i), y (i) + (ballradius div 10) * 5, (ballradius div 10) * 9, ballradius div 2, 360, 180, 115) %hat
        drawline (x (i), y (i) - (ballradius div 6) * 2, x (i), y (i) - (ballradius div 5), black) %nose
        drawoval (x (i) + ballradius div 3, y (i) + ballradius div 3 - ballradius div 10, glasses, glasses, black) %right glass
        drawoval (x (i) - ballradius div 3, y (i) + ballradius div 3 - ballradius div 10, glasses, glasses, black) %left glass
        drawline (x (i) - (ballradius div 10) * 7, y (i) + (ballradius div 10) * 3 - ballradius div 10, x (i) - ballradius, y (i) + (ballradius div 10) * 3 - ballradius div 10, black)
        %left glass
        drawline (x (i) + (ballradius div 10) * 7, y (i) + (ballradius div 10) * 3 - ballradius div 10, x (i) + ballradius, y (i) + (ballradius div 10) * 3 - ballradius div 10, black)
        %right glass

    end for
end ball_movement
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Collision Physics%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc balls_collide
    for i : 1 .. totalballs
        for k : i .. totalballs

            if k not= i then
                if Math.Distance (x (i), y (i), x (k), y (k)) < ballcollidedistance then
                    %CREDIT : THOUGHTFUL
                    if y (k) - y (i) not= 0 and x (k) - x (i) not= 0 then
                        collangle := arctand ((y (k) - y (i)) / ((x (k) - x (i))))

                        nX := cosd (collangle)
                        nY := sind (collangle)

                        a1 := x (i) * nX + y (i) * nY
                        a2 := x (k) * nX + y (k) * nY

                        optimisedP := (2.0 * (a1 - a2)) / (mass + mass)

                        x (i) := x (i) - (round (optimisedP) * round (mass) * round (nX))
                        y (i) := y (i) - (round (optimisedP) * round (mass) * round (nY))
                        x (k) := x (k) + (round (optimisedP) * round (mass) * round (nX))
                        y (k) := y (k) + (round (optimisedP) * round (mass) * round (nY))
                        % moves the balls forward a step so they dont get stuck with each other( but the balls will still stick)
                        x (i) += dx (i)
                        y (i) += dy (i)
                        x (k) += dx (k)
                        y (k) += dy (k)
                    end if
                end if
            end if
        end for
    end for
end balls_collide
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Program%
loop
    exit when hasch
    cls
    drawscreen
    ball_movement
    balls_collide
    View.Update
    delay (8)
end loop


anyone who knows how to fix this PLZZZZZZZZZZZ reply . Thankyou

Author:  Cervantes [ Tue Mar 30, 2004 4:10 pm ]
Post subject: 

terrible sorry dodge, but on this one I have to side with asian.

in this type of situation, especially because you're ussing cirlces, don't use whatdotcolour. use Math.Distance (was it you that was asking what Math.Distance is? if so, just use the distance formula).

code:

if Math.Distance (smallhappyface_x, smallhappyface_y, bighappyface_x, bighappyface_y) < smallhappyface_radius + bighappyface_radius then

that's how you determine if there is a collision.

I also have a few suggestions. Since the smallhappyfaces are bouncing off the big happyfaces (both of which are circles) you should use the same colision data as between the smallhappyfaces, except transfer 100% energy to the smallhappyfaces.
also, drawing each part of your happyfaces each loop is not very efficient. I recommend drawing your happyfaces (both big and small) at the beginning of the program and then use Pic.New to grab the picture that you just drew and assign it a variable handle.

Author:  xmen [ Tue Mar 30, 2004 4:15 pm ]
Post subject: 

wut if i do whatdotcolour for the 4 corners of the small happy faces?? i think that'll work with much less work too dont u think

Author:  Cervantes [ Tue Mar 30, 2004 4:54 pm ]
Post subject: 

doing whatdotcolour on the 4 corners of the happyfaces is what's giving you the trouble isn't it?
trust me, for circles, you want Math.Distance.

Author:  Walker [ Fri Apr 02, 2004 11:35 pm ]
Post subject: 

Wuld is be possible using Math.Distacne + slop to check the pixel color of every pixle on the line between 2 points? Im trying to do something like this for my project.

Author:  recneps [ Sat Apr 03, 2004 3:10 pm ]
Post subject: 

you could. but that isnt a questio nof can whatdotcolour do it, its how you would get the points on the line
(whatdotcolour ALWAYS WORKS! It works for EVERYTHING! *sucks up to dodge*)

Author:  Walker [ Sat Apr 03, 2004 9:32 pm ]
Post subject: 

By possible i ment will it lag the prgram up reeeeealy badly

Author:  Andy [ Sat Apr 17, 2004 12:54 pm ]
Post subject: 

for whatdotcolor circle colission detection, what you do is you add on the value, then u run through all the circumference of ur circle, and check if its a color other than your original if isnt then subtract back the vaule

Author:  Paul [ Sat Apr 17, 2004 1:04 pm ]
Post subject: 

how would you check thru the circumference of the circle??
waaa no one wants to explain to me.

Author:  Andy [ Sat Apr 17, 2004 1:05 pm ]
Post subject: 

use the equation of the circle x^2+y^2=r^2

Author:  Paul [ Sat Apr 17, 2004 1:06 pm ]
Post subject: 

I don't really get that, is that pythagorean or something? can u gimme an example like just something to check all the points on the circumference of the circle.

Author:  Raugrist [ Sat Apr 17, 2004 3:32 pm ]
Post subject: 

It is pythagorean kinda, if you think about it. Draw a circle on the origin. Now pick a point on the circumference and draw one line to the x-axis and another to the center of the circle. You know have a right triangle.

Author:  Andy [ Fri Apr 23, 2004 10:21 am ]
Post subject: 

Paul Bian wrote:
I don't really get that, is that pythagorean or something? can u gimme an example like just something to check all the points on the circumference of the circle.

what grade are you in?

Author:  Paul [ Fri Apr 23, 2004 12:38 pm ]
Post subject: 

grade 10, I know pythagorean but I dunno how to use it in Turing.

Author:  Delta [ Mon Apr 26, 2004 7:55 pm ]
Post subject: 

If you know it then you should be able to use it right? Cuz knowing it implies that you can use it right? the equations are pretty much exactly the same inside and outside of turing right?... hence your either lying or... your just not thinking hard enough Confused

Author:  Paul [ Mon Apr 26, 2004 8:02 pm ]
Post subject: 

Enough with the words just give me a goddamned example code.

Author:  we64 [ Mon May 10, 2004 7:52 pm ]
Post subject: 

dodge_tomahawk wrote:
use the equation of the circle x^2+y^2=r^2

that is not really the pythagorean formula, it is also the equation of the circle. Remember what you did in class? it is actually quite useful, for example, if you know the coordinate of x and it gives you y.

let's say you radius is 5, so when (x = 5, y=0), (x=4 , y=3), (x=3, y=4), (x=2, y = sqrt (21)), (x=1, y= sqrt (24)), (x=0, y=5) it would be the same for the negative x and everything here is plus or minus.

In this case, you want to check for every point of the circle, I don't think that is possible, because whatdotcolour (x,y) must be an integer. It would not be accurate.

Author:  Cuzty [ Wed May 12, 2004 6:16 pm ]
Post subject: 

Ok mister whatdotcolor master guy.. umm i was wondering if you can make the bullet kill the ball that comes down. And i apologize for the crappy code.. i'm not very good at this turing stuff so plz bear with me Confused .

code:
setscreen ("offscreenonly")
var m, x, a, b, ymouse, xmouse, button : int

%The Plane
procedure plane
    drawline (xmouse - 4, 5, xmouse, 40, 4)
    drawline (xmouse - 3, 5, xmouse, 40, 4)
    drawline (xmouse - 2, 5, xmouse, 40, 4)
    drawline (xmouse - 1, 5, xmouse, 40, 4)
    drawline (xmouse, 5, xmouse, 40, 4)
    drawline (xmouse + 1, 5, xmouse, 40, 4)
    drawline (xmouse + 2, 5, xmouse, 40, 4)
    drawline (xmouse + 3, 5, xmouse, 40, 4)
    drawline (xmouse + 4, 5, xmouse, 40, 4)
end plane

%The falling ball
process nme
    loop
        cls
        randint (m, 10, maxx - 10)
        for decreasing i : maxy .. 1 by 7
            drawfilloval (m, i, 10, 10, 4)
            delay (10)
        end for
    end loop
end nme

%Your Plane
process you
    loop
        mousewhere (xmouse, ymouse, button)
        cls
        plane
        View.Update

        %The Bullet
        if button = 1 then
            a := xmouse
            b := ymouse
            for i : 40 .. 400 by 5
                cls
                mousewhere (xmouse, ymouse, button)
                plane

                drawline (a - 1, i, a - 1, i + 40, 7)
                drawline (a, i, a, i + 40, 7)
                drawline (a + 1, i, a + 1, i + 40, 7)
                View.Update
            end for
        end if
    end loop
end you

fork nme
fork you


Oh, and if possible.. can you make the ball stop flickering? Thanks so much in advance, sir. Very Happy

Author:  Leny [ Wed Jun 02, 2004 9:17 am ]
Post subject: 

Ok so you can do anything with whatdotcolour so help me then how do i do what dot coulr in a circular pattern

i.e. in my curling game i need to do the scoreing at the end by checking which rocks are closer to the center

so if there are two blue rocks closer then the first red rock then the score becomes two blue or one red rock cloest to the center then a blue one closer then the next red one then the score is one red

how would i do that?

Author:  Tony [ Wed Jun 02, 2004 12:06 pm ]
Post subject: 

Leny : don't make things complicated and just use Math.Distance() Rolling Eyes

Author:  Leny [ Wed Jun 02, 2004 2:35 pm ]
Post subject: 

our school computers can't do that i've tried it as well as others and it wont work for anyone including the teach who knows what she's doing

Author:  Tony [ Wed Jun 02, 2004 5:09 pm ]
Post subject: 

Leny : Math.Distance is a v4.0.5 feature. If you don't have the latest version of turing installed, you can write this function yourself
code:

function distance (x1, y1, x2, y2 : int) : real
    result sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)
end distance

%example
put distance (0, 0, 3, 4)

Author:  Leny [ Thu Jun 03, 2004 9:14 am ]
Post subject: 

so how would i use this math.distance thingger then? is there a tutorial on it?

or maybe a basic program with it to look at

Author:  Tony [ Thu Jun 03, 2004 11:53 am ]
Post subject: 

leny : there is a tutorial now Laughing

Author:  Leny [ Thu Jun 03, 2004 5:31 pm ]
Post subject: 

thanks man if i have any trouble i'ma ask ya more about it but i should figure it out

Author:  theanimator [ Wed Oct 26, 2005 8:11 pm ]
Post subject: 

this whatdotcolour makes no sense to me at all. Bare with me i am just a beginner.

Author:  TokenHerbz [ Thu Oct 27, 2005 2:59 am ]
Post subject: 

code:

   
        (x1,xy)  <-----TOP RIGHT OF SQUARE
    %%%%%%%
    %     %
    %     %
    %%%%%%%           
 (x,y)           <<---  BOTTOM LEFT OF SQUARE!

 
 whatdotcolor takes the 2 varibles, say (x,y) and looks on the background
 of your program, and sees which colour it is on...



heres an example!

code:

%%Example.
setscreen("Graphics:max;max,offscreenonly")

var x,y: int
var x1,y1: int
x:= 50
y := 50
x1:= x+50
y1 := y+20

loop
    cls
    x += 1
    x1+= 1
    drawfillbox(225,25,175,75,black)     %%this is BIG BLACK BOX!
    if whatdotcolor(x,y) = 7 then  %%IF x,y SEE BLACK!
        exit    %%LEAVES THE LOOP!
    end if
    drawbox(x,y,x1,y1,red)
    View.Update
    delay(20)
end loop
put "Done"


If you run that, you will see it stops only when x,y get hit...

Now if we refer to the top diagram i shows, x1,y1 need to be in play aswell.! this way it will stop at the front.

So we just modify this here...
code:

    if whatdotcolor(x,y) = 7 or  %%IF x,y SEE BLACK!
        whatdotcolor(x1,y1) = black then    %%7 and black are the same thing.
        exit    %%LEAVES THE LOOP!
    end if


run it...

BUT, lets see, change y to this ...
code:

y:= 65


Run that, now you will see that the x1,y1 position is missed, and its not a detection collition at all, so we have to think hard cause programming not easy. For effective collotioning/ useing whatdotcolor, you must cover all angles, i trust you learned a bit??? Well Gl with this! i ll let you try some stuff now


EDIT::

So, we need to be creative (which i am not) and make a simple code what checks all of the obsticle, or at least.. the border of it.

um somthing like??
code:

    %%Example.
setscreen("Graphics:max;max,offscreenonly")

var x,y: int
var x1,y1: int
var endgame: boolean := false
x:= 50
y := 65
x1:= x+50
y1 := y+20

loop
    if endgame = true then
        exit
    end if
    cls
    x += 1
    x1+= 1
    drawfillbox(225,25,175,75,black)     %%this is BIG BLACK BOX!
    for i: x .. x1
        for j: y .. y1
            if whatdotcolor(i,j) = 7 then  %%IF x,y SEE BLACK!
                endgame := true    %%SETS END GAME!
                exit
            end if
        end for
        if endgame = true then
            exit
        end if
    end for
    drawbox(x,y,x1,y1,red)
    View.Update
    delay(20)
end loop
put "Done"


Notice how slow it moves, its not efficiant, cause its checking the INSIDE of the rectangle, when we only need it to check the borders, so ill let you think about it, and work with that... Bye!


EDIT:::

Well again i wish to help you think on how to visualize getting a border..

if we think a 5*5 square..

its,

code:

x,y: int := 0

drawbox(x,y,x+5,y+5,black)


lets look at the *structure* of this

NOTE::: The 1st numbers are x axis numbers, 2nd are the y axis.

code:

1,5  2,5  3,5  4,5  5,5
1,4  2,4  3,4  4,4  5,4
1,3  2,3  3,3  4,3  5,3
1,2  2,2  3,2  4,2  5,2
1,1  2,1  3,1  4,1  5,1


So with that there, Try to code a patter which checks essentailly only these numbers.

code:

1,5  2,5  3,5  4,5  5,5
1,4                 5,4
1,3                 5,3
1,2                 5,2
1,1  2,1  3,1  4,1  5,1


Now, to make it a bit easier for you to get which variables are which..
code:

x,y+4 | x+1,y+4 | x+2,y+4 | x+3,y+4 | x+4,y+4
x,y+3                                 x+4,y+3
x,y+2                                 x+4,y+2
x,y+1                                 x+4,y+1
x,y   | x+1,y   |  x+2,y  |  x+3,y  |  x+4,y


Now you wouldn't want to enter in all the possible variables for a big square, so image if you could have a counter??

of course then, you could replayce all the numbers with i(for x axis) and j(for y axis)

The code gets a little complex, and ill post it later if you dont get it

i think i tend to make thinks more complex then they should :S

Author:  BenLi [ Tue May 02, 2006 4:03 pm ]
Post subject: 

i have a question, why would you use whatdotcolor for things that can probably be done easier with other methods? its a total waste of time

Author:  md [ Tue May 02, 2006 4:44 pm ]
Post subject: 

Because it works for very simple cases and doesn't require consious thought. Wink

Really using math to do collisions is only easy if you know the (admittedly basic) math and are familiar enough with things like records to keep track of everythign easily.

Author:  HellblazerX [ Tue May 02, 2006 4:53 pm ]
Post subject: 

Whatdotcolor is not useless. In fact, it's quite useful in collision detection. Normally, you would use coordinates and calculate whether or not one object is within another, but with whatdotcolor, you can easily determine whether or not the objects have collided by checking the colors of a particular point. Also, if you use coordinates, collision detection becomes more and more difficult when more objects are placed on the field, and the objects themselves become more complicated in their shapes. With whatdotcolor, it doesn't get that much more difficult.

Author:  Andy [ Fri May 05, 2006 9:18 pm ]
Post subject: 

cornflakes! you're such a blasphemer! how dare you say that about whatdotcolour? haha jk..

my obsession with whatdotcolour has nothing to do with "taking the easy way" but rather thinking abstractly. collision detection whatdotcolor is for noobs... unless you're talking about masking irregular shapes

Author:  BenLi [ Thu May 11, 2006 3:07 pm ]
Post subject: 

Though for the example above, it'd be much better to use Math.Distance for the circle

Author:  MysticVegeta [ Thu May 11, 2006 5:57 pm ]
Post subject: 

If you look at the Turing Reference (F10) and check out the Math.Distance index, you will see they used Math.Distance for the circles, you are right.

Author:  evildaddy911 [ Thu Oct 13, 2011 2:49 pm ]
Post subject:  RE:[Tutorial] whatdotcolor

so i now know how to use whatdotcolor for every pixel in a square/ horizontal/vertical line.... but how do i use whatdotcolor for a diagonal line?

drawline (0 , 100 , 100 , 0 , black)

what is the code for this?

EDIT: figured it out:
code:

    for a : 0 .. 100
        if whatdotcolor (a, 100 - a) = blue then
            put "hit"
        end if
    end for

Author:  Hoshi [ Thu Dec 15, 2011 9:21 am ]
Post subject:  RE:[Tutorial] whatdotcolor

Is there a Tutorial on using RGB colours? or is that impossible to use on turing. say i wanted
R=50
G=16
B=17
for a dot

Author:  Insectoid [ Thu Dec 15, 2011 11:30 am ]
Post subject:  RE:[Tutorial] whatdotcolor

Yes, it's possible. There is a tutorial available in the Turing Walkthrough. Instead of asking for a tutorial next time, try using the website's built-in search.


: