// file Dot.java // For FillDemo. // by Harriet Fell // fell@ccs.neu.edu // July 2004 import java.awt.*; import java.awt.geom.*; import javax.swing.*; import java.awt.image.*; class Dot { Graphics2D g2; int wd; int ht; int h; int v; Color c; // int size; set below for 20 by something grid. Dot(Graphics2D gr2, int width, int height, int i, int j, Color cl){ g2 = gr2; wd = width; ht = height; h = i; v = j; c = cl; } Dot Set(int i, int j, Color cl){ h = i; v = j; c = cl; return this; } void Fill(){ int size = Math.min(wd/20, ht/20); g2.setPaint(c); g2.fillOval(size*h + 1, size*v + 1, size - 1, size - 1); g2.setPaint(Color.black); } /* void Flash(short h, short v, short T){ InvertRect(size*h, size*v, 1+size*(h+1), 1+size*(v+1)); Delay(T); InvertRect(size*h, size*v, 1+size*(h+1), 1+size*(v+1)); } void GetDotColor(short h, short v, RGBColor& rgb){ GetCPixel(size*h + 1 + size/2, size*v+1 + size/2, &rgb); } bool SameColor(RGBColor A, RGBColor B){ if (A.red != B.red) return false; if (A.green != B.green) return false; if (A.blue != B.blue) return false; return true; } bool Filled(short h, short v, RGBColor fill, RGBColor boundary){ RGBColor c; GetDotColor(h, v, c); return (SameColor(c, boundary) or SameColor(c, fill) or !InDrawing(h, v)); // for flood fill // return (!SameColor(c, old_value) or !InDrawing(h, v)); } Point Leftmost(short h, short v, RGBColor fill, RGBColor boundary){ assert(!Filled(h, v, fill, boundary)); short start = h; while (!Filled(start, v, fill, boundary)) start--; Point P; P.h = start+1; P.v = v; return P; } bool InDrawing(short h, short v){ return DrawMinX/size <= h and h < DrawMaxX/size and DrawMinY/size <= v and v < DrawMaxY/size; } */ }