package com.annimon.jecp.demo;

import com.annimon.jecp.JecpGraphics;
import com.annimon.jecp.JecpRandom;
import com.annimon.jecp.ApplicationListener;

/**
 * @author aNNiMON
 */
public class Main implements ApplicationListener {
    
    private int width, height;
    private DynamicLine[] lines;

    public void onStartApp(int width, int height) {
        this.width = width;
        this.height = height;
        System.out.println("width: " + width + "  height: " + height);
        
        lines = new DynamicLine[5];
        for (int i = 0; i < lines.length; i++) {
            lines[i] = new DynamicLine(
                    JecpRandom.rand(width), JecpRandom.rand(height),
                    JecpRandom.rand(width), JecpRandom.rand(height));
        }
    }

    public void onPauseApp() {
        System.out.println("onPauseApp");
    }

    public void onDestroyApp() {
        System.out.println("onDestroyApp");
    }

    public void onPaint(JecpGraphics g) {
        g.setColor(0xFF000000);
        g.fillRect(0, 0, width, height);
        final int count = 20;
        final int areaSize = width / count;
        final int colorStep = 255 / (count + 1);
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < count; j++) {
                int color = colorStep * Math.min(i, j);
                color = 0xFF000000 | (color << 16) | (color << 8) | color;
                g.setColor(color);
                g.drawRect(i * areaSize, j * areaSize, areaSize, areaSize);
            }
        }
        for (int i = 0; i < lines.length; i++) {
            lines[i].onPaint(g);
        }
    }

    public void onUpdate() {
        for (int i = 0; i < lines.length; i++) {
            lines[i].onUpdate(width, height);
        }
        try {
            Thread.sleep(20L);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}

@@ -244,58 +244,189 @@
 ate 
-int width, height;%0A    private DynamicLine%5B%5D lines
+static final int CELLS_COUNT = 30;%0A    %0A    private int width, height;%0A    private DynamicLine%5B%5D lines;%0A    %0A    private int cellX, cellY, cellColor;%0A    private long cellUpdateTime
 ;%0A%0A 
@@ -610,24 +610,53 @@
 );%0A        %0A
+        initHighlightCell();%0A
         line
@@ -1225,62 +1225,56 @@
 int 
-count = 20;%0A        final int areaSize = width / count
+areaSize = Math.min(width, height) / CELLS_COUNT
 ;%0A  
@@ -1308,21 +1308,27 @@
  255 / (
-count
+CELLS_COUNT
  + 1);%0A 
@@ -1354,21 +1354,27 @@
  0; i %3C 
-count
+CELLS_COUNT
 ; i++) %7B
@@ -1410,13 +1410,19 @@
 j %3C 
-count
+CELLS_COUNT
 ; j+
@@ -1684,32 +1684,155 @@
     %7D%0A        %7D%0A
+        g.setColor(cellColor);%0A        g.fillRect(cellX * areaSize + 1, cellY * areaSize + 1, areaSize - 1, areaSize - 1);%0A
         for (int
@@ -2060,146 +2060,540 @@
     
-try %7B%0A            Thread.sleep(20L);%0A        %7D catch (InterruptedException ex) %7B%0A            Thread.currentThread().interrupt();%0A        %7D
+if ((System.currentTimeMillis() - cellUpdateTime) %3E 1000) %7B%0A            // Update every second.%0A            initHighlightCell();%0A        %7D%0A        try %7B%0A            Thread.sleep(20L);%0A        %7D catch (InterruptedException ex) %7B%0A            Thread.currentThread().interrupt();%0A        %7D%0A    %7D%0A    %0A    private void initHighlightCell() %7B%0A        cellX = JecpRandom.rand(CELLS_COUNT);%0A        cellY = JecpRandom.rand(CELLS_COUNT);%0A        cellColor = JecpRandom.randomColor(0, 255);%0A        cellUpdateTime = System.currentTimeMillis();
 %0A   

Add highlight cell to demo