Help Needed Related to Randomizing Pictures
Author |
Message |
glitchy_gal12
|
Posted: Sun May 28, 2006 3:07 pm Post subject: Help Needed Related to Randomizing Pictures |
|
|
Ok, I have to create this slot machine program, from which I have to randomize 4 different shapes into 3 seperate square boxes on the same screen, and that the program's purpose is for the user to keep pushing a button until all three slot boxes have 3 identical shapes. The shapes that I am using are a star, an oval, a square, and a maple leaf. The program I'm using is Turing. I'm kind of struggling with this randomizing stuff. If you can, please help me with producing the code |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 3:28 pm Post subject: (No subject) |
|
|
You've got 4 possible shapes to produce on screen one. You can pick a random number between 1 and 4 using
|
|
|
|
|
|
glitchy_gal12
|
Posted: Sun May 28, 2006 3:37 pm Post subject: (No subject) |
|
|
Cervantes wrote: You've got 4 possible shapes to produce on screen one. You can pick a random number between 1 and 4 using
Thanks for replying Thanks for the tip, but out of curiousity, is the answer to my problem within to the following thread? http://www.compsci.ca/v2/viewtopic.php?t=12451&highlight=randomize |
|
|
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 3:58 pm Post subject: (No subject) |
|
|
Maybe.
As for drawing your actual picture, the easiest thing to do would be to create an array of procedures.
code: |
var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int)
procedure box (x1, y1, x2, y2 : int)
Draw.FillBox (x1, y1, x2, y2, black)
end box
% Do the same for the other shapes
outcome (1) := box
% Do the same for the other shapes
outcome (Rand.Int (1, 4)) (100, 100, 200, 200)
|
Not sure I've got the syntax right, here. Can't test it at the moment. Try playing around with it if it's not right, then post back here with the syntax error. |
|
|
|
|
|
HellblazerX
|
Posted: Sun May 28, 2006 4:09 pm Post subject: (No subject) |
|
|
Cervantes wrote: an array of procedures.
What?!!!! Wow, never knew that. Does this only apply to Turing, or does this ability extend to other languages? |
|
|
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 4:17 pm Post subject: (No subject) |
|
|
Yes, it extends to other languages. It extends especially well to functional languages (a procedure is just a function to a language that doesn't have a defined unit (nil) value, to paraphrase wtd).
For an in-depth explanation of this phenomenon, see Turing as a Functional Programming Lanugage. |
|
|
|
|
|
glitchy_gal12
|
Posted: Sun May 28, 2006 4:29 pm Post subject: (No subject) |
|
|
Cervantes wrote: Maybe.
As for drawing your actual picture, the easiest thing to do would be to create an array of procedures.
code: |
var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int)
procedure box (x1, y1, x2, y2 : int)
Draw.FillBox (x1, y1, x2, y2, black)
end box
% Do the same for the other shapes
outcome (1) := box
% Do the same for the other shapes
outcome (Rand.Int (1, 4)) (100, 100, 200, 200)
|
Not sure I've got the syntax right, here. Can't test it at the moment. Try playing around with it if it's not right, then post back here with the syntax error.
Ok, I found no syntax errors (Horray!). However, now that I've figured out how to randomize the outcome once, how would I display 2 more seperate random outcomes on the same screen, in addition to my first outcome display? Here's the code I have so far:
code: | var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int)
var outcome2 : array 1..4 of procedure p (x1,y1,x2,y2:int)
procedure box (x1, y1, x2, y2 : int)
Draw.FillBox (120, 280, 180, 340, black)
end box
procedure star (x1,y1,x2,y2:int)
Draw.FillStar (120,280,180,340,black)
end star
procedure oval (x1,y1,x2,y2:int)
Draw.FillOval (150,310,30,30,black)
end oval
procedure mapleleaf (x1,y1,x2,y2:int)
Draw.FillMapleLeaf (120,280,180,340,black)
end mapleleaf
outcome (1) := box
outcome (2) := star
outcome (3) := oval
outcome (4) := mapleleaf
outcome (Rand.Int (1, 4)) (100, 100, 200, 200) | [/code] |
|
|
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 4:33 pm Post subject: (No subject) |
|
|
code: |
for i : 1 .. 3
outcome (Rand.Int (1, 4)) (100 * i, 100, 100 * i + 75, 175)
end for
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
glitchy_gal12
|
Posted: Sun May 28, 2006 4:42 pm Post subject: (No subject) |
|
|
Cervantes wrote: code: |
for i : 1 .. 3
outcome (Rand.Int (1, 4)) (100 * i, 100, 100 * i + 75, 175)
end for
|
Would that code cause the shapes to overlap each other? I tried testing it onto Turing, and the shapes ended up overlapping. Is it possible for the three seperate outcomes to be in spaced out positions so that the different outcomes can be viewed more easily? By the way, thanks a million for helping me. |
|
|
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 5:02 pm Post subject: (No subject) |
|
|
They're overlapping because you hardcoded the values into the box, star, oval, and mapleleaf procedures. Use the parameters.
Cervantes wrote:
code: | procedure box (x1, y1, x2, y2 : int)
Draw.FillBox (x1, y1, x2, y2, black)
end box |
|
|
|
|
|
|
glitchy_gal12
|
Posted: Sun May 28, 2006 5:12 pm Post subject: (No subject) |
|
|
Cervantes wrote: They're overlapping because you hardcoded the values into the box, star, oval, and mapleleaf procedures. Use the parameters.
Cervantes wrote:
code: | procedure box (x1, y1, x2, y2 : int)
Draw.FillBox (x1, y1, x2, y2, black)
end box |
Oh ok. I get it now. Once again. thanks so much for your time! Really appreciate it. |
|
|
|
|
|
Cervantes
|
Posted: Sun May 28, 2006 6:16 pm Post subject: (No subject) |
|
|
glitchy_gal12 wrote: Once again. thanks so much for your time! Really appreciate it.
It was my pleasure. |
|
|
|
|
|
|
|