Pygame, my circle turns to a rect after I stored it in a variable, how do I prevent that from happening

Multi tool use
Multi tool use












0















I need to store a Circle in a variable but after I've done that it has turned into a rect



circle_1 = pygame.draw.circle(screen, (0, 0, 0), (300, 300), 30)
Print(circle_1)


the print returns



<rect(270, 270, 60, 60)>


but I can't work with that.
My circle is predefined but it won't show it on the canvas, here is an example of the problem



> import pygame, sys
>
>
> pygame.init() screen = pygame.display.set_mode((600, 600))
> predefined_circle = pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30)
>
> def update():
> screen.fill((200, 0, 0))
> while 1:
> for event in pygame.event.get():
> if event.type == pygame.QUIT: sys.exit()
> # It shows my circle if I dirctly tip pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30) into it
> predefined_circle
> pygame.display.update()
>
> update()


So that you can better relate to what I'm trying to achieve here is the code of what I'm doing but it is not necessary to read as I've already tried to explain it as best as I can above.
Please note the comments should explain everything that the block of code below it is doing.



# Creating the canvas which can paint any wanted Object from another class
class Canvas:
# Initialising the screen and setting all needed variables
def __init__(self, painting):
pygame.init()
self.screen_size = (600, 600)
self.background = (25, 255, 255)
self.screen = pygame.display.set_mode(self.screen_size)
self.paint = painting

# Let the user set the name of the canvas
def set_screen_name(self):
return self.screen

# Draw the everything you want to
def update(self):
# Paint the canvas
self.screen.fill(self.background)
# Make the game be quittable
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()

# Draw the defined Circle and then update the Canvas
# it only draws a circle if directly tip pygame.draw.circle(surface, color, position, radius)

self.paint
pygame.display.update()


# Draw any circle you like
class Cir:
# Get all the required Information's to Draw a circle
def __init__(self, canvas, what_color, position, radius, line=0):
self.can = canvas
self.color = what_color
self.pos = position
self.r = radius
self.line = line
self.cir = None

# Create the circle with the acquired Information's
def create(self):
self.cir = pygame.draw.circle(self.can, self.color, self.pos, self.r, self.line)
return self.cir


# So far there is no Surface for the Cir class
# And there is no Object that cloud be painted for the Canvas class
# I initialise a canvas instance without anything that needs to be painted
get_surface = Canvas(None)

# Now I can access set_screen_name from the Canvas class and give the surface a name
# Which the Cir class can now use as a surface
screen = get_surface.set_screen_name()

c1 = pygame.draw.circle(screen, (0,0,0), (300, 300), 30)
print(c1)

# I'm initialising a circle
init_circle = Cir(screen, (0, 255, 0), (300, 300), 30)

# Create the initialised circle
circle_1 = init_circle.create()

# Give the Canvas class the created circle
paint = Canvas(circle_1)

# Draw the circle
paint.update()









share|improve this question



























    0















    I need to store a Circle in a variable but after I've done that it has turned into a rect



    circle_1 = pygame.draw.circle(screen, (0, 0, 0), (300, 300), 30)
    Print(circle_1)


    the print returns



    <rect(270, 270, 60, 60)>


    but I can't work with that.
    My circle is predefined but it won't show it on the canvas, here is an example of the problem



    > import pygame, sys
    >
    >
    > pygame.init() screen = pygame.display.set_mode((600, 600))
    > predefined_circle = pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30)
    >
    > def update():
    > screen.fill((200, 0, 0))
    > while 1:
    > for event in pygame.event.get():
    > if event.type == pygame.QUIT: sys.exit()
    > # It shows my circle if I dirctly tip pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30) into it
    > predefined_circle
    > pygame.display.update()
    >
    > update()


    So that you can better relate to what I'm trying to achieve here is the code of what I'm doing but it is not necessary to read as I've already tried to explain it as best as I can above.
    Please note the comments should explain everything that the block of code below it is doing.



    # Creating the canvas which can paint any wanted Object from another class
    class Canvas:
    # Initialising the screen and setting all needed variables
    def __init__(self, painting):
    pygame.init()
    self.screen_size = (600, 600)
    self.background = (25, 255, 255)
    self.screen = pygame.display.set_mode(self.screen_size)
    self.paint = painting

    # Let the user set the name of the canvas
    def set_screen_name(self):
    return self.screen

    # Draw the everything you want to
    def update(self):
    # Paint the canvas
    self.screen.fill(self.background)
    # Make the game be quittable
    while 1:
    for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()

    # Draw the defined Circle and then update the Canvas
    # it only draws a circle if directly tip pygame.draw.circle(surface, color, position, radius)

    self.paint
    pygame.display.update()


    # Draw any circle you like
    class Cir:
    # Get all the required Information's to Draw a circle
    def __init__(self, canvas, what_color, position, radius, line=0):
    self.can = canvas
    self.color = what_color
    self.pos = position
    self.r = radius
    self.line = line
    self.cir = None

    # Create the circle with the acquired Information's
    def create(self):
    self.cir = pygame.draw.circle(self.can, self.color, self.pos, self.r, self.line)
    return self.cir


    # So far there is no Surface for the Cir class
    # And there is no Object that cloud be painted for the Canvas class
    # I initialise a canvas instance without anything that needs to be painted
    get_surface = Canvas(None)

    # Now I can access set_screen_name from the Canvas class and give the surface a name
    # Which the Cir class can now use as a surface
    screen = get_surface.set_screen_name()

    c1 = pygame.draw.circle(screen, (0,0,0), (300, 300), 30)
    print(c1)

    # I'm initialising a circle
    init_circle = Cir(screen, (0, 255, 0), (300, 300), 30)

    # Create the initialised circle
    circle_1 = init_circle.create()

    # Give the Canvas class the created circle
    paint = Canvas(circle_1)

    # Draw the circle
    paint.update()









    share|improve this question

























      0












      0








      0








      I need to store a Circle in a variable but after I've done that it has turned into a rect



      circle_1 = pygame.draw.circle(screen, (0, 0, 0), (300, 300), 30)
      Print(circle_1)


      the print returns



      <rect(270, 270, 60, 60)>


      but I can't work with that.
      My circle is predefined but it won't show it on the canvas, here is an example of the problem



      > import pygame, sys
      >
      >
      > pygame.init() screen = pygame.display.set_mode((600, 600))
      > predefined_circle = pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30)
      >
      > def update():
      > screen.fill((200, 0, 0))
      > while 1:
      > for event in pygame.event.get():
      > if event.type == pygame.QUIT: sys.exit()
      > # It shows my circle if I dirctly tip pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30) into it
      > predefined_circle
      > pygame.display.update()
      >
      > update()


      So that you can better relate to what I'm trying to achieve here is the code of what I'm doing but it is not necessary to read as I've already tried to explain it as best as I can above.
      Please note the comments should explain everything that the block of code below it is doing.



      # Creating the canvas which can paint any wanted Object from another class
      class Canvas:
      # Initialising the screen and setting all needed variables
      def __init__(self, painting):
      pygame.init()
      self.screen_size = (600, 600)
      self.background = (25, 255, 255)
      self.screen = pygame.display.set_mode(self.screen_size)
      self.paint = painting

      # Let the user set the name of the canvas
      def set_screen_name(self):
      return self.screen

      # Draw the everything you want to
      def update(self):
      # Paint the canvas
      self.screen.fill(self.background)
      # Make the game be quittable
      while 1:
      for event in pygame.event.get():
      if event.type == pygame.QUIT: sys.exit()

      # Draw the defined Circle and then update the Canvas
      # it only draws a circle if directly tip pygame.draw.circle(surface, color, position, radius)

      self.paint
      pygame.display.update()


      # Draw any circle you like
      class Cir:
      # Get all the required Information's to Draw a circle
      def __init__(self, canvas, what_color, position, radius, line=0):
      self.can = canvas
      self.color = what_color
      self.pos = position
      self.r = radius
      self.line = line
      self.cir = None

      # Create the circle with the acquired Information's
      def create(self):
      self.cir = pygame.draw.circle(self.can, self.color, self.pos, self.r, self.line)
      return self.cir


      # So far there is no Surface for the Cir class
      # And there is no Object that cloud be painted for the Canvas class
      # I initialise a canvas instance without anything that needs to be painted
      get_surface = Canvas(None)

      # Now I can access set_screen_name from the Canvas class and give the surface a name
      # Which the Cir class can now use as a surface
      screen = get_surface.set_screen_name()

      c1 = pygame.draw.circle(screen, (0,0,0), (300, 300), 30)
      print(c1)

      # I'm initialising a circle
      init_circle = Cir(screen, (0, 255, 0), (300, 300), 30)

      # Create the initialised circle
      circle_1 = init_circle.create()

      # Give the Canvas class the created circle
      paint = Canvas(circle_1)

      # Draw the circle
      paint.update()









      share|improve this question














      I need to store a Circle in a variable but after I've done that it has turned into a rect



      circle_1 = pygame.draw.circle(screen, (0, 0, 0), (300, 300), 30)
      Print(circle_1)


      the print returns



      <rect(270, 270, 60, 60)>


      but I can't work with that.
      My circle is predefined but it won't show it on the canvas, here is an example of the problem



      > import pygame, sys
      >
      >
      > pygame.init() screen = pygame.display.set_mode((600, 600))
      > predefined_circle = pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30)
      >
      > def update():
      > screen.fill((200, 0, 0))
      > while 1:
      > for event in pygame.event.get():
      > if event.type == pygame.QUIT: sys.exit()
      > # It shows my circle if I dirctly tip pygame.draw.circle(screen,(0, 0, 0),(300, 300), 30) into it
      > predefined_circle
      > pygame.display.update()
      >
      > update()


      So that you can better relate to what I'm trying to achieve here is the code of what I'm doing but it is not necessary to read as I've already tried to explain it as best as I can above.
      Please note the comments should explain everything that the block of code below it is doing.



      # Creating the canvas which can paint any wanted Object from another class
      class Canvas:
      # Initialising the screen and setting all needed variables
      def __init__(self, painting):
      pygame.init()
      self.screen_size = (600, 600)
      self.background = (25, 255, 255)
      self.screen = pygame.display.set_mode(self.screen_size)
      self.paint = painting

      # Let the user set the name of the canvas
      def set_screen_name(self):
      return self.screen

      # Draw the everything you want to
      def update(self):
      # Paint the canvas
      self.screen.fill(self.background)
      # Make the game be quittable
      while 1:
      for event in pygame.event.get():
      if event.type == pygame.QUIT: sys.exit()

      # Draw the defined Circle and then update the Canvas
      # it only draws a circle if directly tip pygame.draw.circle(surface, color, position, radius)

      self.paint
      pygame.display.update()


      # Draw any circle you like
      class Cir:
      # Get all the required Information's to Draw a circle
      def __init__(self, canvas, what_color, position, radius, line=0):
      self.can = canvas
      self.color = what_color
      self.pos = position
      self.r = radius
      self.line = line
      self.cir = None

      # Create the circle with the acquired Information's
      def create(self):
      self.cir = pygame.draw.circle(self.can, self.color, self.pos, self.r, self.line)
      return self.cir


      # So far there is no Surface for the Cir class
      # And there is no Object that cloud be painted for the Canvas class
      # I initialise a canvas instance without anything that needs to be painted
      get_surface = Canvas(None)

      # Now I can access set_screen_name from the Canvas class and give the surface a name
      # Which the Cir class can now use as a surface
      screen = get_surface.set_screen_name()

      c1 = pygame.draw.circle(screen, (0,0,0), (300, 300), 30)
      print(c1)

      # I'm initialising a circle
      init_circle = Cir(screen, (0, 255, 0), (300, 300), 30)

      # Create the initialised circle
      circle_1 = init_circle.create()

      # Give the Canvas class the created circle
      paint = Canvas(circle_1)

      # Draw the circle
      paint.update()






      pygame data-conversion






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 30 '18 at 23:34









      LipipiLipipi

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          1















          My circle turns to a rect.




          Actually, no, it doesn't. As per the documentation for those drawing functions, the intent of the calls is to draw something immediately, not to give you an object you can draw later:




          Draw several simple shapes to a Surface.




          From analysis of your question, it sounds like you believe that you are storing the act of drawing the circle so that it can be done later. That is not the case. Instead, what you are doing is actually drawing the circle and saving the result of that drawing action - evaluating the result later on will not actually draw, or redraw, the circle.



          So, if the draw function is not returning something for later drawing, what is it returning? That can also be found in the above-mentioned documentation:




          The functions return a rectangle representing the bounding area of changed pixels.




          In other words, it's telling you the smallest rectangle that was changed by the drawing action - this will be a square with sides the same length as the diameter and centered around the same point.



          Obviously, the authors of PyGame thought this information may be handy for some purpose, just not the purpose of redrawing the circle :-)





          One way to do what you're trying to achieve would be to simply have a function to draw the "predefined" circle and call that instead of trying to evaluate the rectangle returned from a previous call.






          share|improve this answer


























          • this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

            – sloth
            Jan 2 at 9:46











          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%2f53982294%2fpygame-my-circle-turns-to-a-rect-after-i-stored-it-in-a-variable-how-do-i-prev%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















          My circle turns to a rect.




          Actually, no, it doesn't. As per the documentation for those drawing functions, the intent of the calls is to draw something immediately, not to give you an object you can draw later:




          Draw several simple shapes to a Surface.




          From analysis of your question, it sounds like you believe that you are storing the act of drawing the circle so that it can be done later. That is not the case. Instead, what you are doing is actually drawing the circle and saving the result of that drawing action - evaluating the result later on will not actually draw, or redraw, the circle.



          So, if the draw function is not returning something for later drawing, what is it returning? That can also be found in the above-mentioned documentation:




          The functions return a rectangle representing the bounding area of changed pixels.




          In other words, it's telling you the smallest rectangle that was changed by the drawing action - this will be a square with sides the same length as the diameter and centered around the same point.



          Obviously, the authors of PyGame thought this information may be handy for some purpose, just not the purpose of redrawing the circle :-)





          One way to do what you're trying to achieve would be to simply have a function to draw the "predefined" circle and call that instead of trying to evaluate the rectangle returned from a previous call.






          share|improve this answer


























          • this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

            – sloth
            Jan 2 at 9:46
















          1















          My circle turns to a rect.




          Actually, no, it doesn't. As per the documentation for those drawing functions, the intent of the calls is to draw something immediately, not to give you an object you can draw later:




          Draw several simple shapes to a Surface.




          From analysis of your question, it sounds like you believe that you are storing the act of drawing the circle so that it can be done later. That is not the case. Instead, what you are doing is actually drawing the circle and saving the result of that drawing action - evaluating the result later on will not actually draw, or redraw, the circle.



          So, if the draw function is not returning something for later drawing, what is it returning? That can also be found in the above-mentioned documentation:




          The functions return a rectangle representing the bounding area of changed pixels.




          In other words, it's telling you the smallest rectangle that was changed by the drawing action - this will be a square with sides the same length as the diameter and centered around the same point.



          Obviously, the authors of PyGame thought this information may be handy for some purpose, just not the purpose of redrawing the circle :-)





          One way to do what you're trying to achieve would be to simply have a function to draw the "predefined" circle and call that instead of trying to evaluate the rectangle returned from a previous call.






          share|improve this answer


























          • this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

            – sloth
            Jan 2 at 9:46














          1












          1








          1








          My circle turns to a rect.




          Actually, no, it doesn't. As per the documentation for those drawing functions, the intent of the calls is to draw something immediately, not to give you an object you can draw later:




          Draw several simple shapes to a Surface.




          From analysis of your question, it sounds like you believe that you are storing the act of drawing the circle so that it can be done later. That is not the case. Instead, what you are doing is actually drawing the circle and saving the result of that drawing action - evaluating the result later on will not actually draw, or redraw, the circle.



          So, if the draw function is not returning something for later drawing, what is it returning? That can also be found in the above-mentioned documentation:




          The functions return a rectangle representing the bounding area of changed pixels.




          In other words, it's telling you the smallest rectangle that was changed by the drawing action - this will be a square with sides the same length as the diameter and centered around the same point.



          Obviously, the authors of PyGame thought this information may be handy for some purpose, just not the purpose of redrawing the circle :-)





          One way to do what you're trying to achieve would be to simply have a function to draw the "predefined" circle and call that instead of trying to evaluate the rectangle returned from a previous call.






          share|improve this answer
















          My circle turns to a rect.




          Actually, no, it doesn't. As per the documentation for those drawing functions, the intent of the calls is to draw something immediately, not to give you an object you can draw later:




          Draw several simple shapes to a Surface.




          From analysis of your question, it sounds like you believe that you are storing the act of drawing the circle so that it can be done later. That is not the case. Instead, what you are doing is actually drawing the circle and saving the result of that drawing action - evaluating the result later on will not actually draw, or redraw, the circle.



          So, if the draw function is not returning something for later drawing, what is it returning? That can also be found in the above-mentioned documentation:




          The functions return a rectangle representing the bounding area of changed pixels.




          In other words, it's telling you the smallest rectangle that was changed by the drawing action - this will be a square with sides the same length as the diameter and centered around the same point.



          Obviously, the authors of PyGame thought this information may be handy for some purpose, just not the purpose of redrawing the circle :-)





          One way to do what you're trying to achieve would be to simply have a function to draw the "predefined" circle and call that instead of trying to evaluate the rectangle returned from a previous call.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 7:36

























          answered Dec 30 '18 at 23:39









          paxdiablopaxdiablo

          633k17012471670




          633k17012471670













          • this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

            – sloth
            Jan 2 at 9:46



















          • this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

            – sloth
            Jan 2 at 9:46

















          this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

          – sloth
          Jan 2 at 9:46





          this information may be handy for some purpose The purpose is to know which part of the screen was actually changed in a frame so you can update the screen more efficiently by not having to update the entire screen.

          – sloth
          Jan 2 at 9:46


















          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%2f53982294%2fpygame-my-circle-turns-to-a-rect-after-i-stored-it-in-a-variable-how-do-i-prev%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







          1ezDMI6Yl3,qACKvrc0dzrPbD1Y,rIB1Bgi0Bo5dbm3k,2IRLI z1,Vhoquk,BGZECA p3 5lQvN7EMvnGdH9zXZY
          8utGcVRRfkd,C2HfNxrcHQDT4HkzAWLj7O Kn

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas