Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
21 May, 2013, 18:42:15 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: [java] drawOval problems -  (Read 766 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Snake X
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 14:37:23
Date Registered: 18 March, 2010, 02:48:47
Posts: 806


Topic starter
Total Post Ratings: +25

View Profile
« on: 13 May, 2011, 02:00:04 »
0

Gah sorry for creating so many java threads.. but I get so many buggs  Grin

Ok this time, I have a weird problem dealing with drawOval.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.awt.*;
import java.applet.*;
import java.util.Random;
 
public class sphere extends Applet {
 
        public void paint(Graphics g)  {
 
                Random r = new Random();
                int wh = r.nextInt(300);
                while(true) {
                        Color  c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
                        g.setColor(c);
                        for (wh = 0;wh>=r.nextInt(300);wh++) {
                                g.fillOval(r.nextInt(1001),r.nextInt(701),wh,wh);
                        }
 
//                      wh = r.nextInt(300);
                        try {
 
                Thread.sleep( 20 );
 
            } catch ( InterruptedException e ) {
 
                // do nothing
            }
                }
        }
}

In this applet, There is supposed to be a random circle drawn at a random location. It's width/height starts at 0, and is supposed to increase up to the randomly generated number thus making the circle bigger in an animation style. However it stays at the same size that's defined in the for loop (0) so you can't really see it. How come it's not increasing?
Logged

There's a Zombie for that™
ben_g
LV7 Elite (Next: 700)
*******
Offline Offline

Gender: Male
Last Login: Yesterday at 21:16:47
Date Registered: 08 May, 2011, 21:03:27
Location: (ix+$43)
Posts: 646


Total Post Ratings: +74

View Profile
« Reply #1 on: 14 May, 2011, 20:33:29 »
0

Look closely at this code:

1
for (wh = 0;wh>=r.nextInt(300);wh++) {
It calculates a random number in every cycle of the for loop. This can be very irreliable.

further:

1
2
3
int wh = r.nextInt(300);
...
int wh = r.nextInt(300);
These two lines are a waste of size and CPU. I know that it's only a few bites and under a microsecound, but in a large applet, this kind of optimisation can tell the diference between fitting on a CD, and not fitting on a CD.

back to your question: You draw an oval with increasing the size, but always at a random location withouth deleting the previous one. I think your problem is that the screen is filled with hundreds of ovals so that you can't see a single oval. Instaed the screen will be just a solid color.

The first lines weren't an answer to your question, but I just wanted to help you to optimise your code.
« Last Edit: 14 May, 2011, 20:34:34 by ben_g » Logged

Spoiler for completely unimportant stuff:
My projects
 - A base converter that also supports signed and fixed-point numbers.
 - A first person shooter with a polygon-based 3d engine.
Spoiler for latest screenshot:
- A java MORPG.
Spoiler for screenshot:
- a minecraft game in axe
Spoiler for Only open this spoiler if you want to read what's inside:
What's inside.
From when I saw this image, I never lost the game again!
Spoiler for This is [Edit:
not[/Edit] my contest entry. I hope you like it.]
Snake X
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 14:37:23
Date Registered: 18 March, 2010, 02:48:47
Posts: 806


Topic starter
Total Post Ratings: +25

View Profile
« Reply #2 on: 22 May, 2011, 21:09:11 »
0

oh ok. Well thanks for helping anyways, but I figured it out though :p

oh btw:
Quote from: ben_g
but in a large applet, this kind of optimisation can tell the diference between fitting on a CD, and not fitting on a CD.
theres always winrar Tongue
Logged

There's a Zombie for that™
Ashbad
Guest
« Reply #3 on: 22 May, 2011, 21:12:57 »
0


1
2
3
int wh = r.nextInt(300);
...
int wh = r.nextInt(300);

These two lines are a waste of size and CPU. I know that it's only a few bites and under a microsecound, but in a large applet, this kind of optimisation can tell the diference between fitting on a CD, and not fitting on a CD.

Since it could be placed in a function format, space could be conserved that way.  However, that could be only ~50 bytes (random guess), and follows the idea of 'inlining' functions -- which increases size but speeds many operations up.

I think it would be fine, since declaring it as a method would just add that much more size back, and would not merit any reward for optimization.  I say keep it Wink
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.174 seconds with 32 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.