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

  • Home
  • SEARCH
  • 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 8604639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:37:25+00:00 2026-06-12T02:37:25+00:00

I’m trying to write a spraypaint type program but I have forgotten all my

  • 0

I’m trying to write a spraypaint type program but I have forgotten all my maths.

I need some sort of probability equation to pick pixels near where the user clicks. So the probability should be high near the center and then decrease as the distance from the center gets higher and once you reach a certain distance the probability should be zero.
Also the probability at the center should be a smooth curve (if you know what I mean)

  • 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-06-12T02:37:26+00:00Added an answer on June 12, 2026 at 2:37 am

    I’m not sure which language you’re coding in, so here’s some pseudo-code. I will assume you know the corresponding syntax in the language you’re coding in.

    // Parameters:
    // Radius is the radius of the brush in pixels
    // Strength is a double ranging 0.0 to 1.0 and multiplies the probability of a pixel being painted
    function spraypaint(int radius, double strength) {
        strength = (strength * 2) - 1; //Change strength from 0.0->1.0 to -1.0->1.0 for logical application
    
        // For each pixel within the square...
        for(int x = -radius; x < radius; x++) {
            for(int y = -radius; y < radius; y++) {
                double distance = sqrt(x*x + y*y); // Get distance from center pixel
                double angle = 90*(distance/radius); // Get angle of "bell curve"
                double probability = sine(angle); // Determine probability of filling in this pixel
    
                // Apply additional probability based on strength parameter
                if(strength >= 0.0)
                    probability += ((1-probability) * strength);
                else
                    probability += probability * strength;
    
                if(distance > radius) {
                    continue;   // Skip this pixel if it's out of the circle's radius
                }
    
                if(random(0.0 to 1.0) < probability) { // If we random a decimal lower than our probability
                    setPixel(mouse.x + x, mouse.y + y, "Black"); // Draw this pixel
                }
            }
        }
    }
    

    The basic idea is:

    Iterate through each pixel and...
    
    1. Find its distance from the center pixel (The clicked pixel).
    2. Get distance/radius (0.0 to 1.0) and find the corresponding sine, creating a
       smooth probability curve.
    3. Apply the supplied strength to the probability.
    4. Pull a random double 0.0 to 1.0 and draw the pixel if it's within our probability.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.