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 8986075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:27:54+00:00 2026-06-15T21:27:54+00:00

I am trying to diffuse a color in java Draw (which doesn’t have the

  • 0

I am trying to diffuse a color in java Draw (which doesn’t have the capability to diffuse normally) but I ran into an error and I can’t seem to spot it.
The way I went about diffusing was by writing a small script that would draw my shape hundreds of times, each time smaller and slightly varying in color. This is my snippet:

import javax.swing.*;
import java.awt.*;
public class DiffuseDraw extends JFrame
{
  //set size of window here
  final int length = 350;
  final int height = 370;

  public DiffuseDraw()
  { 
    super("Graphics Project Window");
    Container container = getContentPane(); 
    setBackground(new Color(0,0,0));
    setSize(length, height);
    setVisible(true);
  }


// my problem comes here:

  public void paint(Graphics g)
  {

    Draw.fillRectangle(g,0,0,length,height,new Color(19,24,32));

    int rad = 325; // size of the biggest circle

    float floatGreen = 0; // Color components for black
    float floatBlue = 0;
    float floatRed = 0;

    int counter = 0; // the counter
    while (counter < 290) {
       rad = rad - 1; // Here we shrink the by a small incriment

       floatRed = floatRed + 87/290;  //red component slowly goes brighter
       floatBlue = floatBlue + 178/290; // blue component slowly goes brighter
       floatGreen = floatGreen + 211/290; // green component slowly goes brighter
       int intRed = (int)Math.round(floatRed);
       int intBlue = (int)Math.round(floatBlue);
       int intGreen = (int)Math.round(floatGreen);

       Draw.fillCircle(g,173,307,rad,new Color(intRed,intBlue,intGreen));
       counter = counter + 1;
    }

  }

  public static void main(String args[]) {
    DiffuseDraw prog = new DiffuseDraw();
    prog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }  
}

When I compile and run, I only get a black screen. I am guessing that the problem is coming from the colors not changing. The number I am adding the float red blue and green by came from me wanting to diffuse a type of blue, so I took the the brightest color of blue that would appear and divided it by 290, the number of times the loop would run.

  • 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-15T21:27:55+00:00Added an answer on June 15, 2026 at 9:27 pm

    Instead of

    87/290, 178/290, and 211/290,

    try using

    (float)87/290, (float)178/290, and (float)211/290.

    That will, at least, add some color to the window- the problem is that by default, a number like 87/290 will be evaluated to 0; casting it to a float will give the desired result of 0.3 instead.

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

Sidebar

Related Questions

Trying to copy the msdn refernce here doesn't work and gives an error I
I'm trying to draw a sphere using gluSphere. The sphere appears but certain patches
I've been trying to implement GLSL into my program, however given that i have
trying to get my first HTML/CSS uni assignment sorted but have become a bit
Trying to develop hello world, but getting force close error on emulator. thanks in
Trying to do something really simple, but can't figure out the syntax. I have
Im trying to add two objects, which is created from one part, but since
I'm trying to write a UI in OpenGL and have run into a problem
trying to figure out why this is happening - I have an input text
Trying a simple project to create my own (very basic) data binding. I have

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.