-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb01scmod.pde
177 lines (155 loc) · 4.82 KB
/
b01scmod.pde
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
//Synaptonemal complex modeling in processing + fvlib
// 020120123_13:47_pmc
// starting new, after canonicalizing scmod7. this time, try nuclear confinement…
//Licensed under CC attribution-sharealike http://creativecommons.org/licenses/by-sa/3.0/
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import volatileprototypes.fvlib.*;
// Requires pmcarlton’s branch of fvlib with BehaviorSphereConstraint
import processing.opengl.*;
import processing.video.*;
Point[][] LEs; //Lateral Elements
Point[] CEs; //Central Elements
Point[] allpts; //All points, for the Verlet integrator
Link[][] LinkAcross; //LE-CE and LE-LE links
Link[][] LinkConsec; //Links between consecutive elements
Link[][] LinkEveryOther; //Links between every other Lateral (not Central) element
Link[] alllinks; //All links, for the Spring Relaxation
IntegratorVerlet vi;
BehaviorConstantDistance bcd;
BehaviorSpringRelaxation rs;
BehaviorSphereConstraint bsph;
PeasyCam cam;
float Kd = 1.0;
int lstmp=0;
int ww=800;
int hh=600;
float frx=.999;
float ldist=5.0;
float sdist=5.0;
//float stLC=0.5; //stiffness between Lateral and Central elements
//float stCEL=0.1; //stiffness for consecutive CEs
//float stLEOP=0.5; //stiffness for opposite LEs
float stSKIP=0.241; //stiffness for every other consecutive LE
float stLAT=0.133; //stiffness for consecutive LEs
int steps=200;
int len=100;
int it=0;
float msec=0;
PVector origin;
float theRadius=21.0f;
float sphForce=0.00001;
PFont font;
float strokew=3;
boolean sepon=false;
float theta=0.0;
int flip=1;
int pindex=0;
int lindex=0;
void setup() {
String _timestamp = "" + System.currentTimeMillis();
size(ww, hh, OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
hint(ENABLE_NATIVE_FONTS) ;
// hint(ENABLE_DEPTH_SORT);
cam = new PeasyCam(this, 0, 0, 0, 300); // Camera Setup
cam.setMinimumDistance(10);
cam.setMaximumDistance(1500);
//Make the SC.
origin=new PVector(0.0f, 0.0f, 0.0f);
LEs=new Point[2][len];
allpts=new Point[len*2];
LinkConsec=new Link[2][len-1];
LinkEveryOther=new Link[2][len-2];
//alllinks=new Link[(3*(len))+(3*(len-1))+(2*(len-2))];
alllinks=new Link[(2*(len-1))+(2*(len-2))];
for (int i=0;i<len;i++) {
// LEs[0][i] = new Point(-(ww/4)+i*ldist,sdist,random(1)/100000,1,0.0,ldist*3);//put the LEs in their own array
LEs[0][i] = new Point(random(1), random(1), random(1), 1, 0.0, ldist*3);//put the LEs in their own array
allpts[pindex++]=LEs[0][i];
// LEs[1][i] = new Point(-(ww/4)+i*ldist,-sdist,random(1)/100000,1,0.0,ldist*3);
LEs[1][i] = new Point(random(1), -random(1), random(1), 1, 0.0, ldist*3);
allpts[pindex++]=LEs[1][i];
}
for (int i=0;i<len;i++) {
if (i>0) {
LinkConsec[0][i-1]=new Link(LEs[0][i], LEs[0][i-1], stLAT);
LinkConsec[0][i-1].setC(ldist);
alllinks[lindex++]=LinkConsec[0][i-1];
LinkConsec[1][i-1]=new Link(LEs[1][i], LEs[1][i-1], stLAT);
LinkConsec[1][i-1].setC(ldist);
alllinks[lindex++]=LinkConsec[1][i-1];
if (i>1) {
LinkEveryOther[0][i-2]=new Link(LEs[0][i], LEs[0][i-2], stSKIP);
LinkEveryOther[0][i-2].setC(ldist*2.0);
alllinks[lindex++]=LinkEveryOther[0][i-2];
LinkEveryOther[1][i-2]=new Link(LEs[1][i], LEs[1][i-2], stSKIP);
LinkEveryOther[1][i-2].setC(ldist*2.0);
alllinks[lindex++]=LinkEveryOther[1][i-2];
}
}
}
vi=new IntegratorVerlet(allpts).setF(frx); //initvi
rs=new BehaviorSpringRelaxation(alllinks);
bsph=new BehaviorSphereConstraint(allpts, origin, theRadius);
bsph.setFMult(sphForce);
font = createFont("Commodore 64", 16);
}
void draw() {
background(50, 100);
theRadius=30+sin(2*PI*(it%steps)/steps)*10.0;
bsph.setRadius(theRadius);
for (int j=steps;j>=0;j--) {
it++;
rs.step();
bsph.step();
vi.step();
}
fill(128, 60);
stroke(0);
strokeWeight(0);
//for (int i=0;i<2;i++) {
//for (Link l:LinkConsec[i]) {
//line(l.p1.x,l.p1.y,l.p1.z,l.p2.x,l.p2.y,l.p2.z);
//}
//for (Link l:LinkEveryOther[i]){
// line(l.p1.x,l.p1.y,l.p1.z,l.p2.x,l.p2.y,l.p2.z);
//}
//}
beginShape(TRIANGLES);
for (int i=0;i<2;i++) {
for (Link l:LinkConsec[i]) {
vertex(l.p1.x, l.p1.y, l.p1.z);
vertex(l.p2.x, l.p2.y, l.p2.z);
}
//for (Link l:LinkEveryOther[i]){
// line(l.p1.x,l.p1.y,l.p1.z,l.p2.x,l.p2.y,l.p2.z);
//}
}
endShape();
strokeWeight(3);
beginShape(POINTS);
for (Point pt : LEs[0]) {
stroke(255, 0, 120);
vertex(pt.x, pt.y, pt.z);
}
for (Point pt : LEs[1]) {
stroke(0, 255, 120);
vertex(pt.x, pt.y, pt.z);
}
endShape();
noFill();
strokeWeight(0.1);
stroke(0,200,255,25);
sphere(theRadius);
cam.beginHUD();
textFont(font);
text("Iteration: " + it, 10, height-10);
cam.endHUD();
}
void keyPressed() {
if (keyCode==' ') {
sepon=!sepon;
}
}