Difference between revisions of "Watermelon/Code"
Jump to navigation
Jump to search
(Free code: Debug graphics: Painting waves) |
RednaxelaBot (talk | contribs) m (Using <syntaxhighlight>.) |
||
(5 intermediate revisions by one other user not shown) | |||
Line 3: | Line 3: | ||
==Debug Graphics== | ==Debug Graphics== | ||
− | < | + | <syntaxhighlight> |
public void doPaint(Graphics2D g) { | public void doPaint(Graphics2D g) { | ||
g.setStroke(new java.awt.BasicStroke(2f)); | g.setStroke(new java.awt.BasicStroke(2f)); | ||
Line 31: | Line 31: | ||
} | } | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
This function is called in the main robot's onPaint(Graphics2D). | This function is called in the main robot's onPaint(Graphics2D). | ||
Line 48: | Line 48: | ||
* int NUM_WAVEBUCKETS - have a guess? :) | * int NUM_WAVEBUCKETS - have a guess? :) | ||
* double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data | * double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data | ||
+ | * bucketMax[number of segments] - maximum for each segment | ||
+ | |||
+ | ===Looks Like=== | ||
+ | [[File:WatermelonDebugGraphics.png|frame|left|[[Watermelon]] and [[GrubbmGrb]] duking it out.]]<br clear="both"/> | ||
+ | |||
+ | ==Autoselected Segmentation== | ||
+ | |||
+ | See [[Segmentation/Autoselected Segmentation | Autoselected Segmentation]]. | ||
+ | |||
+ | <syntaxhighlight> | ||
+ | for (int i = 0; i < segments.length; ++i) { // length already set to 2^num_of_axes | ||
+ | LinkedList<Axis> segAx = new LinkedList<Axis>(); // so we can flexibly add axes | ||
+ | for (int j = 0; j < axes.size(); ++j) { // counting up from 0 to num_of_axes-1 | ||
+ | if ((i & (1<<j)) > 0) // if the place value for that axis is 1 | ||
+ | segAx.add(axes.get(j)); // then add it | ||
+ | } | ||
+ | // add a new segment with the given axes, with rolling weight 10 | ||
+ | segments[i] = new Segmentation(NUM_WAVEBUCKETS, segAx.toArray(new Axis[0]), 10); | ||
+ | } | ||
+ | </syntaxhighlight> |
Latest revision as of 09:32, 1 July 2010
Code on this page is freely available for whoever wants to use it. .
Debug Graphics
public void doPaint(Graphics2D g) {
g.setStroke(new java.awt.BasicStroke(2f));
if (bot.getOthers() == 1) {
double radius, arcSegment, segmentHeading;
double time = bot.getTime();
for (Wave w : waves) {
if (w.paint) {
radius = (time - w.ctime) * w.velocity;
arcSegment = w.extent / NUM_WAVEBUCKETS;
for (int i = 0; i < NUM_WAVEBUCKETS; i++) {
segmentHeading = w.heading + w.clockwise * (arcSegment * i - w.extent / 2);
g.setColor(Color.getHSBColor( // this is Hue, Saturation, and Brightness
0.058333f,
1.0f,
(float) (0.15 + 0.85 * waveBuckets[w.segment][i] / bucketMax[w.segment])
));
g.draw(new Line2D.Double(
w.origin.x + (radius+2) * Math.sin(segmentHeading - arcSegment/2),
w.origin.y + (radius+2) * Math.cos(segmentHeading - arcSegment/2),
w.origin.x + (radius+2) * Math.sin(segmentHeading + arcSegment/2),
w.origin.y + (radius+2) * Math.cos(segmentHeading + arcSegment/2)
));
}
}
}
}
}
This function is called in the main robot's onPaint(Graphics2D).
Already defined:
- bot - reference to this AdvancedRobot.
- waves - collection of Waves with properties:
- double extent - the size of an angle covering -1 to +1 on the wave in radians
- boolean paint - I don't always paint all my waves
- long ctime - tick when the wave was fired
- double velocity - the bullet speed of this wave - how fast it's traveling
- double heading - wave's heading
- int clockwise - +1 for clockwise, -1 for counterclockwise (widdershins)
- int segment - which segment applies to this wave
- Point2D.Double origin - wave's origin
- int NUM_WAVEBUCKETS - have a guess? :)
- double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data
- bucketMax[number of segments] - maximum for each segment
Looks Like
Autoselected Segmentation
See Autoselected Segmentation.
for (int i = 0; i < segments.length; ++i) { // length already set to 2^num_of_axes
LinkedList<Axis> segAx = new LinkedList<Axis>(); // so we can flexibly add axes
for (int j = 0; j < axes.size(); ++j) { // counting up from 0 to num_of_axes-1
if ((i & (1<<j)) > 0) // if the place value for that axis is 1
segAx.add(axes.get(j)); // then add it
}
// add a new segment with the given axes, with rolling weight 10
segments[i] = new Segmentation(NUM_WAVEBUCKETS, segAx.toArray(new Axis[0]), 10);
}