Assigning specific colors to circles surrounding one random circle
up vote
-1
down vote
favorite
I am coding for a project which requires me to draw a grid of 15x15 black circles. The program will then randomly choose a circle to fill "gold." The circles surrounding the "gold" circle, are to be "tan," the circles surrounding "tan," should be "grey," and all other circles are "white." The colors are revealed when a mouse click is detected over the circle. I was able to draw the black circles, but am having difficulty with randomizing the "gold" circle and filling in the rest of the colors.
def circle_grid(game):
# Create a list that creates 15x15 grid of black filled circles
Center = Point(30,70)
# append to a list
Y = [ ]
for y in range (15):
for x in range (15):
CIRCLES = Circle(Center, 15)
CIRCLES.setFill("black")
Center = Point ((Center.getX()+30), (Center.getY()))
CIRCLES.draw(game)
Y.append(CIRCLES)
Center = Point(30, Center.getY()+30)
This is the specific description and image of what is supposed to happen:
python
add a comment |
up vote
-1
down vote
favorite
I am coding for a project which requires me to draw a grid of 15x15 black circles. The program will then randomly choose a circle to fill "gold." The circles surrounding the "gold" circle, are to be "tan," the circles surrounding "tan," should be "grey," and all other circles are "white." The colors are revealed when a mouse click is detected over the circle. I was able to draw the black circles, but am having difficulty with randomizing the "gold" circle and filling in the rest of the colors.
def circle_grid(game):
# Create a list that creates 15x15 grid of black filled circles
Center = Point(30,70)
# append to a list
Y = [ ]
for y in range (15):
for x in range (15):
CIRCLES = Circle(Center, 15)
CIRCLES.setFill("black")
Center = Point ((Center.getX()+30), (Center.getY()))
CIRCLES.draw(game)
Y.append(CIRCLES)
Center = Point(30, Center.getY()+30)
This is the specific description and image of what is supposed to happen:
python
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
What graphics library are you using?
– martineau
Nov 9 at 20:19
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am coding for a project which requires me to draw a grid of 15x15 black circles. The program will then randomly choose a circle to fill "gold." The circles surrounding the "gold" circle, are to be "tan," the circles surrounding "tan," should be "grey," and all other circles are "white." The colors are revealed when a mouse click is detected over the circle. I was able to draw the black circles, but am having difficulty with randomizing the "gold" circle and filling in the rest of the colors.
def circle_grid(game):
# Create a list that creates 15x15 grid of black filled circles
Center = Point(30,70)
# append to a list
Y = [ ]
for y in range (15):
for x in range (15):
CIRCLES = Circle(Center, 15)
CIRCLES.setFill("black")
Center = Point ((Center.getX()+30), (Center.getY()))
CIRCLES.draw(game)
Y.append(CIRCLES)
Center = Point(30, Center.getY()+30)
This is the specific description and image of what is supposed to happen:
python
I am coding for a project which requires me to draw a grid of 15x15 black circles. The program will then randomly choose a circle to fill "gold." The circles surrounding the "gold" circle, are to be "tan," the circles surrounding "tan," should be "grey," and all other circles are "white." The colors are revealed when a mouse click is detected over the circle. I was able to draw the black circles, but am having difficulty with randomizing the "gold" circle and filling in the rest of the colors.
def circle_grid(game):
# Create a list that creates 15x15 grid of black filled circles
Center = Point(30,70)
# append to a list
Y = [ ]
for y in range (15):
for x in range (15):
CIRCLES = Circle(Center, 15)
CIRCLES.setFill("black")
Center = Point ((Center.getX()+30), (Center.getY()))
CIRCLES.draw(game)
Y.append(CIRCLES)
Center = Point(30, Center.getY()+30)
This is the specific description and image of what is supposed to happen:
python
python
edited Nov 9 at 20:11
martineau
65.3k988177
65.3k988177
asked Nov 9 at 19:46
Jennifer
31
31
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
What graphics library are you using?
– martineau
Nov 9 at 20:19
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34
add a comment |
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
What graphics library are you using?
– martineau
Nov 9 at 20:19
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
What graphics library are you using?
– martineau
Nov 9 at 20:19
What graphics library are you using?
– martineau
Nov 9 at 20:19
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
I would suggest making the grid two-dimensional—a list-of-lists—so that the Circle
s in it can be referenced by the row and column they are in. Here's what I mean:
def circle_grid(game):
grid_width, grid_height = 15, 15
radius = 15 # of each Circle in grid
diameter = radius*2
x, y = radius, radius # Center of upper-left-most Circle of grid
grid =
for i in range(grid_width):
row =
for j in range(grid_height):
row.append(Circle(x+(i*diameter), y+(j*diameter), radius, 'black'))
grid.append(row)
return grid
grid = circle_grid(None)
# Print grid of Circles created.
for row in range(len(grid)):
line =
for col in range(len(grid[0])):
line.append(str(grid[row][col]))
print(', '.join(line))
Doing this will make it relatively easy to access them via grid[row][col]
, so after deciding on the position of the gold one, changing the color of groups of them around it would become a matter of, adding or subtracting values from the row, col of the gold one.
For example, say you want the put the gold one at a random position on the grid
:
row_gold, col_gold = random.randrange(grid_width), random.randrange(grid_width)
grid[row_gold][col_gold].setFill('gold')
Afterwards, the eight tan Circle
s immediately around it can be accessed relative to its position like this:
grid[row_gold-1][col_gold-1].setFill('tan')
grid[row_gold-1][col_gold].setFill('tan')
grid[row_gold-1][col_gold+1].setFill('tan')
grid[row_gold][col_gold-1].setFill('tan')
# grid[row_gold][col_gold] # don't change the gold one itself
grid[row_gold][col_gold+1].setFill('tan')
grid[row_gold+1][col_gold-1].setFill('tan')
grid[row_gold+1][col_gold].setFill('tan')
grid[row_gold+1][col_gold+1].setFill('tan')
and the indices of all the grey ones could also be calculated relative to it in a similar manner (i.e. based on the values of row_gold
and col_gold
).
add a comment |
up vote
0
down vote
You should be able to find basic documentation to give you random x
and y
values for the gold circle.
Now, what defines "adjacent" in a square lattice? The tan layer is all the circles that have x
and/or y
differing by 1 from the gold's position. Gray circles have to have one coordinate (or both) that differs by exactly 2.
That's the algorithm. Can you take it from there?
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: usecol
for the variable name: that will align nicely withrow
, and your code will be easier to copy-paste and read.
– Prune
Nov 9 at 20:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232373%2fassigning-specific-colors-to-circles-surrounding-one-random-circle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I would suggest making the grid two-dimensional—a list-of-lists—so that the Circle
s in it can be referenced by the row and column they are in. Here's what I mean:
def circle_grid(game):
grid_width, grid_height = 15, 15
radius = 15 # of each Circle in grid
diameter = radius*2
x, y = radius, radius # Center of upper-left-most Circle of grid
grid =
for i in range(grid_width):
row =
for j in range(grid_height):
row.append(Circle(x+(i*diameter), y+(j*diameter), radius, 'black'))
grid.append(row)
return grid
grid = circle_grid(None)
# Print grid of Circles created.
for row in range(len(grid)):
line =
for col in range(len(grid[0])):
line.append(str(grid[row][col]))
print(', '.join(line))
Doing this will make it relatively easy to access them via grid[row][col]
, so after deciding on the position of the gold one, changing the color of groups of them around it would become a matter of, adding or subtracting values from the row, col of the gold one.
For example, say you want the put the gold one at a random position on the grid
:
row_gold, col_gold = random.randrange(grid_width), random.randrange(grid_width)
grid[row_gold][col_gold].setFill('gold')
Afterwards, the eight tan Circle
s immediately around it can be accessed relative to its position like this:
grid[row_gold-1][col_gold-1].setFill('tan')
grid[row_gold-1][col_gold].setFill('tan')
grid[row_gold-1][col_gold+1].setFill('tan')
grid[row_gold][col_gold-1].setFill('tan')
# grid[row_gold][col_gold] # don't change the gold one itself
grid[row_gold][col_gold+1].setFill('tan')
grid[row_gold+1][col_gold-1].setFill('tan')
grid[row_gold+1][col_gold].setFill('tan')
grid[row_gold+1][col_gold+1].setFill('tan')
and the indices of all the grey ones could also be calculated relative to it in a similar manner (i.e. based on the values of row_gold
and col_gold
).
add a comment |
up vote
0
down vote
accepted
I would suggest making the grid two-dimensional—a list-of-lists—so that the Circle
s in it can be referenced by the row and column they are in. Here's what I mean:
def circle_grid(game):
grid_width, grid_height = 15, 15
radius = 15 # of each Circle in grid
diameter = radius*2
x, y = radius, radius # Center of upper-left-most Circle of grid
grid =
for i in range(grid_width):
row =
for j in range(grid_height):
row.append(Circle(x+(i*diameter), y+(j*diameter), radius, 'black'))
grid.append(row)
return grid
grid = circle_grid(None)
# Print grid of Circles created.
for row in range(len(grid)):
line =
for col in range(len(grid[0])):
line.append(str(grid[row][col]))
print(', '.join(line))
Doing this will make it relatively easy to access them via grid[row][col]
, so after deciding on the position of the gold one, changing the color of groups of them around it would become a matter of, adding or subtracting values from the row, col of the gold one.
For example, say you want the put the gold one at a random position on the grid
:
row_gold, col_gold = random.randrange(grid_width), random.randrange(grid_width)
grid[row_gold][col_gold].setFill('gold')
Afterwards, the eight tan Circle
s immediately around it can be accessed relative to its position like this:
grid[row_gold-1][col_gold-1].setFill('tan')
grid[row_gold-1][col_gold].setFill('tan')
grid[row_gold-1][col_gold+1].setFill('tan')
grid[row_gold][col_gold-1].setFill('tan')
# grid[row_gold][col_gold] # don't change the gold one itself
grid[row_gold][col_gold+1].setFill('tan')
grid[row_gold+1][col_gold-1].setFill('tan')
grid[row_gold+1][col_gold].setFill('tan')
grid[row_gold+1][col_gold+1].setFill('tan')
and the indices of all the grey ones could also be calculated relative to it in a similar manner (i.e. based on the values of row_gold
and col_gold
).
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I would suggest making the grid two-dimensional—a list-of-lists—so that the Circle
s in it can be referenced by the row and column they are in. Here's what I mean:
def circle_grid(game):
grid_width, grid_height = 15, 15
radius = 15 # of each Circle in grid
diameter = radius*2
x, y = radius, radius # Center of upper-left-most Circle of grid
grid =
for i in range(grid_width):
row =
for j in range(grid_height):
row.append(Circle(x+(i*diameter), y+(j*diameter), radius, 'black'))
grid.append(row)
return grid
grid = circle_grid(None)
# Print grid of Circles created.
for row in range(len(grid)):
line =
for col in range(len(grid[0])):
line.append(str(grid[row][col]))
print(', '.join(line))
Doing this will make it relatively easy to access them via grid[row][col]
, so after deciding on the position of the gold one, changing the color of groups of them around it would become a matter of, adding or subtracting values from the row, col of the gold one.
For example, say you want the put the gold one at a random position on the grid
:
row_gold, col_gold = random.randrange(grid_width), random.randrange(grid_width)
grid[row_gold][col_gold].setFill('gold')
Afterwards, the eight tan Circle
s immediately around it can be accessed relative to its position like this:
grid[row_gold-1][col_gold-1].setFill('tan')
grid[row_gold-1][col_gold].setFill('tan')
grid[row_gold-1][col_gold+1].setFill('tan')
grid[row_gold][col_gold-1].setFill('tan')
# grid[row_gold][col_gold] # don't change the gold one itself
grid[row_gold][col_gold+1].setFill('tan')
grid[row_gold+1][col_gold-1].setFill('tan')
grid[row_gold+1][col_gold].setFill('tan')
grid[row_gold+1][col_gold+1].setFill('tan')
and the indices of all the grey ones could also be calculated relative to it in a similar manner (i.e. based on the values of row_gold
and col_gold
).
I would suggest making the grid two-dimensional—a list-of-lists—so that the Circle
s in it can be referenced by the row and column they are in. Here's what I mean:
def circle_grid(game):
grid_width, grid_height = 15, 15
radius = 15 # of each Circle in grid
diameter = radius*2
x, y = radius, radius # Center of upper-left-most Circle of grid
grid =
for i in range(grid_width):
row =
for j in range(grid_height):
row.append(Circle(x+(i*diameter), y+(j*diameter), radius, 'black'))
grid.append(row)
return grid
grid = circle_grid(None)
# Print grid of Circles created.
for row in range(len(grid)):
line =
for col in range(len(grid[0])):
line.append(str(grid[row][col]))
print(', '.join(line))
Doing this will make it relatively easy to access them via grid[row][col]
, so after deciding on the position of the gold one, changing the color of groups of them around it would become a matter of, adding or subtracting values from the row, col of the gold one.
For example, say you want the put the gold one at a random position on the grid
:
row_gold, col_gold = random.randrange(grid_width), random.randrange(grid_width)
grid[row_gold][col_gold].setFill('gold')
Afterwards, the eight tan Circle
s immediately around it can be accessed relative to its position like this:
grid[row_gold-1][col_gold-1].setFill('tan')
grid[row_gold-1][col_gold].setFill('tan')
grid[row_gold-1][col_gold+1].setFill('tan')
grid[row_gold][col_gold-1].setFill('tan')
# grid[row_gold][col_gold] # don't change the gold one itself
grid[row_gold][col_gold+1].setFill('tan')
grid[row_gold+1][col_gold-1].setFill('tan')
grid[row_gold+1][col_gold].setFill('tan')
grid[row_gold+1][col_gold+1].setFill('tan')
and the indices of all the grey ones could also be calculated relative to it in a similar manner (i.e. based on the values of row_gold
and col_gold
).
edited Nov 10 at 1:10
answered Nov 9 at 22:04
martineau
65.3k988177
65.3k988177
add a comment |
add a comment |
up vote
0
down vote
You should be able to find basic documentation to give you random x
and y
values for the gold circle.
Now, what defines "adjacent" in a square lattice? The tan layer is all the circles that have x
and/or y
differing by 1 from the gold's position. Gray circles have to have one coordinate (or both) that differs by exactly 2.
That's the algorithm. Can you take it from there?
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: usecol
for the variable name: that will align nicely withrow
, and your code will be easier to copy-paste and read.
– Prune
Nov 9 at 20:10
add a comment |
up vote
0
down vote
You should be able to find basic documentation to give you random x
and y
values for the gold circle.
Now, what defines "adjacent" in a square lattice? The tan layer is all the circles that have x
and/or y
differing by 1 from the gold's position. Gray circles have to have one coordinate (or both) that differs by exactly 2.
That's the algorithm. Can you take it from there?
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: usecol
for the variable name: that will align nicely withrow
, and your code will be easier to copy-paste and read.
– Prune
Nov 9 at 20:10
add a comment |
up vote
0
down vote
up vote
0
down vote
You should be able to find basic documentation to give you random x
and y
values for the gold circle.
Now, what defines "adjacent" in a square lattice? The tan layer is all the circles that have x
and/or y
differing by 1 from the gold's position. Gray circles have to have one coordinate (or both) that differs by exactly 2.
That's the algorithm. Can you take it from there?
You should be able to find basic documentation to give you random x
and y
values for the gold circle.
Now, what defines "adjacent" in a square lattice? The tan layer is all the circles that have x
and/or y
differing by 1 from the gold's position. Gray circles have to have one coordinate (or both) that differs by exactly 2.
That's the algorithm. Can you take it from there?
answered Nov 9 at 20:04
Prune
42.3k143454
42.3k143454
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: usecol
for the variable name: that will align nicely withrow
, and your code will be easier to copy-paste and read.
– Prune
Nov 9 at 20:10
add a comment |
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: usecol
for the variable name: that will align nicely withrow
, and your code will be easier to copy-paste and read.
– Prune
Nov 9 at 20:10
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
So should I use column = randint(0,224) and row = randint(0,224) then use those values for gold circle?
– Jennifer
Nov 9 at 20:08
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
That's the right idea, but index with your 15x15 grid, not at the pixel level.
– Prune
Nov 9 at 20:10
Hint: use
col
for the variable name: that will align nicely with row
, and your code will be easier to copy-paste and read.– Prune
Nov 9 at 20:10
Hint: use
col
for the variable name: that will align nicely with row
, and your code will be easier to copy-paste and read.– Prune
Nov 9 at 20:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232373%2fassigning-specific-colors-to-circles-surrounding-one-random-circle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"Can Someone Help Me?" is not a valid SO question. This usually suggests that what you need is time with a local tutor or walk through a tutorial, rather than Stack Overflow.
– Prune
Nov 9 at 20:01
What graphics library are you using?
– martineau
Nov 9 at 20:19
Can the list created be a list-of-lists? If so, it would make doing many things easier.
– martineau
Nov 9 at 20:23
yes, it can be a list of lists
– Jennifer
Nov 9 at 20:34