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
|
package com.jogamp.opencl.demos.fft;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
/**
* Draws an image and lets you draw white dots in it with the mouse. Or big white dots with code.
* @author notzed
*/
@SuppressWarnings("serial")
class PaintView extends ImageView implements MouseListener, MouseMotionListener {
Graphics2D imgg;
Paint paint;
Shape brush;
BlurTest win;
public PaintView(BlurTest win, BufferedImage img) {
super(img);
this.win = win;
paint = new RadialGradientPaint(new Point2D.Float(0, 0), 3,
new float[]{0.0f, 1.0f}, new Color[]{new Color(255, 255, 255, 255), new Color(255, 255, 255, 0)});
brush = new java.awt.geom.Ellipse2D.Float(-5, -5, 11, 11);
imgg = img.createGraphics();
this.addMouseListener(this);
}
void drawPaint(double x, double y) {
Graphics2D gg = (Graphics2D) imgg.create();
gg.translate(x, y);
gg.setPaint(paint);
gg.fill(brush);
gg.dispose();
repaint(new Rectangle((int) (x - 6), (int) (y - 6), 12, 12));
// close your eyes if you're under-age ...
win.recalc();
}
public void drawDot(double width, double height, double angle) {
Graphics2D gg = (Graphics2D) imgg.create();
gg.setPaint(paint);
gg.translate(img.getWidth() / 2, img.getHeight() / 2);
gg.rotate(angle);
gg.scale(width, height);
gg.fill(brush);
gg.dispose();
repaint();
win.recalc();
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
addMouseMotionListener(this);
drawPaint(e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
removeMouseMotionListener(this);
//drawPaint(e.getX(), e.getY());
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
drawPaint(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e) {
}
}
|