Last active
December 10, 2016 02:04
-
-
Save hjanetzek/62794836821182c80dcb to your computer and use it in GitHub Desktop.
drawing circles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.oscim.test; | |
import static java.lang.Math.random; | |
import static org.oscim.backend.canvas.Color.fade; | |
import static org.oscim.utils.ColorUtil.shiftHue; | |
import org.oscim.backend.canvas.Color; | |
import org.oscim.core.GeometryBuffer; | |
import org.oscim.gdx.GdxMapApp; | |
import org.oscim.layers.GenericLayer; | |
import org.oscim.renderer.BucketRenderer; | |
import org.oscim.renderer.GLViewport; | |
import org.oscim.renderer.bucket.LineBucket; | |
import org.oscim.renderer.bucket.MeshBucket; | |
import org.oscim.theme.styles.AreaStyle; | |
import org.oscim.theme.styles.LineStyle; | |
public class CircleDemo extends GdxMapApp { | |
public static GeometryBuffer makeCircle(float x, float y, float radius, int segments) { | |
GeometryBuffer g = new GeometryBuffer(segments, 1); | |
g.startPolygon(); | |
for (int i = 0; i < segments; i++) { | |
double rad = Math.toRadians(i * (360f / segments)); | |
g.addPoint((float) (x + Math.cos(rad) * radius), | |
(float) (y + Math.sin(rad) * radius)); | |
} | |
return g; | |
} | |
@Override | |
public void createLayers() { | |
CircleRenderer r = new CircleRenderer(); | |
MeshBucket mb; | |
LineBucket lb; | |
GeometryBuffer g; | |
int level = 0; | |
for (int i = 0; i < 100; i++) { | |
AreaStyle style = new AreaStyle(fade(shiftHue(Color.RED, random()), 0.8f)); | |
mb = r.buckets.addMeshBucket(level++, | |
style); | |
lb = r.buckets.addLineBucket(level++, new LineStyle(Color.BLACK, 1.2f)); | |
float radius = (float) (random() * 10) + 0.5f; | |
g = makeCircle((float) (random() * 400), | |
(float) (random() * 400), | |
radius, | |
60); | |
mb.addConvexMesh(g); | |
lb.addLine(g); | |
} | |
mMap.layers().add(new GenericLayer(mMap, r)); | |
} | |
static class CircleRenderer extends BucketRenderer { | |
boolean first = true; | |
@Override | |
public void update(GLViewport v) { | |
if (first) { | |
/* keep drawing relative to current position */ | |
mMapPosition.copy(v.pos); | |
compile(); | |
first = false; | |
} | |
} | |
} | |
public static void main(String[] args) { | |
GdxMapApp.init(); | |
GdxMapApp.run(new CircleDemo(), null, 400); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment