-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVersion1
182 lines (142 loc) · 3.99 KB
/
Version1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;
import ij.plugin.*;
import java.util.*;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.gui.NewImage;
import ij.plugin.PlugIn;
import java.lang.Object.*;
import java.awt.event.*;
import java.awt.Component;
import ij.plugin.filter.*;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import java.awt.event.*;
class Result{
boolean generated;
boolean clicked;
Result(){
generated=false;
clicked=false;
}
void registerClick(){
clicked=true;
}
}
public class Grid2 extends MouseAdapter implements PlugIn {
//variable delclaration...................................................................................................................................
static String title = "New Image";
static int width = 512;
static int height = 512;
static int bitdep=32;
boolean box[ ][ ]=new boolean[32][32];
boolean clickstatus[ ][ ]=new boolean[512][512];
Result result[ ][ ]=new Result[32][32];
public void run(String arg) {
for(int m=0;m<512;m++){
for(int n=0;n<512;n++){
clickstatus[m][n]=false;
}
}
for(int p=0;p<512;p++){
for(int q=0;q<512;q++){
clickstatus[p][q]=false;
}
}
for(int p=0;p<32;p++){
for(int q=0;q<32;q++){
result[p][q] = new Result();
}
}
//Generic window making ..........................................
GenericDialog gd = new GenericDialog("New Image");
gd.addStringField("Title:", title);
gd.addNumericField("Width:", width, 0);
gd.addNumericField("Height:", height, 0);
gd.addNumericField("BitDepth:", bitdep, 0);
gd.showDialog();
if (gd.wasCanceled())
return;
title = gd.getNextString();
width = (int) gd.getNextNumber();
height = (int) gd.getNextNumber();
bitdep = (int) gd.getNextNumber();
//random numbers used...............................................................
Random generator1 =new Random();
Random generator2 =new Random();
Random generator3 =new Random();
Random generator4 =new Random();
//message...............................
IJ.showMessage("instructions","click ok to enter test,");
//creating image..................................................................
ImagePlus im = NewImage.createImage(
title, width, height, 1,8, NewImage.FILL_BLACK);
ImageProcessor ip=im.getProcessor();
im.show(); // show image on screen
ImageWindow win = im.getWindow();
ImageCanvas canvas = win.getCanvas();
canvas.addMouseListener(this);
IJ.wait(1000);
int i=0;
while(true){
double angle = generator3.nextInt();
double xx=16+(generator1.nextInt(16)*Math.cos(angle));
double yy=16+(generator2.nextInt(16)*Math.sin(angle));
int x = (int)xx;
int y=(int)yy;
int delay=generator3.nextInt( 300 );
i++;
if(!box[x][y]){
getXY(x,y);
geti(i);
ip.putPixel(x*16+8,y*16+8,255);
//ip.putPixel(x*16+9,y*16+8,255);
//ip.putPixel(x*16+8,y*16+8,255);
//ip.putPixel(x*16+9,y*16+9,255);
im.updateAndDraw(); // redisplay modified imageI
IJ.wait(300+delay);
ip.putPixel(x*16+8,y*16+8,0);
//ip.putPixel(x*16+9,y*16+8,0);
//ip.putPixel(x*16+8,y*16+8,0);
//ip.putPixel(x*16+9,y*16+9,0);
im.updateAndDraw();
IJ.wait(200+delay);
box[x][y]=true;
}//if end
if (i>=20000)break;
}//while ends
IJ.wait(2000);
im.close();
ImagePlus im_result = NewImage.createImage(
title, width, height, 1,8, NewImage.FILL_BLACK);
ImageProcessor ip_result=im_result.getProcessor();
for(int c=0;c<32;c++){
for(int j=0;j<32;j++){
if((result[c][j].generated==true)&(result[c][j].clicked==false))
ip_result.putPixel(c*16+8,j*16+8,255);
}
}
im_result.show();
}//run ends
int xx=0,yy=0,ii=0;
void getXY(int x,int y){
xx=x;
yy=y;
result[xx][yy].generated=true;
}
void geti(int i){ii=i;}
public void mouseClicked(MouseEvent e) {
result[xx][yy].clicked=true;
clickstatus[xx*16+8][yy*16+8]=true;
IJ.write("mousePressed: "+(8+xx*16)+","+(16*yy+8));
IJ.beep();
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}//plugin ends