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

Username:   Password: 
 RegisterRegister   
 [Tutorial] whatdotcolor
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Andy




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sun Nov 30, 2003 10:51 pm   Post subject: (No 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]
rizzix




PostPosted: Sun Nov 30, 2003 10:58 pm   Post subject: (No subject)

Razz +1 bit

jkz u got 10 on top of dan's
AsianSensation




PostPosted: 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
Andy




PostPosted: Mon Dec 01, 2003 11:38 am   Post subject: (No 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
bugzpodder




PostPosted: Mon Dec 01, 2003 5:12 pm   Post subject: (No subject)

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




PostPosted: Mon Dec 01, 2003 6:29 pm   Post subject: (No 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...
Martin




PostPosted: Tue Feb 24, 2004 3:44 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Feb 26, 2004 7:11 pm   Post subject: (No 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!
Andy




PostPosted: Thu Feb 26, 2004 8:03 pm   Post subject: (No 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
programer007




PostPosted: Sun Mar 07, 2004 4:38 pm   Post subject: (No 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
Cervantes




PostPosted: Sun Mar 07, 2004 4:55 pm   Post subject: (No 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.
AsianSensation




PostPosted: Sun Mar 07, 2004 6:54 pm   Post subject: (No 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.
xmen




PostPosted: Mon Mar 29, 2004 10:07 pm   Post subject: (No 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
Cervantes




PostPosted: Tue Mar 30, 2004 4:10 pm   Post subject: (No 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.
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 4  [ 49 Posts ]
Goto page 1, 2, 3, 4  Next
Jump to:   


Style:  
Search: