How to make a circle follow the mouse pointer?












-2















I am trying to make 2D shooter with Python tkinter.

Here are my progress:



from tkinter import *

root = Tk()

c = Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1x = 250
circle1y = 250
circle2x = 250
circle2y = 250

circle1 = c.create_oval(circle1x, circle1y, circle1x + 10, circle1y + 10, outline='white')
circle2 = c.create_rectangle(circle2x, circle2y,circle2x + 10, circle2y + 10)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250 - pos1[0], 250 - pos1[2])
c.move(circle2, 250 - pos1[0], 250 - pos1[2])

beginWall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circle(event):
pass

c.bind('<Motion>', move_circle)

root.mainloop()


But I am trying to make the function called move_circle make circle1 and circle2 follow the mouse pointer . Something like this c.goto(circle1, x, y).










share|improve this question




















  • 2





    Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

    – Flamma
    Dec 25 '18 at 9:36











  • Ok thx I will try it

    – Harry Kruger
    Dec 25 '18 at 9:55
















-2















I am trying to make 2D shooter with Python tkinter.

Here are my progress:



from tkinter import *

root = Tk()

c = Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1x = 250
circle1y = 250
circle2x = 250
circle2y = 250

circle1 = c.create_oval(circle1x, circle1y, circle1x + 10, circle1y + 10, outline='white')
circle2 = c.create_rectangle(circle2x, circle2y,circle2x + 10, circle2y + 10)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250 - pos1[0], 250 - pos1[2])
c.move(circle2, 250 - pos1[0], 250 - pos1[2])

beginWall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circle(event):
pass

c.bind('<Motion>', move_circle)

root.mainloop()


But I am trying to make the function called move_circle make circle1 and circle2 follow the mouse pointer . Something like this c.goto(circle1, x, y).










share|improve this question




















  • 2





    Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

    – Flamma
    Dec 25 '18 at 9:36











  • Ok thx I will try it

    – Harry Kruger
    Dec 25 '18 at 9:55














-2












-2








-2








I am trying to make 2D shooter with Python tkinter.

Here are my progress:



from tkinter import *

root = Tk()

c = Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1x = 250
circle1y = 250
circle2x = 250
circle2y = 250

circle1 = c.create_oval(circle1x, circle1y, circle1x + 10, circle1y + 10, outline='white')
circle2 = c.create_rectangle(circle2x, circle2y,circle2x + 10, circle2y + 10)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250 - pos1[0], 250 - pos1[2])
c.move(circle2, 250 - pos1[0], 250 - pos1[2])

beginWall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circle(event):
pass

c.bind('<Motion>', move_circle)

root.mainloop()


But I am trying to make the function called move_circle make circle1 and circle2 follow the mouse pointer . Something like this c.goto(circle1, x, y).










share|improve this question
















I am trying to make 2D shooter with Python tkinter.

Here are my progress:



from tkinter import *

root = Tk()

c = Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1x = 250
circle1y = 250
circle2x = 250
circle2y = 250

circle1 = c.create_oval(circle1x, circle1y, circle1x + 10, circle1y + 10, outline='white')
circle2 = c.create_rectangle(circle2x, circle2y,circle2x + 10, circle2y + 10)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250 - pos1[0], 250 - pos1[2])
c.move(circle2, 250 - pos1[0], 250 - pos1[2])

beginWall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circle(event):
pass

c.bind('<Motion>', move_circle)

root.mainloop()


But I am trying to make the function called move_circle make circle1 and circle2 follow the mouse pointer . Something like this c.goto(circle1, x, y).







python tkinter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 25 '18 at 11:54









martineau

68.7k1090183




68.7k1090183










asked Dec 25 '18 at 9:31









Harry KrugerHarry Kruger

102




102








  • 2





    Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

    – Flamma
    Dec 25 '18 at 9:36











  • Ok thx I will try it

    – Harry Kruger
    Dec 25 '18 at 9:55














  • 2





    Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

    – Flamma
    Dec 25 '18 at 9:36











  • Ok thx I will try it

    – Harry Kruger
    Dec 25 '18 at 9:55








2




2





Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

– Flamma
Dec 25 '18 at 9:36





Hi, Harry, welcome to Stack Overflow. I can't answer your question, but I can suggest you to use a better title for it. "I am trying to make a game" is not a question, and doesn't give the relevant information of what is your problem. How about renaming it to something like "How can I make a circle follow the mouse in tkinter?"?

– Flamma
Dec 25 '18 at 9:36













Ok thx I will try it

– Harry Kruger
Dec 25 '18 at 9:55





Ok thx I will try it

– Harry Kruger
Dec 25 '18 at 9:55












1 Answer
1






active

oldest

votes


















1














You can do it by modifying the coordinates of the two "circles" in the move_circle() event handler function. A simple calculation is done to make it so the centers of these two objects are positioned at the "tip" of the mouse pointer (see image below).



Note, I also modified your code to more closely follow the PEP 8 - Style Guide for Python Code coding guidelines.



import tkinter as tk

# Constants
CIRCLE1_X = 250
CIRCLE1_Y = 250
CIRCLE2_X = 250
CIRCLE2_Y = 250
SIZE = 10 # Height and width of the two "circle" Canvas objects.
EXTENT = SIZE // 2 # Their height and width as measured from center.

root = tk.Tk()

c = tk.Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1 = c.create_oval(CIRCLE1_X, CIRCLE1_Y,
CIRCLE1_X + SIZE, CIRCLE1_Y + SIZE,
outline='white')
circle2 = c.create_rectangle(CIRCLE2_X, CIRCLE2_Y,
CIRCLE2_X + SIZE, CIRCLE2_Y + SIZE)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250-pos1[0], 250-pos1[2])
c.move(circle2, 250-pos1[0], 250-pos1[2])

begin_wall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circles(event):
# Move two "circle" widgets so they're centered at event.x, event.y.
x0, y0 = event.x - EXTENT, event.y - EXTENT
x1, y1 = event.x + EXTENT, event.y + EXTENT
c.coords(circle1, x0, y0, x1, y1)
c.coords(circle2, x0, y0, x1, y1)

c.bind('<Motion>', move_circles)

root.mainloop()


Here's a screenshot of it running on my Windows computer:



screenshot of GUI app running






share|improve this answer


























  • when you halved it why did you type two //

    – Harry Kruger
    Dec 25 '18 at 13:02











  • what does the root.mainloop() do?

    – Harry Kruger
    Dec 25 '18 at 13:10











  • Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

    – martineau
    Dec 25 '18 at 19:01













  • Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

    – cdlane
    Dec 25 '18 at 20:53













  • @cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

    – martineau
    Dec 25 '18 at 21:27













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',
autoActivateHeartbeat: false,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53921071%2fhow-to-make-a-circle-follow-the-mouse-pointer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can do it by modifying the coordinates of the two "circles" in the move_circle() event handler function. A simple calculation is done to make it so the centers of these two objects are positioned at the "tip" of the mouse pointer (see image below).



Note, I also modified your code to more closely follow the PEP 8 - Style Guide for Python Code coding guidelines.



import tkinter as tk

# Constants
CIRCLE1_X = 250
CIRCLE1_Y = 250
CIRCLE2_X = 250
CIRCLE2_Y = 250
SIZE = 10 # Height and width of the two "circle" Canvas objects.
EXTENT = SIZE // 2 # Their height and width as measured from center.

root = tk.Tk()

c = tk.Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1 = c.create_oval(CIRCLE1_X, CIRCLE1_Y,
CIRCLE1_X + SIZE, CIRCLE1_Y + SIZE,
outline='white')
circle2 = c.create_rectangle(CIRCLE2_X, CIRCLE2_Y,
CIRCLE2_X + SIZE, CIRCLE2_Y + SIZE)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250-pos1[0], 250-pos1[2])
c.move(circle2, 250-pos1[0], 250-pos1[2])

begin_wall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circles(event):
# Move two "circle" widgets so they're centered at event.x, event.y.
x0, y0 = event.x - EXTENT, event.y - EXTENT
x1, y1 = event.x + EXTENT, event.y + EXTENT
c.coords(circle1, x0, y0, x1, y1)
c.coords(circle2, x0, y0, x1, y1)

c.bind('<Motion>', move_circles)

root.mainloop()


Here's a screenshot of it running on my Windows computer:



screenshot of GUI app running






share|improve this answer


























  • when you halved it why did you type two //

    – Harry Kruger
    Dec 25 '18 at 13:02











  • what does the root.mainloop() do?

    – Harry Kruger
    Dec 25 '18 at 13:10











  • Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

    – martineau
    Dec 25 '18 at 19:01













  • Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

    – cdlane
    Dec 25 '18 at 20:53













  • @cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

    – martineau
    Dec 25 '18 at 21:27


















1














You can do it by modifying the coordinates of the two "circles" in the move_circle() event handler function. A simple calculation is done to make it so the centers of these two objects are positioned at the "tip" of the mouse pointer (see image below).



Note, I also modified your code to more closely follow the PEP 8 - Style Guide for Python Code coding guidelines.



import tkinter as tk

# Constants
CIRCLE1_X = 250
CIRCLE1_Y = 250
CIRCLE2_X = 250
CIRCLE2_Y = 250
SIZE = 10 # Height and width of the two "circle" Canvas objects.
EXTENT = SIZE // 2 # Their height and width as measured from center.

root = tk.Tk()

c = tk.Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1 = c.create_oval(CIRCLE1_X, CIRCLE1_Y,
CIRCLE1_X + SIZE, CIRCLE1_Y + SIZE,
outline='white')
circle2 = c.create_rectangle(CIRCLE2_X, CIRCLE2_Y,
CIRCLE2_X + SIZE, CIRCLE2_Y + SIZE)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250-pos1[0], 250-pos1[2])
c.move(circle2, 250-pos1[0], 250-pos1[2])

begin_wall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circles(event):
# Move two "circle" widgets so they're centered at event.x, event.y.
x0, y0 = event.x - EXTENT, event.y - EXTENT
x1, y1 = event.x + EXTENT, event.y + EXTENT
c.coords(circle1, x0, y0, x1, y1)
c.coords(circle2, x0, y0, x1, y1)

c.bind('<Motion>', move_circles)

root.mainloop()


Here's a screenshot of it running on my Windows computer:



screenshot of GUI app running






share|improve this answer


























  • when you halved it why did you type two //

    – Harry Kruger
    Dec 25 '18 at 13:02











  • what does the root.mainloop() do?

    – Harry Kruger
    Dec 25 '18 at 13:10











  • Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

    – martineau
    Dec 25 '18 at 19:01













  • Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

    – cdlane
    Dec 25 '18 at 20:53













  • @cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

    – martineau
    Dec 25 '18 at 21:27
















1












1








1







You can do it by modifying the coordinates of the two "circles" in the move_circle() event handler function. A simple calculation is done to make it so the centers of these two objects are positioned at the "tip" of the mouse pointer (see image below).



Note, I also modified your code to more closely follow the PEP 8 - Style Guide for Python Code coding guidelines.



import tkinter as tk

# Constants
CIRCLE1_X = 250
CIRCLE1_Y = 250
CIRCLE2_X = 250
CIRCLE2_Y = 250
SIZE = 10 # Height and width of the two "circle" Canvas objects.
EXTENT = SIZE // 2 # Their height and width as measured from center.

root = tk.Tk()

c = tk.Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1 = c.create_oval(CIRCLE1_X, CIRCLE1_Y,
CIRCLE1_X + SIZE, CIRCLE1_Y + SIZE,
outline='white')
circle2 = c.create_rectangle(CIRCLE2_X, CIRCLE2_Y,
CIRCLE2_X + SIZE, CIRCLE2_Y + SIZE)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250-pos1[0], 250-pos1[2])
c.move(circle2, 250-pos1[0], 250-pos1[2])

begin_wall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circles(event):
# Move two "circle" widgets so they're centered at event.x, event.y.
x0, y0 = event.x - EXTENT, event.y - EXTENT
x1, y1 = event.x + EXTENT, event.y + EXTENT
c.coords(circle1, x0, y0, x1, y1)
c.coords(circle2, x0, y0, x1, y1)

c.bind('<Motion>', move_circles)

root.mainloop()


Here's a screenshot of it running on my Windows computer:



screenshot of GUI app running






share|improve this answer















You can do it by modifying the coordinates of the two "circles" in the move_circle() event handler function. A simple calculation is done to make it so the centers of these two objects are positioned at the "tip" of the mouse pointer (see image below).



Note, I also modified your code to more closely follow the PEP 8 - Style Guide for Python Code coding guidelines.



import tkinter as tk

# Constants
CIRCLE1_X = 250
CIRCLE1_Y = 250
CIRCLE2_X = 250
CIRCLE2_Y = 250
SIZE = 10 # Height and width of the two "circle" Canvas objects.
EXTENT = SIZE // 2 # Their height and width as measured from center.

root = tk.Tk()

c = tk.Canvas(root, height=500, width=500, bg='blue')
c.pack()

circle1 = c.create_oval(CIRCLE1_X, CIRCLE1_Y,
CIRCLE1_X + SIZE, CIRCLE1_Y + SIZE,
outline='white')
circle2 = c.create_rectangle(CIRCLE2_X, CIRCLE2_Y,
CIRCLE2_X + SIZE, CIRCLE2_Y + SIZE)

pos1 = c.coords(circle1)
pos2 = c.coords(circle2)

c.move(circle1, 250-pos1[0], 250-pos1[2])
c.move(circle2, 250-pos1[0], 250-pos1[2])

begin_wall = c.create_rectangle(0, 200, 500, 210, outline='white')

def move_circles(event):
# Move two "circle" widgets so they're centered at event.x, event.y.
x0, y0 = event.x - EXTENT, event.y - EXTENT
x1, y1 = event.x + EXTENT, event.y + EXTENT
c.coords(circle1, x0, y0, x1, y1)
c.coords(circle2, x0, y0, x1, y1)

c.bind('<Motion>', move_circles)

root.mainloop()


Here's a screenshot of it running on my Windows computer:



screenshot of GUI app running







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 8:17

























answered Dec 25 '18 at 11:48









martineaumartineau

68.7k1090183




68.7k1090183













  • when you halved it why did you type two //

    – Harry Kruger
    Dec 25 '18 at 13:02











  • what does the root.mainloop() do?

    – Harry Kruger
    Dec 25 '18 at 13:10











  • Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

    – martineau
    Dec 25 '18 at 19:01













  • Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

    – cdlane
    Dec 25 '18 at 20:53













  • @cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

    – martineau
    Dec 25 '18 at 21:27





















  • when you halved it why did you type two //

    – Harry Kruger
    Dec 25 '18 at 13:02











  • what does the root.mainloop() do?

    – Harry Kruger
    Dec 25 '18 at 13:10











  • Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

    – martineau
    Dec 25 '18 at 19:01













  • Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

    – cdlane
    Dec 25 '18 at 20:53













  • @cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

    – martineau
    Dec 25 '18 at 21:27



















when you halved it why did you type two //

– Harry Kruger
Dec 25 '18 at 13:02





when you halved it why did you type two //

– Harry Kruger
Dec 25 '18 at 13:02













what does the root.mainloop() do?

– Harry Kruger
Dec 25 '18 at 13:10





what does the root.mainloop() do?

– Harry Kruger
Dec 25 '18 at 13:10













Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

– martineau
Dec 25 '18 at 19:01







Harry: // is the floor division operator and is used so the result is an integer instead of floating-point value. mainloop() is a universal widget method that contains a loop that continually processes keyboard and mouse events from the user. All tkinter apps must call it at some point to give the GUI itself a chance to "run". Here's some documentation I found about it.

– martineau
Dec 25 '18 at 19:01















Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

– cdlane
Dec 25 '18 at 20:53







Careful, // does not guarantee "an integer instead of floating-point value". Conside range(SIZE // 2) It works if SIZE is 10 but throws an error if SIZE is 10.0 -- you may still need an int() wrapper depending on what you're doing. Perhaps it guarantees an integral value but not an integer one?

– cdlane
Dec 25 '18 at 20:53















@cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

– martineau
Dec 25 '18 at 21:27







@cdlane: While what you say is true, floor division of integers results in an integer rather than the floating-point value regular division would have produced—exactly what's intended in this usage case. In fact everything would still work in this case if SIZE had been set to 10.5 so I guess it's not that important of a point.

– martineau
Dec 25 '18 at 21:27






















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53921071%2fhow-to-make-a-circle-follow-the-mouse-pointer%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules