Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6955607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:45:32+00:00 2026-05-27T14:45:32+00:00

Say that you are in a constrained computing environment where the multiplication operation is

  • 0

Say that you are in a constrained computing environment where the multiplication operation is expensive or unavailable. You have access to a stream of pixels for an image of known dimensions. How would you draw a circle overlay onto the image?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:45:33+00:00Added an answer on May 27, 2026 at 2:45 pm

    Here is a Python script that demonstrates how you would draw a circle without using multiplication. It uses the formula x2 + y2 > r2 to check whether the current pixel position (x, y) is outside the circle.

    One can maintain a running computation of the squared values by using addition, since the rate of change of the difference between the squares of adjacent pixel indices is 2. As you iterate through pixels, you’ll keep adding a number (call that number z) to your running “squares” computations, and for each pixel, you will also add 2 to z.

    The __init__ function below does contain some multiplication operations. However, if the image dimensions are constant, the compiler will perform the multiplication and only load the result onto the device. If the image dimensions are not constant, a “slow” multiplication need only be performed once upon startup, as opposed to once per pixel.

    #!/usr/bin/env python
    
    class CircularMaskGenerator:
        '''Generates a circular "mask" for an image.
        Maintains a running computation of squared values to eliminate the need for multiplication'''
    
        def __init__(self, w, h):
            self.image_width = w
            self.image_height = h
    
            # Precompute some important values.
            # The embedded device doesn't actaully have to do this math; the
            # compiler does it before loading the code onto the device.
    
            self.half_image_width = self.image_width >> 1
            self.half_image_height = self.image_height >> 1
            self.radius = self.half_image_height
    
            self.squared_half_image_width = self.half_image_width*self.half_image_width
            self.squared_half_image_height = self.half_image_height*self.half_image_height
            self.squared_radius = self.radius*self.radius
    
            # The "deltas" are the difference between the squared values of adjacent pixel indices.
            self.initial_x_squared_delta = 1 - self.image_width
            self.initial_y_squared_delta = 1 - self.image_height
    
            self.resetFrame()
    
        def resetFrame(self):
    
            # Start with a white binary image
            import Image
            self.image = Image.new("1", (self.image_width, self.image_height), 1)
            self.pixels = self.image.load()
    
            # Reset indices
            self.resetColumnIndex()
            self.resetRowIndex()
    
        def processPixel(self):
    
            # Write a black pixel if we're outside the circle
            if self.current_x_squared + self.current_y_squared > self.squared_radius:
                self.pixels[(self.current_column_index, self.current_row_index)] = 0
    
            self.updateIndices()
    
        def updateIndices(self):
            '''Update the indices and squares values'''
    
            self.incrementColumnIndex()
    
            # Wrap to the next row if necessary
            if self.current_column_index == self.image_width:
                self.incrementRowIndex()
    
                # Wrap to the next frame if necessary
                if self.current_row_index == self.image_height:
                    self.writeImage()
                    self.resetFrame()
    
        def incrementColumnIndex(self):
            self.current_column_index += 1
            self.current_x_squared += self.current_x_squared_delta
            self.current_x_squared_delta += 2
    
        def resetColumnIndex(self):
            self.current_column_index = 0
            self.current_x_squared = self.squared_half_image_width
            self.current_x_squared_delta = self.initial_x_squared_delta
    
        def incrementRowIndex(self):
            '''The row increment has to send the column index back to the left.'''
    
            self.resetColumnIndex()
    
            self.current_row_index += 1
            self.current_y_squared += self.current_y_squared_delta
            self.current_y_squared_delta += 2
    
        def resetRowIndex(self):
            self.current_row_index = 0
            self.current_y_squared = self.squared_half_image_height
            self.current_y_squared_delta = self.initial_y_squared_delta
    
        def writeImage(self):
            '''Save the image in PNG format in the current directory'''
            self.image.save("output.png", "PNG")
    
    # =============================================================================
    def simulate_system():
    
        image_width = 800
        image_height = 600
    
        # initialize the system
        circle_processor = CircularMaskGenerator(image_width, image_height)
    
        # supply a pixel stream to drive the system
        for i in xrange(image_width*image_height):
            circle_processor.processPixel()
    
    # =============================================================================
    if __name__ == "__main__":
        simulate_system()

    This code creates a centered circle like so:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have two models- Users and Accounts. Each account can have at
Say that I have two tables like those: Employers (id, name, .... , deptId).
Say that I have LINQ query such as: var authors = from x in
Say that I have an article with multiple pages. Each page has a short
Say that i have a generic dictionary with data like this (I hope the
Note : I have tried using unserialize function but it say that first argument
Lets say that you have websites www.xyz.com and www.abc.com. Lets say that a user
Let’s say that I have two C# applications - game.exe (XNA, needs to support
Let's say you have a form with a component that displays data from a
Let's say I have a short list of strings, that can contain duplicates: <A,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.