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

Username:   Password: 
 RegisterRegister   
 Using loops to get all possible x,y co-ordinates of a value
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tristanbryce7




PostPosted: Tue Dec 04, 2012 10:46 pm   Post subject: Using loops to get all possible x,y co-ordinates of a value

Hey, I wanted to know if there was any way to use loops, to get all the possible x,y co-ordinates in an output window? so far all I can manage to figure out is, how to get all values for (1,y), where y is all the y values of the co-ordinate up to the max y co-ordinate, but thats only when x = 1, how would I change my code to get it to get all the possible co-ordinates in my program. How would I use the loop statement to acheive this?

Turing:


var x, y : int := 0

setscreen ("graphics:600;600")

forward proc code

var dexter : int
var stream : int
open : stream, "turing.txt", put

dexter := Pic.FileNew ("dexter.jpg")

Pic.Draw (dexter, 0, 0, picCopy)

body proc code


    for lool : 1 .. maxy
        x := 1
        y := y + 1
        put : stream, "drawdot(", x, ",", y, ",", whatdotcolor (x, y), ")"
    end for


end code

code
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue Dec 04, 2012 11:04 pm   Post subject: RE:Using loops to get all possible x,y co-ordinates of a value

You might try putting a loop inside a loop.
tristanbryce7




PostPosted: Tue Dec 04, 2012 11:39 pm   Post subject: Re: Using loops to get all possible x,y co-ordinates of a value

Turing:

var x, y : int := 0

setscreen ("graphics:600;600")

forward proc code

var dexter : int
var stream : int
open : stream, "turing.txt", put

dexter := Pic.FileNew ("dexter.jpg")

Pic.Draw (dexter, 0, 0, picCopy)

body proc code


    for xloop : 1 .. maxx
        x := x + 1


        for yloop : 1 .. maxy
            put : stream, "drawdot(", x, ",", y, ",", whatdotcolor (x, y), ")"
            y := y + 1

        end for
        y := 0
    end for

end code

code



It took the longest time ever to run Sad , and the final output to draw the dude was like 300,000+ lines, but i got it though, after I got the output on the turing.txt file i copied and pasted, and voila, done. I dont know of any better way to do it though , if you could tell me a better way that I did, id appreciate it (for like getting turing to draw it for you). Did you have a different idea in mind, if you did, id love to know Smile, cuz this seems pretty inefficent lol (300,000 lines toooo much xD)
Tony




PostPosted: Wed Dec 05, 2012 12:02 am   Post subject: RE:Using loops to get all possible x,y co-ordinates of a value

Draw.Line

For example, instead of saying
Quote:

draw black dot
draw black dot
draw black dot
draw black dot
draw black dot

it can be shortened to
Quote:

draw black line, length 5


Welcome to the exciting ideas of http://en.wikipedia.org/wiki/Image_compression
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zren




PostPosted: Wed Dec 05, 2012 12:24 pm   Post subject: RE:Using loops to get all possible x,y co-ordinates of a value

You do realize that when the window's width/height is 600, maxx and maxy are equal to 599 right? Which is the last coordinate on screen (599, 599) in your case. The screen coordinates start from (0, 0) and go to (window.width - 1, window.height - 1).

This beings up the matter of your for loops. Which cover the range of:
code:

x = 0
for each value represented as x2 (or xloop in your case) in the range 1 <= x2 <= maxx (when incrementing by 1):
    x += 1 % x=1
    put x % 1

And on the final iteration, xLoop will be 599 and x will be 600, which is offscreen.
code:

for each value represented as x2 (or xloop in your case) in the range 1 <= x2 <= maxx (when incrementing by 1):
    x += 1 % x = 600
    put x % 600

You want to cover the range from 0 .. maxx.

Which brings up the question as to why you're not using the for loops counter variable (xloop and yloop), and instead creating another counter (x and y).
tristanbryce7




PostPosted: Wed Dec 05, 2012 6:11 pm   Post subject: Re: Using loops to get all possible x,y co-ordinates of a value

Ahh, I see, That is true, the thougt never ocurred in my mind to use x/y loop, im so used to counters that I guess I forgot :[, and the program ran perfectly fine regardless Smile Just too many liness lool ...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: