Repository navigation
Expand file tree
/
Copy pathLayerTexture.java
More file actions
194 lines (155 loc) · 4.91 KB
/
Copy pathLayerTexture.java
File metadata and controls
194 lines (155 loc) · 4.91 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import javax.media.opengl.GL2;
import controlP5.Group;
import controlP5.Tab;
import processing.core.PApplet;
import processing.core.PImage;
public class LayerTexture extends LayerMovement {
private PImage texture;
public float gradients[];
public LayerTexture(Application parent){
super(parent);
gradients = new float[4];
gradients[0]=0.0f;
gradients[1]=1.f;
gradients[2]=1.0f;
gradients[3]=1f;
setParameterMap();
}
public void set(GL2 gl){
texture = parent.loadImage("VK.gif");
texture.mask(parent.loadImage("VK.gif"));
}
@Override
public void draw(GL2 gl) {
//transform
gl.glPushMatrix();
gl.glTranslatef(Config.WIDTH/2,Config.HEIGHT/2,0);
gl.glScalef(zoom.v(),zoom.v(),0);
gl.glRotatef(angle.v()/(2*(float)Math.PI)*360,0,0,1);
//gl.glTranslatef(-width/2,-Config.HEIGHT/2,0);
gl.glTranslatef(scrollX.v(),scrollY.v(),0);
fillAll();
gl.glPopMatrix();
}
private void fillAll(){
parent.color(foregroundR/255f, foregroundG/255f, foregroundB/255f);
int range = 2+(int)(
(Math.min(width,height)*zoom.v()+Math.sqrt((float)Config.WIDTH*Config.WIDTH+Config.HEIGHT*Config.HEIGHT))
/
(Math.min(width,height)*zoom.v())
/ 2
);
for(int x=0;x<=range;x++){
int xOffset=width*x;
for(int y=0;y<=range;y++){
int yOffset=height*y;
paint(xOffset,yOffset);
if(x!=0){
paint(-xOffset,yOffset);
}
if(y!=0){
paint(xOffset,-yOffset);
}
if(x!=0&&y!=0){
paint(-xOffset,-yOffset);
}
}
}
}
public void paintBackground(){
}
private void paint(float x,float y){
//gl.glPushMatrix();
parent.translate(x,y);
if(texture!=null ) {
parent.beginShape(PApplet.QUADS);
parent.texture(texture);
parent.vertex(x, y,0f,0f);
parent.vertex(x+width, y,texture.width,0f);
parent.vertex(x+width,y+height,texture.width,texture.height);
parent.vertex(x,y+height,0f, texture.height);
parent.endShape();
}else{
System.out.println("pattern texture is null");
}
parent.translate(-x,-y);
}
float ratio=0.5f;;
@SuppressWarnings("unused")
private void tri( int x1,int y1,int x2,int y2,int x3,int y3,GL2 gl){
float ratio=1;
gl.glBegin(GL2.GL_TRIANGLES);
ratio=gradients[0]*gradient.v();
gl.glColor4f(
(1-ratio)*foregroundR/255f +(ratio)*backgroundR/255f
, (1-ratio)*foregroundG/255f +(ratio)*backgroundG/255f,
(1-ratio)*foregroundB/255f +(ratio)*backgroundB/255f
,fgAlpha.v()
);
gl.glVertex2f(x1,y1);
ratio=gradients[1]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x2,y2);
ratio=gradients[2]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x3,y3);
gl.glEnd();
}
@SuppressWarnings("unused")
private void quadri(float x1, float y1,float x2,float y2,float x3,float y3,float x4,float y4,GL2 gl){
float ratio=1;
gl.glBegin(GL2.GL_QUADS);
//parent.texture(parent.textures[1]);
ratio=gradients[0]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x1,y1);
ratio=gradients[1]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x2,y2);
ratio=gradients[2]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x3,y3);
ratio=gradients[3]*gradient.v();
gl.glColor4f(
(1-ratio)*(foregroundR)/255.0f +(ratio)*(backgroundR)/255.0f
, (1-ratio)*(foregroundG)/255.0f +(ratio)*(backgroundG)/255.0f ,
(1-ratio)*(foregroundB)/255.0f +(ratio)*(backgroundB)/255.0f
,fgAlpha.v()
);
gl.glVertex2f(x4,y4);
gl.glEnd();
}
@Override
public int buildUI(GUIController controller,int x, int y , Tab tab, Group group) {
// TODO Auto-generated method stub
return(0);
}
@Override
public void drawBackground(GL2 gl) {
}
}