summaryrefslogtreecommitdiff
path: root/cad/src/experimental/CoNTub/GLienzo2.java
blob: fbfc5b6242cef984a7c0f984398771dba2cda8df (plain)
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
//package nt;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//import nttabs.*;

public class GLienzo2 extends JPanel implements MouseListener
{

	JButton bot;
	int n1, m1, n2, m2;
	boolean ph;
	public GLienzo2 ()
	{
		addMouseListener (this);
		n1 = 0;
		m1 = 0;
		n2 = 0;
		m2 = 1;
		ph = true;
	}


	public GLienzo2 (int gn1, int gm1, int gn2, int gm2)
	{
		addMouseListener (this);
		n1 = gn1;
		n2 = gn2;
		m1 = gm1;
		m2 = gm2;
		ph = true;

	}


	public void paint (Graphics g)
	{
		g.setColor (java.awt.Color.LIGHT_GRAY);
		g.fillRect (0, 0, getSize ().width, getSize ().height);	// blanqueamos

		g.setColor (Color.blue);
		//dibujamos ejes de coordenadas
		int centrox = getSize ().width / 2;
		int centroy = getSize ().height / 2;


		//determinamos la escala en pixeles por unidad. Sean, a buen ojo, 10 px por unidad
		double e = 4;

		g.drawLine (0, centroy, 2 * centrox, centroy);
		g.drawLine (centrox, 0, centrox, 2 * centroy);
		//dibujvos vector del tubo 1


		//vector1
		double x1 = n1 + m1 / 2;
		double y1 = Math.sqrt (3) / 2 * m1;
		//vector2
		double x2 = n2 + m2 / 2;
		double y2 = Math.sqrt (3) / 2 * m2;
		//vector union
		int na, ma, nb, mb;

		Nanotubo NTA, NTB;	//ambos tubos
		NTA = new Nanotubo (n1, m1, 2.46);
		NTB = new Nanotubo (n2, m2, 2.46);

		int nad = m2 - m1;
		int mad = n1 - n2 + m1 - m2;
		int nbd = n1 + m1 - m2;
		int mbd = n2 - n1 + m2;
		//La solucion invertida (Hep-Pent)
		int nai = n1 - n2 + m1 - m2;
		int mai = n2 - n1;
		int nbi = n2 - m1 + m2;
		int mbi = m1 - n2 + n1;
		//que viene antes, P o H?? si creciente=true, h va primero, p despues
		if (!ph) {
			na = nai;
			ma = mai;
		} else {
			na = nad;
			ma = mad;
		}

		double xa = na + ma / 2;
		double ya = Math.sqrt (3) / 2 * ma;

		//Dibujos
		g.setColor (Color.black);
		g.drawLine (centrox, centroy, (int) (centrox + e * x1), (int) (centroy - e * y1));
		g.setColor (Color.red);
		g.drawLine (centrox, centroy, (int) (centrox + e * xa), (int) (centroy - e * ya));
		g.setColor (Color.black);
		g.drawLine ((int) (centrox + e * xa), (int) (centroy - e * ya), (int) (centrox + e * (xa + x2)), (int) (centroy - e * (ya + y2)));
		g.setColor (Color.blue);
		g.drawLine ((int) (centrox + e * x1), (int) (centroy - e * y1), (int) (centrox + e * (xa + x2)), (int) (centroy - e * (ya + y2)));

		g.setColor (Color.black);
		g.drawString ("(" + n1 + "," + m1 + ")", 20, 20);
		g.drawString ("(" + n2 + "," + m2 + ")", 80, 20);
		if (ph)
			g.drawString ("p-h, h en (" + na + "," + ma + ")", 10, -10 + 2 * centroy);
		else
			g.drawString ("h-, p en (" + na + "," + ma + ")", 10, -10 + 2 * centroy);
	}

	public void mousePressed (MouseEvent ev)
	{

		int nn2 = n2;
		int nm2 = m2;
		if (ev.getButton () == MouseEvent.BUTTON1) {
			nn2 = -m2;
			nm2 = n2 + m2;
		}
		if (ev.getButton () == MouseEvent.BUTTON3)
			ph = !ph;
		redraw (n1, m1, nn2, nm2, ph);
	}
	public void mouseReleased (MouseEvent ev)
	{
	}
	public void mouseEntered (MouseEvent ev)
	{
	}
	public void mouseExited (MouseEvent ev)
	{
	}
	public void mouseClicked (MouseEvent ev)
	{


	}

	public void redraw (int gn1, int gm1, int gn2, int gm2, boolean b)
	{			//Segundo metodo, de redibujado, parametrizado
		this.n1 = gn1;
		this.n2 = gn2;
		this.m1 = gm1;
		this.m2 = gm2;
		this.ph = b;
		repaint ();
	}
}