BUG Community

Welcome! Log In

Forums Recent Posts

Subscribe to Recent Posts 12,498 posts found

Mar 16, 2008 9:50pm
amormachine 6 posts

Topic: Java / Graphics Question

Hi,

I’m trying to learn Java in preparation for getting a Bug and have gotten stuck when it comes to understanding how graphics work.

I wrote a program that randomly selects a start and ending point on a 2D grid. Then, it unleashes thousands of ‘bugs’ (cast from the bug class) which move about quasi-randomly trying to find the end point.

Basically, I’d like to simply be able to draw out that 2D grid and illustrate each bug as a colored circle. Could someone explain how that could be done in my code, or point to a sample program which does something similiar?

Thanks!

CLASS 1:
public class Bug {

/ Initial Variables /
String name;
private int xPos;            //X-Position variable
private int yPos;            //Y-Position variable
private int i = 0;            //Indexing Variable
private float xPosRandom = (float) Math.random();
private float yPosRandom = (float) Math.random();
/ This method is used to pull in the initial starting position of the given
Bug object /
public void setInitialize(BugMain2 HiveMind)    {
// Pull Initial Starting Coordinates
xPos = HiveMind.getxStartPosition();
yPos = HiveMind.getxStartPosition();
}
/ This method is used to randomly simulate movement used to simulate movement /
public void moveBug(BugMain2 HiveMind)    {
// Modification of the X-Position Variable
if (Math.random() >= xPosRandom)    {
    ++xPos;
}    else    {
    --xPos;
}
// Modification of the Y-Position Variable
if (Math.random() >= yPosRandom)    {
    ++yPos;
}    else    {
    --yPos;
}
// Final Checks for Arena Size Constraints (i.e. the bug can't leave the field)
if (xPos > HiveMind.getxMaxValue())    {    --xPos;        }
if (yPos > HiveMind.getyMaxValue())    {    --yPos;        }
if (xPos < HiveMind.getxMinValue())    {    ++xPos;        }
if (yPos < HiveMind.getyMinValue())    {    ++yPos;        }
System.out.println(name  ": "  i  " "  getxPos()  " "  getyPos());
i++;
if (xPos  HiveMind.getxEndPosition() && yPos  HiveMind.getyEndPosition())    {
    HiveMind.setIsFinished(true);
    System.out.println("");
    System.out.println("Solution Found By: " + name);
    System.out.println("Number of Attempts: " + i);
    System.out.println("Percent Over Optimal: " + (float) 100  Math.abs(Math.max(HiveMind.getxEndPosition(), HiveMind.getyEndPosition()) - i)/Math.max(HiveMind.getxEndPosition(), HiveMind.getyEndPosition()));
}
}
/ Used to get the xPos variable /
public int getxPos()    {
    return xPos;
}
/ Used to get the yPos variable /
public int getyPos()    {
    return yPos;
}
/ Used to set the Bug's Name /
public void setName(String nameString)    {
    name = nameString;
}

}

CLASS 2:
import javax.swing.
;
import java.awt.;
import java.awt.geom.
;

public class BugMain2 {

/ Initialization of Important Parameters /
int xStartPosition = 0;            //Initialization of starting positions
int yStartPosition = 0;
int xEndPosition = 87;            //Initialization of ending position (puzzle solution)
int yEndPosition = 66;
int xMaxValue = 100;            //Initialization of max and min values for the arena
int yMaxValue = 100;
int xMinValue = 0;
int yMinValue = 0;
int NumberInSwarm = 1000;
Boolean IsFinished = false;
public static void main(String[] args)    {
// Variables and Objects
BugMain2 HiveMind = new BugMain2();
HiveMind.go(HiveMind);
}
public void go(BugMain2 HiveMind)    {
// Creation of Bug(s)
Bug[] Bugs = new Bug[NumberInSwarm];
// Initialization
for (int i=0; i < NumberInSwarm; i++)    {
    Bugs[i] = new Bug();
    Bugs[i].setName("BuG_" + i);
}
// Begin Race
while (IsFinished != true)    {
for (int j=0; j < NumberInSwarm ; j++)    {
    Bugs[j].moveBug(HiveMind);
    if (IsFinished == true)    {    break;    }
}
}
}
public int getxStartPosition()    {
    return xStartPosition;
}
public int getyStartPosition()    {
    return yStartPosition;
}
public int getxEndPosition()    {
    return xEndPosition;
}
public int getyEndPosition()    {
    return yEndPosition;
}
public int getxMaxValue()    {
    return xMaxValue;
}
public int getyMaxValue()    {
    return yMaxValue;
}
public int getxMinValue()    {
    return xMinValue;
}
public int getyMinValue()    {
    return yMinValue;
}
public void setIsFinished(Boolean IsFound)    {
    IsFinished = IsFound;
}

}

Mar 13, 2008 12:11pm
Medium finsprings 268 posts

Topic: BUGnet / Downloading application from BUGnet

Thanks Heather, sounds good!

Mar 13, 2008 11:39am
hzaida 38 posts

Topic: BUGnet / Downloading application from BUGnet

Hi finsprings,

You are right and we have been looking at different solutions to allow our users to browse applications on BUGnet with ease. Our Development team has created a new Search function. There will be a Search Applications icon within the BUGnet view and when selected will return the Community Applications web page, with a Search box.

This new feature is currently in QA, we should be delivering a new SDK build to the community soon. Keep you posted.

Thanks,
Heather

Mar 12, 2008 11:09pm
Medium finsprings 268 posts

Topic: BUGnet / Downloading application from BUGnet

I found an easier way just now. In Eclipse, if you go to the Window menu and select Preferences, you will see a BUGnet tab. In that tab there is a "Number of applications to display" field that defaults to 15. I set it to 30 (since there are 29 apps on BUGnet right now) and it immediately updated the BUGnet tab on the Dragonfly perspective to show the extra apps.

I have Dragonfly 1.0.0.1475 but this may have been there forever; I just happened to come across it just now when looking for something else.

Mar 12, 2008 10:43pm
Medium finsprings 268 posts

Topic: BUGnet / Downloading application from BUGnet

The BUGnet tab in the Dragonfly perspective in Eclipse has a "Top Apps" section, which is the easiest way to get an application downloaded into Eclipse. However, there are more applications available than it shows, and there’s no "more" or "next" button that I can see. You can download the JAR files from a regular browser, but I’m not sure how to import them into Eclipse that way.

The easiest way around is that I could find was to click on any app that is listed in the "Top Apps" section and then click on the "Community Applications" hyperlink all the way at the bottom of the app’s page. That will give you the same all-applications view that you can get in a regular browser, with links to each page-worth of applications, but it has the advantage that the "Download latest version to SDK" link is available.[/list]

Mar 12, 2008 9:55pm
Medium finsprings 268 posts

Topic: BUG SDK / OS-level development for the Bug

As the ship date is getting close for the Hiro P (yay :-)), can you guys provide some thoughts on how you foresee community-based OS-level development going for the Bug?

People are likely to want to port or create drivers for USB, vonHippel and other port-connected devices, which of course is not possible at the Dragonfly level. To develop a driver though, you need the kernel headers, cross-compiler tool chain and so forth. Are there any plans to post this sort of information on the wiki or elsewhere (or is it out there and I’m not seeing it)?

Cheers,
Dave

Mar 12, 2008 9:48pm
Medium finsprings 268 posts

Topic: Applications / JNI

I’m not sure which section this belongs in, but are there any recommendations on the use of JNI on the Bug?

For example:
Since JNI is generally non-portable, what should I use as my starting point?
Any JNI-related limitations of PhoneME of note?
What C library did you choose for the bug?
Any compiler or linker flags of note?

I have a recent iMX27 LTIB build on my Fedora Core 8 VM for other reasons. I imagine it’s pretty close to what the bug has with its iMX31, but I guess it depends what C library you guys are using and whether you used LTIB or went some other way to get Linux up and running on it. I was hoping that I could build a JNI lib on that but I can’t think of a way to test it until my real bug shows up. Is there any point in doing JNI stuff in the VirtualBug in the meantime?

Mar 12, 2008 9:40pm
Medium finsprings 268 posts

Topic: BUG SDK / Extremely Basic Questions

amormachine

1. When I install Eclipse on my XP machine, why doesn't it add anything to the start menu? I just want to make sure that that is by-design, and not indicative of a bad install.

No, that is normal

2. Is there a step-by-step guide to downloading user-posted programs (the .jar files) and opening them in Eclipse?

If you go to the Wiki main page at http://bugbeta.com/wiki/index.php/BUG_Wiki and scroll down to below the welcome message, you will see several sections that should help you get started. Downloading of an existing app from Bugnet is covered in the "Bug Intro\Download an application from Bugnet" topic at http://bugbeta.com/wiki/index.php/Download_an_application_from_BUGnet but it will make more sense if you go through the steps before that first.

3. When I try to install the BUG SDK in Eclipse, I get the following error:
Dragonfly SDK (1.0.0.277) requires feature "org.eclipse.pde (3.2.0)", or later version.

You need to use Eclipse Classic 3.3 or later which you can get from http://www.eclipse.org/downloads/. See the instructions on the Wiki at:
http://bugcommunity.com/wiki/index.php/Installation_of_Eclipse_%26_Dragonfly_%28the_BUG_SDK%29#Install_Eclipse


Hope that helps, and have fun!
Mar 12, 2008 8:39pm
amormachine 6 posts

Topic: BUG SDK / Extremely Basic Questions

I had a few extremely basic questions I was hoping someone could answer. I’m new to Java and basically the whole Open Source movement!

1. When I install Eclipse on my XP machine, why doesn’t it add anything to the start menu? I just want to make sure that that is by-design, and not indicative of a bad install.

2. Is there a step-by-step guide to downloading user-posted programs (the .jar files) and opening them in Eclipse?

3. When I try to install the BUG SDK in Eclipse, I get the following error:
Dragonfly SDK (1.0.0.277) requires feature "org.eclipse.pde (3.2.0)", or later version.

I did full search for updates to Eclipse, but that didn’t seem to fix anything.

Thanks!
[/img]

Mar 12, 2008 7:25pm
bmartinek 22 posts

Topic: BUGbase / USB Access

I am praying for the VonHippel module as I will just be doing initially a couple potentiometers and On/Off binaries.

I posted this on the VonHippel module thread:
http://bugcommunity.com/forums/viewtopic.php?t=209

Thanks for the reply!

Powered by Community Engine

Top
Login
Close
Bottom