• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Commit MetaInfo

Revisionf935858c240200d2bc58b50bab3b3217184b2537 (tree)
Zeit2015-07-02 07:25:17
AutorMirrgieRiana
CommiterMirrgieRiana

Log Message

add mirrg.applet.mathematics.zinc

Ändern Zusammenfassung

Diff

diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/.classpath
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/.classpath Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,10 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<classpath>
3+ <classpathentry kind="src" path="src"/>
4+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+ <classpathentry combineaccessrules="false" kind="src" path="/mirrg.applet.nitrogen"/>
6+ <classpathentry combineaccessrules="false" kind="src" path="/mirrg.event.nitrogen"/>
7+ <classpathentry combineaccessrules="false" kind="src" path="/mirrg.util.hydrogen"/>
8+ <classpathentry combineaccessrules="false" kind="src" path="/mirrg.complex.hydrogen"/>
9+ <classpathentry kind="output" path="bin"/>
10+</classpath>
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/.project
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/.project Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,17 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<projectDescription>
3+ <name>mirrg.applet.mathematics.zinc</name>
4+ <comment></comment>
5+ <projects>
6+ </projects>
7+ <buildSpec>
8+ <buildCommand>
9+ <name>org.eclipse.jdt.core.javabuilder</name>
10+ <arguments>
11+ </arguments>
12+ </buildCommand>
13+ </buildSpec>
14+ <natures>
15+ <nature>org.eclipse.jdt.core.javanature</nature>
16+ </natures>
17+</projectDescription>
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/AppletZinc.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/AppletZinc.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,191 @@
1+package mirrg.applet.mathematics.zinc;
2+
3+import java.awt.event.MouseEvent;
4+import java.awt.image.BufferedImage;
5+
6+import mirrg.applet.mathematics.zinc.core.IColorProvider;
7+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
8+import mirrg.applet.mathematics.zinc.core.ZincTransform;
9+import mirrg.applet.mathematics.zinc.events.NitrogenEventZinc;
10+import mirrg.applet.mathematics.zinc.events.NitrogenEventZincRender;
11+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetGrid;
12+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetMove;
13+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetPainterBase;
14+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetPainterFast;
15+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetZoom;
16+import mirrg.applet.nitrogen.AppletNitrogen;
17+import mirrg.applet.nitrogen.BackBuffer;
18+import mirrg.applet.nitrogen.HAppletNitrogen;
19+import mirrg.applet.nitrogen.HAppletNitrogen.ResponceApplyStandard;
20+import mirrg.applet.nitrogen.IBuffer;
21+import mirrg.applet.nitrogen.InputStatus;
22+import mirrg.applet.nitrogen.TripleBuffer;
23+import mirrg.applet.nitrogen.events.NitrogenEventApplet;
24+import mirrg.applet.nitrogen.events.NitrogenEventGameThread;
25+
26+public abstract class AppletZinc extends AppletNitrogen implements IZincCanvas
27+{
28+
29+ private static final long serialVersionUID = -2261994240357290706L;
30+
31+ ///////////////////////////////////////////////////
32+
33+ protected ZincGadgetPainterBase zincGadgetPainterBase;
34+ protected ZincGadgetGrid zincGadgetGrid;
35+ protected ZincGadgetMove zincGadgetMove;
36+ protected ZincGadgetZoom zincGadgetZoom;
37+
38+ public ZincGadgetPainterBase getZincGadgetPainterBase()
39+ {
40+ return zincGadgetPainterBase;
41+ }
42+
43+ public ZincGadgetGrid getZincGadgetGrid()
44+ {
45+ return zincGadgetGrid;
46+ }
47+
48+ public ZincGadgetMove getZincGadgetMove()
49+ {
50+ return zincGadgetMove;
51+ }
52+
53+ public ZincGadgetZoom getZincGadgetZoom()
54+ {
55+ return zincGadgetZoom;
56+ }
57+
58+ public AppletZinc()
59+ {
60+
61+ {
62+ responce = HAppletNitrogen.applyStandard(this);
63+ inputStatus = responce.inputStatus;
64+ tripleBuffer = responce.tripleBuffer;
65+ }
66+
67+ {
68+ bufferWorking = new BackBuffer(BufferedImage.TYPE_INT_RGB);
69+ bufferWorking.subscribeEvent(getEventManager());
70+ }
71+
72+ {
73+ zincTransform = new ZincTransform(
74+ this::getWidth,
75+ this::getHeight);
76+ }
77+
78+ {
79+ //zincGadgetPainterBase = new ZincGadgetPainter(this);
80+ zincGadgetPainterBase = new ZincGadgetPainterFast(this);
81+ zincGadgetGrid = new ZincGadgetGrid(this);
82+ zincGadgetMove = new ZincGadgetMove(this);
83+ zincGadgetMove.button = MouseEvent.BUTTON2;
84+ zincGadgetZoom = new ZincGadgetZoom(this);
85+ }
86+
87+ getEventManager().register(NitrogenEventGameThread.Render.class, event -> {
88+ repaint();
89+ });
90+ getEventManager().register(NitrogenEventGameThread.PostTick.class, event -> {
91+ responce.inputStatus.spend();
92+ });
93+ getEventManager().register(NitrogenEventApplet.Paint.class, event -> {
94+
95+ // render mathematical buffer
96+ {
97+ getEventManager().post(new NitrogenEventZinc.Render.Mathematical(getColorProvider()));
98+ }
99+
100+ // render dirty buffer
101+ {
102+ getBufferDirty().getGraphics().drawImage(getBufferMathematical().getBuffer(), 0, 0, this);
103+ getEventManager().post(new NitrogenEventZinc.Render.Overlay());
104+ }
105+
106+ // render safety buffer
107+ {
108+ responce.tripleBuffer.copy();
109+ }
110+
111+ // render primary buffer
112+ event.graphics.drawImage(responce.tripleBuffer.getBufferSafety().getBuffer(), 0, 0, this);
113+
114+ });
115+
116+ getEventManager().register(NitrogenEventApplet.Rebuffer.class, event -> {
117+ dirty();
118+ });
119+
120+ {
121+ getEventManager().register(NitrogenEventZincRender.Start.class, event -> {
122+ System.out.println("Start Rendering");
123+ });
124+ getEventManager().register(NitrogenEventZincRender.Finish.class, event -> {
125+ System.out.println("Finish Rendering");
126+ });
127+ }
128+
129+ }
130+
131+ protected abstract IColorProvider getColorProvider();
132+
133+ ////////////////////////////////////////////////////////////
134+
135+ protected ResponceApplyStandard responce;
136+ protected InputStatus inputStatus;
137+ protected TripleBuffer tripleBuffer;
138+
139+ @Override
140+ public InputStatus getInputStatus()
141+ {
142+ return inputStatus;
143+ }
144+
145+ @Override
146+ public BackBuffer getBufferSafety()
147+ {
148+ return tripleBuffer.getBufferSafety();
149+ }
150+
151+ @Override
152+ public BackBuffer getBufferDirty()
153+ {
154+ return tripleBuffer.getBufferDirty();
155+ }
156+
157+ //
158+
159+ protected BackBuffer bufferWorking;
160+
161+ @Override
162+ public IBuffer getBufferMathematical()
163+ {
164+ return zincGadgetPainterBase;
165+ }
166+
167+ @Override
168+ public BackBuffer getBufferWorking()
169+ {
170+ return bufferWorking;
171+ }
172+
173+ //
174+
175+ protected ZincTransform zincTransform;
176+
177+ @Override
178+ public ZincTransform getTransform()
179+ {
180+ return zincTransform;
181+ }
182+
183+ //
184+
185+ @Override
186+ public void dirty()
187+ {
188+ getEventManager().post(new NitrogenEventZinc.Dirty());
189+ }
190+
191+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/IColorProvider.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/IColorProvider.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,9 @@
1+package mirrg.applet.mathematics.zinc.core;
2+
3+@FunctionalInterface
4+public interface IColorProvider
5+{
6+
7+ public int getColorFromComplex(double re, double im);
8+
9+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/IZincCanvas.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/IZincCanvas.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,51 @@
1+package mirrg.applet.mathematics.zinc.core;
2+
3+import mirrg.applet.nitrogen.BackBuffer;
4+import mirrg.applet.nitrogen.IBuffer;
5+import mirrg.applet.nitrogen.InputStatus;
6+import mirrg.event.nitrogen.INitrogenEventManager;
7+
8+/**
9+ * レイヤー構成:
10+ * <ul>
11+ * <li>チェーンになっているレイヤー</li>
12+ * <ul>
13+ * <li>出力レイヤー</li>
14+ * <li>完成レイヤー {@link #getBufferSafety()}</li>
15+ * <li>オーバーレイ {@link #getBufferDirty()}</li>
16+ * <li>数学レイヤー {@link #getBufferMathematical()}</li>
17+ * </ul>
18+ * <li>独立レイヤー</li>
19+ * <ul>
20+ * <li>作業用レイヤー {@link #getBufferWorking()}</li>
21+ * </ul>
22+ * </ul>
23+ */
24+public interface IZincCanvas
25+{
26+
27+ public BackBuffer getBufferSafety();
28+
29+ public BackBuffer getBufferDirty();
30+
31+ public IBuffer getBufferMathematical();
32+
33+ public BackBuffer getBufferWorking();
34+
35+ //
36+
37+ public InputStatus getInputStatus();
38+
39+ public INitrogenEventManager getEventManager();
40+
41+ public ZincTransform getTransform();
42+
43+ //
44+
45+ public void dirty();
46+
47+ public int getHeight();
48+
49+ public int getWidth();
50+
51+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/ZincTransform.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/core/ZincTransform.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,55 @@
1+package mirrg.applet.mathematics.zinc.core;
2+
3+import java.util.function.IntSupplier;
4+
5+public class ZincTransform
6+{
7+
8+ public double pixelsPerX = 100;
9+ public double pixelsPerY = 100;
10+ public double centerCoordX = 0.0;
11+ public double centerCoordY = 0.0;
12+ public IntSupplier supplierScreenWidth;
13+ public IntSupplier supplierScreenHeight;
14+
15+ public ZincTransform(IntSupplier supplierScreenWidth, IntSupplier supplierScreenHeight)
16+ {
17+ this.supplierScreenWidth = supplierScreenWidth;
18+ this.supplierScreenHeight = supplierScreenHeight;
19+ }
20+
21+ public double getCoordX(double screenX)
22+ {
23+
24+ return centerCoordX + (screenX - getScreenWidth() / 2) / pixelsPerX;
25+ }
26+
27+ public double getCoordY(double screenY)
28+ {
29+
30+ return -(centerCoordY + (screenY - getScreenHeight() / 2) / pixelsPerY);
31+ }
32+
33+ public double getScreenX(double coordX)
34+ {
35+
36+ return (coordX - centerCoordX) * pixelsPerX + getScreenWidth() / 2;
37+ }
38+
39+ public double getScreenY(double coordY)
40+ {
41+
42+ return (-coordY - centerCoordY) * pixelsPerY + getScreenHeight() / 2;
43+ }
44+
45+ public int getScreenWidth()
46+ {
47+ return supplierScreenWidth.getAsInt();
48+ }
49+
50+ public int getScreenHeight()
51+ {
52+ return supplierScreenHeight.getAsInt();
53+ }
54+
55+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZinc.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZinc.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,44 @@
1+package mirrg.applet.mathematics.zinc.events;
2+
3+import mirrg.applet.mathematics.zinc.core.IColorProvider;
4+
5+public class NitrogenEventZinc
6+{
7+
8+ public static class Render
9+ {
10+
11+ /**
12+ * 数学バッファを更新するイベント。
13+ */
14+ public static class Mathematical
15+ {
16+
17+ public IColorProvider colorProvider;
18+
19+ public Mathematical(IColorProvider colorProvider)
20+ {
21+ this.colorProvider = colorProvider;
22+ }
23+
24+ }
25+
26+ /**
27+ * オーバーレイの描画を行うイベント。
28+ */
29+ public static class Overlay
30+ {
31+
32+ }
33+
34+ }
35+
36+ /**
37+ * 描画バッファを更新しなければならないというイベント。
38+ */
39+ public static class Dirty
40+ {
41+
42+ }
43+
44+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZincMove.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZincMove.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,29 @@
1+package mirrg.applet.mathematics.zinc.events;
2+
3+public class NitrogenEventZincMove
4+{
5+
6+ public static class Moved extends NitrogenEventZincMove
7+ {
8+
9+ private int dmx, dmy;
10+
11+ public Moved(int dmx, int dmy)
12+ {
13+ this.dmx = dmx;
14+ this.dmy = dmy;
15+ }
16+
17+ public int getDmx()
18+ {
19+ return dmx;
20+ }
21+
22+ public int getDmy()
23+ {
24+ return dmy;
25+ }
26+
27+ }
28+
29+}
\ No newline at end of file
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZincRender.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/events/NitrogenEventZincRender.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,16 @@
1+package mirrg.applet.mathematics.zinc.events;
2+
3+public class NitrogenEventZincRender
4+{
5+
6+ public static class Start extends NitrogenEventZincRender
7+ {
8+
9+ }
10+
11+ public static class Finish extends NitrogenEventZincRender
12+ {
13+
14+ }
15+
16+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadget.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadget.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,42 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import mirrg.applet.mathematics.zinc.core.IColorProvider;
4+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
5+import mirrg.applet.mathematics.zinc.events.NitrogenEventZinc;
6+import mirrg.applet.nitrogen.events.NitrogenEventGameThread;
7+
8+public class ZincGadget
9+{
10+
11+ protected IZincCanvas zincCanvas;
12+
13+ public ZincGadget(IZincCanvas zincCanvas)
14+ {
15+ this.zincCanvas = zincCanvas;
16+ zincCanvas.getEventManager().register(NitrogenEventGameThread.Tick.class, event -> {
17+ doInput();
18+ });
19+ zincCanvas.getEventManager().register(NitrogenEventZinc.Render.Mathematical.class, event -> {
20+ renderMathematical(event.colorProvider);
21+ });
22+ zincCanvas.getEventManager().register(NitrogenEventZinc.Render.Overlay.class, event -> {
23+ renderOverlay();
24+ });
25+ }
26+
27+ protected void doInput()
28+ {
29+
30+ }
31+
32+ protected void renderMathematical(IColorProvider colorProvider)
33+ {
34+
35+ }
36+
37+ protected void renderOverlay()
38+ {
39+
40+ }
41+
42+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetGrid.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetGrid.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,215 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import java.awt.Color;
4+import java.awt.Font;
5+import java.awt.event.KeyEvent;
6+
7+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
8+import mirrg.util.hydrogen.HMath;
9+import mirrg.util.hydrogen.HString;
10+import mirrg.util.hydrogen.HAwt;
11+
12+public class ZincGadgetGrid extends ZincGadget
13+{
14+
15+ private static final Font font = new Font("MS Gothic", Font.BOLD, 14);
16+
17+ public boolean enabledGrid = true;
18+ public boolean enabledCursor = true;
19+
20+ public IFunction function;
21+
22+ public ZincGadgetGrid(IZincCanvas zincCanvas)
23+ {
24+ super(zincCanvas);
25+ }
26+
27+ @Override
28+ public void renderOverlay()
29+ {
30+ if (!(enabledGrid || enabledCursor)) return;
31+
32+ // 画面の頂点における数学的座標の取得
33+ double mx1 = zincCanvas.getTransform().getCoordX(0);
34+ double my1 = zincCanvas.getTransform().getCoordY(0);
35+ double mx2 = zincCanvas.getTransform().getCoordX(zincCanvas.getWidth());
36+ double my2 = zincCanvas.getTransform().getCoordY(zincCanvas.getHeight());
37+
38+ // 数学的座標の反転のチェック
39+ {
40+ if (mx1 > mx2) {
41+ double tmp = mx1;
42+ mx1 = mx2;
43+ mx2 = tmp;
44+ }
45+
46+ if (my1 > my2) {
47+ double tmp = my1;
48+ my1 = my2;
49+ my2 = tmp;
50+ }
51+ }
52+
53+ // 画面の縦横の数学的大きさ
54+ final double mwidth = mx2 - mx1;
55+ final double mheight = my2 - my1;
56+
57+ // グリッド間隔の数学的距離
58+ final double gridSpaceW = HMath.nice(mwidth * 0.3);
59+ final double gridSpaceH = HMath.nice(mheight * 0.3);
60+
61+ // 有効小数点以下桁数
62+ final int effectiveDigitW = (int) (-Math.log10(gridSpaceW) + 0.9);
63+ final int effectiveDigitH = (int) (-Math.log10(gridSpaceH) + 0.9);
64+
65+ // グリッドの開始数学的座標
66+ double mgridstartx = Math.ceil(mx1 / gridSpaceW) * gridSpaceW;
67+ double mgridstarty = Math.ceil(my1 / gridSpaceH) * gridSpaceH;
68+
69+ // グリッド間隔の描画距離
70+ final double gridSpaceDispW = zincCanvas.getTransform().getScreenX(mx1 + gridSpaceW);
71+ //final double gridSpaceDispH = cc.getScreenYFromCoordY(my1 + gridSpaceH);
72+
73+ // グリッドの終了数学的座標
74+ double mgridendx = mx2;
75+ double mgridendy = my2;
76+
77+ // lines
78+ if (enabledGrid) {
79+ zincCanvas.getBufferDirty().getGraphics().setColor(Color.black);
80+ for (double mgridx = mgridstartx; mgridx < mgridendx; mgridx += gridSpaceW) {
81+ int dx = (int) zincCanvas.getTransform().getScreenX(mgridx);
82+ zincCanvas.getBufferDirty().getGraphics().drawLine(dx, 0, dx, zincCanvas.getHeight());
83+ }
84+ for (double mgridy = mgridstarty; mgridy < mgridendy; mgridy += gridSpaceH) {
85+ int dy = (int) zincCanvas.getTransform().getScreenY(mgridy);
86+ zincCanvas.getBufferDirty().getGraphics().drawLine(0, dy, zincCanvas.getWidth(), dy);
87+ }
88+ }
89+
90+ // lines cursor
91+ if (enabledCursor) {
92+ zincCanvas.getBufferDirty().getGraphics().setColor(Color.blue);
93+
94+ {
95+ double mgridx = zincCanvas.getTransform().getCoordX(zincCanvas.getInputStatus().getMouseX());
96+ int dx = (int) zincCanvas.getTransform().getScreenX(mgridx);
97+ zincCanvas.getBufferDirty().getGraphics().drawLine(dx, 0, dx, zincCanvas.getHeight());
98+ }
99+
100+ {
101+ double mgridy = zincCanvas.getTransform().getCoordY(zincCanvas.getInputStatus().getMouseY());
102+ int dy = (int) zincCanvas.getTransform().getScreenY(mgridy);
103+ zincCanvas.getBufferDirty().getGraphics().drawLine(0, dy, zincCanvas.getWidth(), dy);
104+ }
105+
106+ }
107+
108+ // labels
109+ if (enabledGrid) {
110+ // X座標ラベルの描画位置カウンタ
111+ int drawY = 0;
112+
113+ for (double mgridx = mgridstartx; mgridx < mgridendx; mgridx += gridSpaceW) {
114+ int dx = (int) zincCanvas.getTransform().getScreenX(mgridx);
115+ String str = HString.getEffectiveExpression(mgridx, effectiveDigitW);
116+
117+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
118+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str, dx, (1 + drawY) * zincCanvas.getBufferDirty().getGraphics().getFont().getSize(), Color.white, Color.black);
119+
120+ int textLength = zincCanvas.getBufferDirty().getGraphics().getFontMetrics().stringWidth(str);
121+ drawY = (drawY + 1) % (1 + (int) (textLength / gridSpaceDispW));
122+ }
123+
124+ for (double mgridy = mgridstarty; mgridy < mgridendy; mgridy += gridSpaceH) {
125+ int dy = (int) zincCanvas.getTransform().getScreenY(mgridy);
126+ String str = HString.getEffectiveExpression(mgridy, effectiveDigitH);
127+
128+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
129+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str, 0, dy + zincCanvas.getBufferDirty().getGraphics().getFont().getSize(), Color.white, Color.black);
130+ }
131+ }
132+
133+ // labels cursor
134+ if (enabledCursor) {
135+
136+ if (function != null) {
137+ double[] value = function.getValue(
138+ zincCanvas.getTransform().getCoordX(zincCanvas.getInputStatus().getMouseX()), zincCanvas.getTransform().getCoordY(zincCanvas.getInputStatus().getMouseY()));
139+
140+ {
141+ String str = "Re: " + value[0];
142+
143+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
144+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str,
145+ zincCanvas.getInputStatus().getMouseX() + 2,
146+ zincCanvas.getInputStatus().getMouseY() - 2 - zincCanvas.getBufferDirty().getGraphics().getFont().getSize() * 3,
147+ Color.white, Color.black);
148+ }
149+ {
150+ String str = "Im: " + value[1];
151+
152+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
153+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str,
154+ zincCanvas.getInputStatus().getMouseX() + 2,
155+ zincCanvas.getInputStatus().getMouseY() - 2 - zincCanvas.getBufferDirty().getGraphics().getFont().getSize() * 2,
156+ Color.white, Color.black);
157+ }
158+ }
159+
160+ {
161+ double mgridx = zincCanvas.getTransform().getCoordX(zincCanvas.getInputStatus().getMouseX());
162+
163+ String str = "X: " + HString.getEffectiveExpression(
164+ mgridx, effectiveDigitW + 4);
165+
166+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
167+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str,
168+ zincCanvas.getInputStatus().getMouseX() + 2,
169+ zincCanvas.getInputStatus().getMouseY() - 2 - zincCanvas.getBufferDirty().getGraphics().getFont().getSize(),
170+ Color.white, Color.black);
171+ }
172+
173+ {
174+ double mgridy = zincCanvas.getTransform().getCoordY(zincCanvas.getInputStatus().getMouseY());
175+
176+ String str = "Y: " + HString.getEffectiveExpression(
177+ mgridy, effectiveDigitH + 4);
178+
179+ zincCanvas.getBufferDirty().getGraphics().setFont(getFont());
180+ HAwt.drawBoldString(zincCanvas.getBufferDirty().getGraphics(), str,
181+ zincCanvas.getInputStatus().getMouseX() + 2,
182+ zincCanvas.getInputStatus().getMouseY() - 2,
183+ Color.white, Color.black);
184+ }
185+
186+ }
187+
188+ }
189+
190+ @Override
191+ public void doInput()
192+ {
193+ if (zincCanvas.getInputStatus().getKeyBoard().getState(KeyEvent.VK_G) == 1) {
194+ if (zincCanvas.getInputStatus().getKeyBoard().getState(KeyEvent.VK_CONTROL) <= 0) {
195+ enabledGrid = !enabledGrid;
196+ }
197+ if (zincCanvas.getInputStatus().getKeyBoard().getState(KeyEvent.VK_SHIFT) <= 0) {
198+ enabledCursor = !enabledCursor;
199+ }
200+ }
201+ }
202+
203+ protected Font getFont()
204+ {
205+ return font;
206+ }
207+
208+ public static interface IFunction
209+ {
210+
211+ public double[] getValue(double r, double i);
212+
213+ }
214+
215+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetMove.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetMove.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,45 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
4+import mirrg.applet.mathematics.zinc.events.NitrogenEventZincMove;
5+
6+/**
7+ * 中央クリック移動
8+ */
9+public class ZincGadgetMove extends ZincGadget
10+{
11+
12+ public int button;
13+
14+ public ZincGadgetMove(IZincCanvas zincCanvas)
15+ {
16+ super(zincCanvas);
17+ }
18+
19+ @Override
20+ public void doInput()
21+ {
22+ if (zincCanvas.getInputStatus().getMouseButtons().getState(button) >= 2) {
23+ int dmx = zincCanvas.getInputStatus().getMouseX() - zincCanvas.getInputStatus().getMouseXPrevious();
24+ int dmy = zincCanvas.getInputStatus().getMouseY() - zincCanvas.getInputStatus().getMouseYPrevious();
25+
26+ if (dmx != 0 || dmy != 0) {
27+ // save working buffer
28+ zincCanvas.getBufferWorking().getGraphics().drawImage(
29+ zincCanvas.getBufferMathematical().getBuffer(), 0, 0, null);
30+
31+ zincCanvas.getTransform().centerCoordX -= dmx / zincCanvas.getTransform().pixelsPerX;
32+ zincCanvas.getTransform().centerCoordY -= dmy / zincCanvas.getTransform().pixelsPerY;
33+
34+ zincCanvas.dirty();
35+
36+ // load working buffer
37+ zincCanvas.getBufferMathematical().getGraphics().drawImage(
38+ zincCanvas.getBufferWorking().getBuffer(), dmx, dmy, null);
39+
40+ zincCanvas.getEventManager().post(new NitrogenEventZincMove.Moved(dmx, dmy));
41+ }
42+ }
43+ }
44+
45+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainter.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,49 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import java.awt.Graphics2D;
4+import java.awt.image.BufferedImage;
5+
6+import mirrg.applet.mathematics.zinc.core.IColorProvider;
7+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
8+import mirrg.applet.nitrogen.BackBuffer;
9+
10+public class ZincGadgetPainter extends ZincGadgetPainterBase
11+{
12+
13+ protected BackBuffer buffer;
14+
15+ public ZincGadgetPainter(IZincCanvas zincCanvas)
16+ {
17+ super(zincCanvas);
18+
19+ {
20+ buffer = new BackBuffer(BufferedImage.TYPE_INT_RGB);
21+ buffer.subscribeEvent(zincCanvas.getEventManager());
22+ }
23+
24+ }
25+
26+ @Override
27+ protected void paintLine(IColorProvider colorProvider)
28+ {
29+ for (int x = 0; x < buffer.getBuffer().getWidth(); x++) {
30+ buffer.getBuffer().setRGB(
31+ x, y, colorProvider.getColorFromComplex(
32+ zincCanvas.getTransform().getCoordX(x),
33+ zincCanvas.getTransform().getCoordY(y)));
34+ }
35+ }
36+
37+ @Override
38+ public BufferedImage getBuffer()
39+ {
40+ return buffer.getBuffer();
41+ }
42+
43+ @Override
44+ public Graphics2D getGraphics()
45+ {
46+ return buffer.getGraphics();
47+ }
48+
49+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainterBase.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainterBase.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,85 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import mirrg.applet.mathematics.zinc.core.IColorProvider;
4+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
5+import mirrg.applet.mathematics.zinc.events.NitrogenEventZinc;
6+import mirrg.applet.mathematics.zinc.events.NitrogenEventZincRender;
7+import mirrg.applet.nitrogen.IBuffer;
8+
9+public abstract class ZincGadgetPainterBase extends ZincGadget implements IBuffer
10+{
11+
12+ protected int y = 0;
13+ protected int clearStart = 0;
14+ protected boolean inited = false;
15+ protected boolean dirty = false;
16+
17+ public ZincGadgetPainterBase(IZincCanvas zincCanvas)
18+ {
19+ super(zincCanvas);
20+ zincCanvas.getEventManager().register(NitrogenEventZinc.Dirty.class, event -> {
21+ dirty();
22+ });
23+ }
24+
25+ protected void dirty()
26+ {
27+ if (!dirty) {
28+ dirty = true;
29+ zincCanvas.getEventManager().post(new NitrogenEventZincRender.Start());
30+ }
31+ clearStart = y;
32+ }
33+
34+ @Override
35+ public void renderMathematical(IColorProvider colorProvider)
36+ {
37+ if (!inited) {
38+ inited = true;
39+ dirty();
40+ }
41+
42+ if (dirty) {
43+
44+ preTick();
45+
46+ long startTime = System.currentTimeMillis();
47+
48+ do {
49+
50+ if (colorProvider != null) {
51+ paintLine(colorProvider);
52+ }
53+
54+ y++;
55+ if (y >= zincCanvas.getHeight()) {
56+ y = 0;
57+ }
58+
59+ if (clearStart == y) {
60+ dirty = false;
61+ zincCanvas.getEventManager().post(new NitrogenEventZincRender.Finish());
62+ break;
63+ }
64+
65+ } while (startTime + 20 > System.currentTimeMillis());
66+
67+ postTick();
68+
69+ }
70+
71+ }
72+
73+ protected void preTick()
74+ {
75+
76+ }
77+
78+ protected void postTick()
79+ {
80+
81+ }
82+
83+ protected abstract void paintLine(IColorProvider colorProvider);
84+
85+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainterFast.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPainterFast.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,60 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import java.awt.Graphics2D;
4+import java.awt.image.BufferedImage;
5+
6+import mirrg.applet.mathematics.zinc.core.IColorProvider;
7+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
8+import mirrg.applet.nitrogen.events.NitrogenEventApplet;
9+import mirrg.util.hydrogen.HAwt;
10+
11+public class ZincGadgetPainterFast extends ZincGadgetPainterBase
12+{
13+
14+ private int width;
15+ private int height;
16+ private int[] data;
17+ private BufferedImage image;
18+ private Graphics2D graphics;
19+
20+ public ZincGadgetPainterFast(IZincCanvas zincCanvas)
21+ {
22+ super(zincCanvas);
23+
24+ zincCanvas.getEventManager().register(NitrogenEventApplet.Rebuffer.class, event -> {
25+ width = event.width;
26+ height = event.height;
27+ if (width < 1) width = 1;
28+ if (height < 1) height = 1;
29+ data = new int[width * height];
30+ image = HAwt.createBufferedImageFromIntArray(data, width, height);
31+
32+ graphics = image.createGraphics();
33+ });
34+ }
35+
36+ @Override
37+ protected void paintLine(IColorProvider colorProvider)
38+ {
39+ if (y < height) {
40+ for (int x = 0; x < width; x++) {
41+ data[x + width * y] = colorProvider.getColorFromComplex(
42+ zincCanvas.getTransform().getCoordX(x),
43+ zincCanvas.getTransform().getCoordY(y));
44+ }
45+ }
46+ }
47+
48+ @Override
49+ public BufferedImage getBuffer()
50+ {
51+ return image;
52+ }
53+
54+ @Override
55+ public Graphics2D getGraphics()
56+ {
57+ return graphics;
58+ }
59+
60+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPointer.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetPointer.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,45 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import java.awt.Color;
4+import java.awt.event.MouseEvent;
5+
6+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
7+
8+/**
9+ * 中央クリック移動
10+ */
11+public class ZincGadgetPointer extends ZincGadget
12+{
13+
14+ public int toggleButton = MouseEvent.BUTTON1;
15+ public Color color = Color.white;
16+ public double x = 0;
17+ public double y = 0;
18+
19+ public ZincGadgetPointer(IZincCanvas zincCanvas)
20+ {
21+ super(zincCanvas);
22+ }
23+
24+ @Override
25+ public void renderOverlay()
26+ {
27+ zincCanvas.getBufferDirty().getGraphics().setColor(color);
28+ zincCanvas.getBufferDirty().getGraphics().fillRect(
29+ (int) zincCanvas.getTransform().getScreenX(x) - 1,
30+ (int) zincCanvas.getTransform().getScreenY(y) - 1,
31+ 3, 3);
32+ }
33+
34+ @Override
35+ public void doInput()
36+ {
37+ if (zincCanvas.getInputStatus().getMouseButtons().getState(toggleButton) > 0) {
38+ x = zincCanvas.getTransform().getCoordX(zincCanvas.getInputStatus().getMouseX());
39+ y = zincCanvas.getTransform().getCoordY(zincCanvas.getInputStatus().getMouseY());
40+
41+ zincCanvas.dirty();
42+ }
43+ }
44+
45+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetZoom.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/gadgets/ZincGadgetZoom.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,75 @@
1+package mirrg.applet.mathematics.zinc.gadgets;
2+
3+import java.awt.event.KeyEvent;
4+
5+import mirrg.applet.mathematics.zinc.core.IZincCanvas;
6+import mirrg.applet.mathematics.zinc.core.ZincTransform;
7+import mirrg.applet.nitrogen.InputStatus;
8+
9+/**
10+ * 拡大縮小
11+ */
12+public class ZincGadgetZoom extends ZincGadget
13+{
14+
15+ public double wheelRate = 1.1;
16+
17+ public ZincGadgetZoom(IZincCanvas zincCanvas)
18+ {
19+ super(zincCanvas);
20+ }
21+
22+ @Override
23+ public void doInput()
24+ {
25+ ZincTransform t = zincCanvas.getTransform();
26+ InputStatus is = zincCanvas.getInputStatus();
27+
28+ int dmw = is.getMouseW() - is.getMouseWPrevious();
29+
30+ if (dmw != 0) {
31+ double rate2X = 1;
32+ double rate2Y = 1;
33+
34+ // save working buffer
35+ zincCanvas.getBufferWorking().getGraphics().drawImage(
36+ zincCanvas.getBufferMathematical().getBuffer(), 0, 0, null);
37+
38+ if (is.getKeyBoard().getState(KeyEvent.VK_CONTROL) <= 0) {
39+ rate2X = Math.pow(wheelRate, -dmw);
40+ t.centerCoordX += (is.getMouseX() - t.getScreenWidth() / 2) / t.pixelsPerX;
41+ t.pixelsPerX *= rate2X;
42+ t.centerCoordX -= (is.getMouseX() - t.getScreenWidth() / 2) / t.pixelsPerX;
43+ }
44+
45+ if (is.getKeyBoard().getState(KeyEvent.VK_SHIFT) <= 0) {
46+ rate2Y = Math.pow(wheelRate, -dmw);
47+ t.centerCoordY += (is.getMouseY() - t.getScreenHeight() / 2) / t.pixelsPerY;
48+ t.pixelsPerY *= rate2Y;
49+ t.centerCoordY -= (is.getMouseY() - t.getScreenHeight() / 2) / t.pixelsPerY;
50+ }
51+
52+ zincCanvas.dirty();
53+
54+ // load working buffer
55+ zincCanvas.getBufferMathematical().getGraphics().drawImage(
56+ zincCanvas.getBufferWorking().getBuffer(),
57+ (int) (is.getMouseX() * (1 - rate2X)),
58+ (int) (is.getMouseY() * (1 - rate2Y)),
59+ (int) (zincCanvas.getWidth() * rate2X),
60+ (int) (zincCanvas.getHeight() * rate2Y),
61+ null);
62+ }
63+
64+ if (is.getKeyBoard().getState(KeyEvent.VK_Z) == 1) {
65+ t.pixelsPerX = -t.pixelsPerX;
66+ zincCanvas.dirty();
67+ }
68+ if (is.getKeyBoard().getState(KeyEvent.VK_X) == 1) {
69+ t.pixelsPerY = -t.pixelsPerY;
70+ zincCanvas.dirty();
71+ }
72+
73+ }
74+
75+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/Library.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/Library.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,174 @@
1+package mirrg.applet.mathematics.zinc.samples;
2+
3+import mirrg.complex.hydrogen.StructureComplex;
4+import mirrg.complex.hydrogen.functions.Exponential;
5+import mirrg.util.hydrogen.HColor;
6+import mirrg.util.hydrogen.HMath;
7+
8+public class Library
9+{
10+
11+ public static int getMandNumber(double x0, double y0, double re, double im, int limit)
12+ {
13+ double x = x0, y = y0;
14+
15+ for (int t = 0; t < limit; t++) {
16+
17+ double tmp_x = Math.pow(x, 2) - Math.pow(y, 2) + re;
18+ y = 2 * x * y + im;
19+ x = tmp_x;
20+
21+ if (HMath.magnitude2(x, y) > 4) {
22+ return t;
23+ }
24+
25+ }
26+
27+ return limit;
28+ }
29+
30+ public static StructureComplex getMandNumberEx(double x0, double y0, double re, double im, int limit)
31+ {
32+ double x = x0, y = y0;
33+ StructureComplex z = new StructureComplex();
34+ StructureComplex a = new StructureComplex();
35+
36+ for (int t = 0;; t++) {
37+
38+ //a.add(x, y);
39+
40+ //a.set(x, y);
41+ double tmp_x = Math.pow(x, 2) - Math.pow(y, 2) + re;
42+ y = 2 * x * y + im;
43+ x = tmp_x;
44+
45+ /*
46+ if (t == 0) {
47+ a.add(x, y);
48+ a.sub(x0, y0);
49+ }
50+ */
51+ if (HMath.magnitude2(x, y) > 4 || t == limit) {
52+ /*z.add(x, y);
53+ z.sub(x0, y0);
54+ z.div(z.getAbstract());
55+ z.mul(t);*/
56+
57+ //a.sub(x, y);
58+ //a.set(x0, y0);
59+ a.set(x, y);
60+ z.set(Math.log(t), a.getArgument());
61+ Exponential.exp(z);
62+
63+ return z;
64+ }
65+
66+ }
67+
68+ }
69+
70+ public static int getBurningShipNumber(double x0, double y0, double r, double i, int limit)
71+ {
72+ double x = x0, y = y0;
73+
74+ for (int t = 0; t < limit; t++) {
75+
76+ if (x < 0) x = -x;
77+ if (y < 0) y = -y;
78+
79+ double tmp_x = Math.pow(x, 2) - Math.pow(y, 2) + r;
80+ y = 2 * x * y + i;
81+ x = tmp_x;
82+
83+ if (HMath.magnitude2(x, y) > 4) {
84+ return t;
85+ }
86+
87+ }
88+
89+ return limit;
90+ }
91+
92+ public static int getPow2ColorInt(double re, double im)
93+ {
94+ double _r = Math.pow(re, 2) - Math.pow(im, 2);
95+ double _i = 2 * re * im;
96+
97+ return getColorInt(_r, _i);
98+ }
99+
100+ public static int getColorInt(double re, double im)
101+ {
102+ double arg = Math.atan2(im, re);
103+ double abs = HMath.magnitude(re, im);
104+
105+ return getColorIntFromPolar(abs, arg);
106+ }
107+
108+ public static int getColorIntFromPolar(double abs, double arg)
109+ {
110+ double R = Math.cos(arg);
111+ double G = Math.cos(arg - 120.0 / 180 * Math.PI);
112+ double B = Math.cos(arg - 240.0 / 180 * Math.PI);
113+
114+ double brightness = 0.5 - 0.5 * Math.cos(abs * 2 * Math.PI);
115+
116+ brightness = 1 - Math.pow(brightness, 2);
117+
118+ return HColor.getColorInt(
119+ (int) ((128 + (126 * R)) * brightness),
120+ (int) ((128 + (126 * G)) * brightness),
121+ (int) ((128 + (126 * B)) * brightness));
122+ }
123+
124+ public static int getColorIntFromTriangleNumber(int r, int g, int b, int limit)
125+ {
126+ return HColor.getColorInt(
127+ getTriangleNumber(r, limit),
128+ getTriangleNumber(g, limit),
129+ getTriangleNumber(b, limit));
130+ }
131+
132+ public static long uramIndex(long x, long y)
133+ {
134+ long dist = Math.max(Math.abs(x), Math.abs(y));
135+
136+ if (dist == 0) return 1;
137+
138+ long length = (dist * 2 + 1);
139+
140+ // down
141+ if (y > 0 && Math.abs(x) <= Math.abs(y)) {
142+ return length * length + (-y + x);
143+ }
144+
145+ // left
146+ if (x < 0 && Math.abs(x) >= Math.abs(y)) {
147+ return length * length - (length - 1) + (y + x);
148+ }
149+
150+ // up
151+ if (y < 0 && Math.abs(x) <= Math.abs(y)) {
152+ return length * length - (length - 1) * 2 + (y - x);
153+ }
154+
155+ // right
156+ if (x > 0 && Math.abs(x) >= Math.abs(y)) {
157+ return length * length - (length - 1) * 3 + (-y - x);
158+ }
159+
160+ return 0;
161+ }
162+
163+ public static int getTriangleNumber(int n, int limit)
164+ {
165+ if (n == limit) {
166+ return 255;
167+ } else {
168+ n = n % 510; // 山頂の長さは1つ
169+ if (n >= 255) n = 510 - n;
170+ }
171+ return n;
172+ }
173+
174+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/SampleAppletZincUlam.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/SampleAppletZincUlam.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,32 @@
1+package mirrg.applet.mathematics.zinc.samples;
2+
3+import mirrg.applet.mathematics.zinc.AppletZinc;
4+import mirrg.applet.mathematics.zinc.core.IColorProvider;
5+import mirrg.util.hydrogen.HMath;
6+
7+public class SampleAppletZincUlam extends AppletZinc
8+{
9+
10+ private static final long serialVersionUID = -3068221136181833636L;
11+
12+ public SampleAppletZincUlam()
13+ {
14+ zincTransform.pixelsPerX = 1;
15+ zincTransform.pixelsPerY = 1;
16+ }
17+
18+ @Override
19+ protected IColorProvider getColorProvider()
20+ {
21+ return (re, im) -> {
22+ long uramIndex = Library.uramIndex((long) Math.floor(re), (long) Math.floor(im));
23+
24+ if (HMath.isPrime(uramIndex)) {
25+ return 0x000000;
26+ } else {
27+ return 0xffffff;
28+ }
29+ };
30+ }
31+
32+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/AppletZincComplex.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/AppletZincComplex.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,53 @@
1+package mirrg.applet.mathematics.zinc.samples.complex;
2+
3+import java.awt.Color;
4+import java.awt.event.MouseEvent;
5+
6+import mirrg.applet.mathematics.zinc.AppletZinc;
7+import mirrg.applet.mathematics.zinc.core.IColorProvider;
8+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetPointer;
9+import mirrg.applet.mathematics.zinc.samples.Library;
10+import mirrg.complex.hydrogen.StructureComplex;
11+
12+public abstract class AppletZincComplex extends AppletZinc implements IColorProvider
13+{
14+
15+ private static final long serialVersionUID = -8056098896957412575L;
16+
17+ protected ZincGadgetPointer p1;
18+ protected ZincGadgetPointer p2;
19+
20+ public AppletZincComplex()
21+ {
22+ p1 = new ZincGadgetPointer(this);
23+ p1.color = Color.blue;
24+ p1.toggleButton = MouseEvent.BUTTON1;
25+
26+ p2 = new ZincGadgetPointer(this);
27+ p2.x = 1;
28+ p2.color = Color.orange;
29+ p2.toggleButton = MouseEvent.BUTTON3;
30+ }
31+
32+ @Override
33+ protected IColorProvider getColorProvider()
34+ {
35+ return this;
36+ }
37+
38+ private StructureComplex buffer = new StructureComplex();
39+
40+ @Override
41+ public int getColorFromComplex(double re, double im)
42+ {
43+ buffer.re = re;
44+ buffer.im = im;
45+
46+ getValue(buffer);
47+
48+ return Library.getColorInt(buffer.re, buffer.im);
49+ }
50+
51+ protected abstract void getValue(StructureComplex buffer);
52+
53+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplex.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplex.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,98 @@
1+package mirrg.applet.mathematics.zinc.samples.complex;
2+
3+import static mirrg.complex.hydrogen.functions.Exponential.*;
4+import mirrg.applet.mathematics.zinc.samples.Library;
5+import mirrg.complex.hydrogen.StructureComplex;
6+import mirrg.complex.hydrogen.functions.Trigonometry;
7+
8+public class SampleAppletZincComplex extends AppletZincComplex
9+{
10+
11+ private static final long serialVersionUID = -6829268920303792926L;
12+
13+ @Override
14+ protected void getValue(StructureComplex buffer)
15+ {
16+ Trigonometry.sinh(buffer);
17+ if (true) return;
18+
19+ StructureComplex z = buffer.copy();
20+ StructureComplex p = new StructureComplex(this.p1.x, this.p1.y);
21+ StructureComplex p2 = new StructureComplex(this.p2.x, this.p2.y);
22+
23+ /*
24+ logit(z, p2);
25+ //p.inv();
26+ //p.neg();
27+ z.add(p);
28+ sigmoid(z, p2);
29+ */
30+
31+ /*
32+ StructureComplex a = z.copy();
33+ a.neg();
34+ a.add(1);
35+ z.div(a);
36+
37+ log(z);
38+
39+ z.add(-0, 2 * Math.PI);
40+
41+ z.neg();
42+
43+ exp(z);
44+
45+ z.add(1);
46+
47+ z.inv();
48+ */
49+ //log(z);
50+ /*
51+ //p.div(-4000000);
52+ z.div(1000000);
53+ z.set(Static.sigmoid(z.r), Static.sigmoid(z.i));
54+ z.add(0.000001);
55+ z.set(Static.logit(z.r), Static.logit(z.i));
56+ z.mul(1000000);
57+ */
58+
59+ //pow(z, 2);
60+ /*
61+ StructureComplex a = z.copy();
62+
63+ z.inv();
64+
65+ z.set(
66+ 0,//Static.getMandNumber(p.r, p.i, z.r, z.i, 300) / 600.0 + 0.5,
67+ Static.getMandNumberEx(z.r, z.i, p2.r, p2.i, 300) / 600.0 + 0.5);
68+ a.div(a.getAbstract());
69+
70+ z.mul(a);
71+ */
72+ z.inv();
73+
74+ z.set(
75+ Math.log(Library.getMandNumber(z.re, z.im, p2.re, p2.im, 300)),
76+ p.getArgument());
77+ exp(z);
78+
79+ //z = Static.getMandNumberEx(z.r, z.i, p2.r, p2.i, 300);
80+ z.div(600);
81+ z.setAbstract(z.getAbstract() + 0.5);
82+ /*
83+ z.set(
84+ 0,//Static.getMandNumber(p.r, p.i, z.r, z.i, 300) / 600.0 + 0.5,
85+ Static.getMandNumber(z.r, z.i, p2.r, p2.i, 300) / 600.0 + 0.5);
86+ */
87+ //z.mul(5, 6);
88+
89+ /*
90+ z.set(
91+ Math.abs(z.r / Math.PI / 2) * Math.cos(z.i),
92+ Math.abs(z.r / Math.PI / 2) * Math.sin(z.i));
93+ */
94+
95+ buffer.set(z);
96+ }
97+
98+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexMand.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexMand.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,31 @@
1+package mirrg.applet.mathematics.zinc.samples.complex;
2+
3+import static mirrg.complex.hydrogen.functions.Exponential.*;
4+import mirrg.applet.mathematics.zinc.samples.Library;
5+import mirrg.complex.hydrogen.StructureComplex;
6+
7+public class SampleAppletZincComplexMand extends AppletZincComplex
8+{
9+
10+ private static final long serialVersionUID = -6829268920303792926L;
11+
12+ @Override
13+ protected void getValue(StructureComplex buffer)
14+ {
15+ StructureComplex z = buffer.copy();
16+ StructureComplex p = new StructureComplex(this.p1.x, this.p1.y);
17+
18+ z.inv();
19+
20+ z.set(
21+ Math.log(Library.getMandNumber(z.re, z.im, p2.x, p2.y, 300)),
22+ p.getArgument());
23+ exp(z);
24+
25+ z.div(600);
26+ z.setAbstract(z.getAbstract() + 0.5);
27+
28+ buffer.set(z);
29+ }
30+
31+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexSimple.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexSimple.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,16 @@
1+package mirrg.applet.mathematics.zinc.samples.complex;
2+
3+import mirrg.complex.hydrogen.StructureComplex;
4+
5+public class SampleAppletZincComplexSimple extends AppletZincComplex
6+{
7+
8+ private static final long serialVersionUID = -6829268920303792926L;
9+
10+ @Override
11+ protected void getValue(StructureComplex buffer)
12+ {
13+
14+ }
15+
16+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexZeta.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/complex/SampleAppletZincComplexZeta.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,31 @@
1+package mirrg.applet.mathematics.zinc.samples.complex;
2+
3+import mirrg.complex.hydrogen.StructureComplex;
4+import mirrg.complex.hydrogen.functions.Exponential;
5+
6+public class SampleAppletZincComplexZeta extends AppletZincComplex
7+{
8+
9+ private static final long serialVersionUID = -6829268920303792926L;
10+
11+ @Override
12+ protected void getValue(StructureComplex buffer)
13+ {
14+ int limit = (int) (p1.x * 10000);
15+
16+ if (limit < 0) return;
17+
18+ StructureComplex s = buffer.copy();
19+ buffer.set(0, 0);
20+ StructureComplex c = new StructureComplex();
21+ for (int n = 1; n <= limit; n++) {
22+ c.set(s.re, s.im);
23+ Exponential.exp(c, n);
24+ c.inv();
25+
26+ buffer.add(c);
27+ }
28+
29+ }
30+
31+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/AppletZincFractal.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/AppletZincFractal.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,54 @@
1+package mirrg.applet.mathematics.zinc.samples.fractal;
2+
3+import java.awt.Color;
4+import java.awt.event.MouseEvent;
5+
6+import mirrg.applet.mathematics.zinc.AppletZinc;
7+import mirrg.applet.mathematics.zinc.core.IColorProvider;
8+import mirrg.applet.mathematics.zinc.gadgets.ZincGadgetPointer;
9+import mirrg.applet.mathematics.zinc.samples.Library;
10+
11+public abstract class AppletZincFractal extends AppletZinc implements IColorProvider
12+{
13+
14+ private static final long serialVersionUID = 3225715598176116501L;
15+
16+ protected ZincGadgetPointer gadgetPointerMand;
17+ protected ZincGadgetPointer gadgetPointerJulia;
18+
19+ protected int limit;
20+
21+ public AppletZincFractal()
22+ {
23+ gadgetPointerMand = new ZincGadgetPointer(this);
24+ gadgetPointerMand.color = Color.blue;
25+ gadgetPointerMand.toggleButton = MouseEvent.BUTTON3;
26+
27+ gadgetPointerJulia = new ZincGadgetPointer(this);
28+ gadgetPointerJulia.x = 0.2;
29+ gadgetPointerJulia.color = Color.orange;
30+ gadgetPointerJulia.toggleButton = MouseEvent.BUTTON1;
31+
32+ limit = 500;
33+ }
34+
35+ @Override
36+ protected IColorProvider getColorProvider()
37+ {
38+ return this;
39+ }
40+
41+ private int[] buffer = new int[2];
42+
43+ @Override
44+ public int getColorFromComplex(double re, double im)
45+ {
46+ getValue(re, im, buffer);
47+
48+ return Library.getColorIntFromTriangleNumber(
49+ buffer[0], buffer[1], 0, limit);
50+ }
51+
52+ protected abstract void getValue(double re, double im, int[] buffer);
53+
54+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincBurningShip.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincBurningShip.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,29 @@
1+package mirrg.applet.mathematics.zinc.samples.fractal;
2+
3+import mirrg.applet.mathematics.zinc.samples.Library;
4+
5+
6+public class SampleAppletZincBurningShip extends AppletZincFractal
7+{
8+
9+ private static final long serialVersionUID = 5934764986594139350L;
10+
11+ public SampleAppletZincBurningShip()
12+ {
13+ limit = 2000;
14+ }
15+
16+ @Override
17+ protected void getValue(double re, double im, int[] buffer)
18+ {
19+ buffer[0] = Library.getBurningShipNumber(
20+ gadgetPointerMand.x, gadgetPointerMand.y,
21+ re, im,
22+ limit);
23+ buffer[1] = Library.getBurningShipNumber(
24+ re, im,
25+ gadgetPointerJulia.x, gadgetPointerJulia.y,
26+ limit);
27+ }
28+
29+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincFractalSimple.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincFractalSimple.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,15 @@
1+package mirrg.applet.mathematics.zinc.samples.fractal;
2+
3+public class SampleAppletZincFractalSimple extends AppletZincFractal
4+{
5+
6+ private static final long serialVersionUID = 5934764986594139350L;
7+
8+ @Override
9+ protected void getValue(double re, double im, int[] buffer)
10+ {
11+ buffer[0] = (int) (re * 2 + im * 4) % 256;
12+ buffer[1] = (int) (re * -3 + im * 5) % 256;
13+ }
14+
15+}
diff -r 08fff8cb7027 -r f935858c2402 mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincMandelbrot.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mirrg.applet.mathematics.zinc/src/mirrg/applet/mathematics/zinc/samples/fractal/SampleAppletZincMandelbrot.java Thu Jul 02 07:25:17 2015 +0900
@@ -0,0 +1,24 @@
1+package mirrg.applet.mathematics.zinc.samples.fractal;
2+
3+import mirrg.applet.mathematics.zinc.samples.Library;
4+
5+
6+public class SampleAppletZincMandelbrot extends AppletZincFractal
7+{
8+
9+ private static final long serialVersionUID = 5934764986594139350L;
10+
11+ @Override
12+ protected void getValue(double re, double im, int[] buffer)
13+ {
14+ buffer[0] = Library.getMandNumber(
15+ gadgetPointerMand.x, gadgetPointerMand.y,
16+ re, im,
17+ limit);
18+ buffer[1] = Library.getMandNumber(
19+ re, im,
20+ gadgetPointerJulia.x, gadgetPointerJulia.y,
21+ limit);
22+ }
23+
24+}