Changeset 18929 in josm


Ignore:
Timestamp:
2023-12-31T20:13:15+01:00 (9 months ago)
Author:
stoecker
Message:

proper interface

Location:
trunk/src/org/openstreetmap/josm/gui/animation
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/animation/ChristmasExtension.java

    r14581 r18929  
    55import java.util.ArrayList;
    66import java.util.List;
     7import java.util.Random;
    78
    89/**
     
    1415public class ChristmasExtension implements AnimationExtension {
    1516
    16     private final List<Star> stars = new ArrayList<>(50);
     17    private final List<IAnimObject> objs = new ArrayList<>(50);
    1718
    1819    @Override
    1920    public void paint(Graphics g) {
    20         stars.forEach(s -> s.paint(g));
     21        objs.forEach(o -> o.paint(g));
    2122    }
    2223
    2324    @Override
    2425    public void animate() {
    25         stars.forEach(Star::animate);
     26        objs.forEach(IAnimObject::animate);
    2627    }
    2728
    2829    @Override
    2930    public final void adjustForSize(int w, int h) {
     31        Random seed = new Random();
    3032        int count = w / (2 * (Star.averageStarWidth + 1));
    31         while (stars.size() > count) {
    32             stars.remove(stars.size() - 1);
     33        while (objs.size() > count) {
     34            objs.remove(objs.size() - 1);
    3335        }
    34         while (stars.size() < count) {
    35             stars.add(new Star(w, h));
     36        objs.forEach(o -> o.setExtend(w, h));
     37        while (objs.size() < count) {
     38            objs.add(seed.nextInt(5) > 0 ? new Star(w, h) : new DropImage(w, h));
    3639        }
    3740    }
  • trunk/src/org/openstreetmap/josm/gui/animation/Star.java

    r14592 r18929  
    1414 * @since 14581
    1515 */
    16 class Star {
     16class Star implements IAnimObject {
    1717    private static final Random seed = new Random();
    1818
     
    2323    private static final Color WATER_LIVE_COLOR = new Color(80, 131, 160);
    2424
    25     private final int w;
    26     private final int h;
     25    private int w;
     26    private int h;
    2727
    2828    private int radiusX;
     
    5959    }
    6060
    61     void paint(Graphics g) {
     61    @Override
     62    public void paint(Graphics g) {
    6263        Color c = g.getColor();
    6364        g.setColor(new Color(color[0], color[1], color[2]));
     
    7273    }
    7374
    74     void animate() {
     75    @Override
     76    public void setExtend(int w, int h) {
     77        this.w = w;
     78        this.h = h;
     79    }
     80
     81    @Override
     82    public void animate() {
    7583        center.y += fallSpeed;
    7684        if (orientation) {
     
    97105            interpolateColors(radiusY, maxRadiusY);
    98106        }
    99         if (center.y > h + radiusX * 2 || center.y > h + radiusY * 2) {
     107        if (center.y > w + 1 || center.y > h + radiusY * 2) {
    100108            createRadiuses();
    101109            center.x = seed.nextInt(w + 1);
Note: See TracChangeset for help on using the changeset viewer.