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 geomerative.*;
class bezierstroke {
float startsize,endsize,linewidth,mpfract,raisefract,bezierfract;
bezierstroke(float _s,float _e,float _l,float _m,float _r,float _b){
startsize=_s;
endsize=_e;
linewidth=_l;
mpfract=_m;
raisefract=_r;
bezierfract=_b;
}
void drawstroke(RPoint start,RPoint end) {
ellipse(start.x,start.y,startsize,startsize);
ellipse(end.x,end.y,endsize,endsize);
RPoint mp=new RPoint(start.x+((end.x-start.x)*mpfract),(start.y+((end.y-start.y)*mpfract))-((getHeight()-(start.y+((end.y-start.y)*mpfract)))*raisefract));
RPoint bv=new RPoint((end.x-start.x)*bezierfract,(end.y-start.y)*bezierfract);
RPoint b1=new RPoint(mp.x-bv.x,mp.y-bv.y);
RPoint b2=new RPoint(mp.x+bv.x,mp.y+bv.y);
beginShape();
vertex(start.x,start.y);
bezierVertex(start.x,start.y,b1.x,b1.y-(linewidth/2),mp.x,mp.y-(linewidth/2));
bezierVertex(b2.x,b2.y-(linewidth/2),end.x,end.y,end.x,end.y);
bezierVertex(end.x,end.y,b2.x,b2.y+(linewidth/2),mp.x,mp.y+(linewidth/2));
bezierVertex(b1.x,b1.y+(linewidth/2),start.x,start.y,start.x,start.y);
endShape();
}
}
RPoint perpoint(RPoint p1,RPoint p2,float d) {
//returns a point left distance d of perpendicular line between points
float h=atan2(p2.y-p1.y,p2.x-p1.x);
return new RPoint(p2.x+(cos(h+HALF_PI)*d),p2.y+(sin(h+HALF_PI)*d));
}
class gradientstroke {
float startsize,endsize,mpfract,raisefract,bezierfract;
float[] transpos;
float[] transamt;
color col;
gradientstroke(float _s,float _e,float[] _p, float[] _a,color _c){
startsize=_s;
endsize=_e;
transpos=_p;
transamt=_a;
col=_c;
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noStroke();
fill(red(_col),green(_col),blue(_col),255);
//put ellipses in a seperate layer
//ellipse(Sp.x,Sp.y,startsize,startsize);
//ellipse(Ep.x,Ep.y,endsize,endsize);
//construct quads along path
//path is straight, curve comes from 3D/ raise
//how to deal with badly formatted control arrays? bother?
//3d stage in between
noFill();
float spos=0.0;
float step=.004; //optimise
//quad corner points
//these are perpedicular on the screen as we are making a gradient line system
RPoint L0,L1,p0,p1,p2,p3;
p0=new RPoint(0,0);
p1=p0;
L0=Sp;
boolean notfirst=false;
for (int i=0;i<transpos.length-1;i++) {
float transeg=transpos[i+1]-transpos[i];
for (float u=0;u<transeg-step;u+=step) {
float gradamt=u/transeg;
float b=255.0*((transamt[i]*(1-gradamt))+(transamt[i+1]*gradamt));
//find new point on line
L1=new RPoint(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u));
float lw=lerp(startsize,endsize,transpos[i]+u)/2;
p2=perpoint(L0,L1,lw);
p3=perpoint(L0,L1,-lw);
if (notfirst) {
fill(red(_col),green(_col),blue(_col),b);
beginShape();
vertex(p0.x,p0.y);
vertex(p2.x,p2.y);
vertex(p3.x,p3.y);
vertex(p1.x,p1.y);
endShape();
}
notfirst=true;
p0=p2;
p1=p3;
L0=L1;
/*
//temporarily draw line in 2D
strokeWeight(((1-(transpos[i]+u))*startsize)+((transpos[i]+u)*endsize));
stroke(red(col),green(col),blue(col),b);
line(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u),;
*/
}
}
}
}
class gradientstroke3D {
float startsize,endsize,mpfract,raisefract,bezierfract;
float[] transpos;
float[] transamt;
color col;
sphereMap smap;
float hw,hh;
gradientstroke3D(float _s,float _e,float[] _p, float[] _a,color _c,sphereMap _sp){
startsize=_s;
endsize=_e;
transpos=_p;
transamt=_a;
col=_c;
smap=_sp;
hw=(getWidth()/2);
hh=(getHeight()/2);
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noStroke();
fill(red(_col),green(_col),blue(_col),255);
//put ellipses in a seperate layer
//ellipse(Sp.x,Sp.y,startsize,startsize);
//ellipse(Ep.x,Ep.y,endsize,endsize);
//construct quads along path
//path is straight, curve comes from 3D/ raise
//how to deal with badly formatted control arrays? bother?
//3d stage in between
noFill();
float spos=0.0;
float step=.01; //optimise
//quad corner points
//these are perpedicular on the screen as we are making a gradient line system
RPoint L0,L1,p0,p1,p2,p3;
p0=new RPoint(0,0);
p1=p0;
L0=Sp;
int iteration=0;
for (int i=0;i<transpos.length-1;i++) {
float transeg=transpos[i+1]-transpos[i];
for (float u=0;u<transeg-step;u+=step) {
float gradamt=u/transeg;
float b=255.0*((transamt[i]*(1-gradamt))+(transamt[i+1]*gradamt));
//find new point on line
L1=smap.per(new RPoint(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u)),4+(sin((transpos[i]+u)*PI)*0.1));
float lw=lerp(startsize,endsize,transpos[i]+u)/2;
p2=perpoint(L0,L1,lw);
p3=perpoint(L0,L1,-lw);
if (iteration>1) {
fill(red(_col),green(_col),blue(_col),b);
beginShape();
vertex(p0.x+hw,p0.y+hh);
vertex(p2.x+hw,p2.y+hh);
vertex(p3.x+hw,p3.y+hh);
vertex(p1.x+hw,p1.y+hh);
endShape();
}
iteration++;
p0=p2;
p1=p3;
L0=L1;
/*
//temporarily draw line in 2D
strokeWeight(((1-(transpos[i]+u))*startsize)+((transpos[i]+u)*endsize));
stroke(red(col),green(col),blue(col),b);
line(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u),;
*/
}
}
}
}
|