Download Jar. Uses 994K of libraries. Click here for Pure Java version (2074L/11K).
1 | !7 |
2 | |
3 | p { pMain(It); } |
4 | |
5 | sclass It extends PApplet { |
6 | |
7 | //Artificial Horizon+Compass by Adrian Fernandez 4-19-2013 |
8 | //Built with Processing 1.5.1 |
9 | int W=1350; //My Laptop's screen width |
10 | int H=690; //My Laptop's screen height |
11 | float Pitch; |
12 | float Bank; |
13 | float Azimuth; |
14 | float ArtificialHoizonMagnificationFactor=0.7f; |
15 | float CompassMagnificationFactor=0.85f; |
16 | float SpanAngle=120; |
17 | int NumberOfScaleMajorDivisions; |
18 | int NumberOfScaleMinorDivisions; |
19 | PVector v1, v2; //For testing only |
20 | |
21 | void settings() { size(W, H); } |
22 | |
23 | void setup() |
24 | { |
25 | rectMode(CENTER); |
26 | smooth(); |
27 | //strokeCap(SQUARE);//Optional |
28 | } |
29 | void draw() |
30 | { |
31 | background(0); |
32 | translate(W/4, H/2.1f); |
33 | MakeAnglesDependentOnMouse(); |
34 | Horizon(); |
35 | rotate(-Bank); |
36 | PitchScale(); |
37 | Axis(); |
38 | rotate(Bank); |
39 | Borders(); |
40 | Plane(); |
41 | ShowAngles(); |
42 | Compass(); |
43 | ShowAzimuth(); |
44 | } |
45 | void MakeAnglesDependentOnMouse() //For testing only. |
46 | { |
47 | v2= new PVector(); |
48 | v1= new PVector(W/2, H/2); |
49 | v2.x=mouseX; |
50 | v2.y=mouseY; |
51 | Bank = PVector.angleBetween(v1, v2); |
52 | Pitch=mouseY-H/2; |
53 | Azimuth=(180/PI*10*Bank)%360; |
54 | } |
55 | void Horizon() |
56 | { |
57 | scale(ArtificialHoizonMagnificationFactor); |
58 | noStroke(); |
59 | fill(0, 180, 255); |
60 | rect(0, -100, 900, 1000); |
61 | fill(95, 55, 40); |
62 | rotate(-Bank); |
63 | rect(0, 400+Pitch, 900, 800); |
64 | rotate(Bank); |
65 | rotate(-PI-PI/6); |
66 | SpanAngle=120; |
67 | NumberOfScaleMajorDivisions=12; |
68 | NumberOfScaleMinorDivisions=24; |
69 | CircularScale(); |
70 | rotate(PI+PI/6); |
71 | rotate(-PI/6); |
72 | CircularScale(); |
73 | rotate(PI/6); |
74 | } |
75 | void ShowAzimuth() |
76 | { |
77 | fill(50); |
78 | noStroke(); |
79 | rect(20, 470, 440, 50); |
80 | int Azimuth1=round(Azimuth); |
81 | textAlign(CORNER); |
82 | textSize(35); |
83 | fill(255); |
84 | text("Azimuth: "+Azimuth1+" Deg", 80, 477, 500, 60); |
85 | } |
86 | void Compass() |
87 | { |
88 | translate(2*W/3, 0); |
89 | scale(CompassMagnificationFactor); |
90 | noFill(); |
91 | stroke(100); |
92 | strokeWeight(80); |
93 | ellipse(0, 0, 750, 750); |
94 | strokeWeight(50); |
95 | stroke(50); |
96 | fill(0, 0, 40); |
97 | ellipse(0, 0, 610, 610); |
98 | for (int k=255;k>0;k=k-5) |
99 | { |
100 | noStroke(); |
101 | fill(0, 0, 255-k); |
102 | ellipse(0, 0, 2*k, 2*k); |
103 | } |
104 | strokeWeight(20); |
105 | NumberOfScaleMajorDivisions=18; |
106 | NumberOfScaleMinorDivisions=36; |
107 | SpanAngle=180; |
108 | CircularScale(); |
109 | rotate(PI); |
110 | SpanAngle=180; |
111 | CircularScale(); |
112 | rotate(-PI); |
113 | fill(255); |
114 | textSize(60); |
115 | textAlign(CENTER); |
116 | text("W", -375, 0, 100, 80); |
117 | text("E", 370, 0, 100, 80); |
118 | text("N", 0, -365, 100, 80); |
119 | text("S", 0, 375, 100, 80); |
120 | textSize(30); |
121 | text("COMPASS-01", 0, -130, 500, 80); |
122 | rotate(PI/4); |
123 | textSize(40); |
124 | text("NW", -370, 0, 100, 50); |
125 | text("SE", 365, 0, 100, 50); |
126 | text("NE", 0, -355, 100, 50); |
127 | text("SW", 0, 365, 100, 50); |
128 | rotate(-PI/4); |
129 | CompassPointer(); |
130 | } |
131 | void CompassPointer() |
132 | { |
133 | rotate(PI+radians(Azimuth)); |
134 | stroke(0); |
135 | strokeWeight(4); |
136 | fill(100, 255, 100); |
137 | triangle(-20, -210, 20, -210, 0, 270); |
138 | triangle(-15, 210, 15, 210, 0, 270); |
139 | ellipse(0, 0, 45, 45); |
140 | fill(0, 0, 50); |
141 | noStroke(); |
142 | ellipse(0, 0, 10, 10); |
143 | triangle(-20, -213, 20, -213, 0, -190); |
144 | triangle(-15, -215, 15, -215, 0, -200); |
145 | rotate(-PI-radians(Azimuth)); |
146 | } |
147 | void Plane() |
148 | { |
149 | fill(0); |
150 | strokeWeight(1); |
151 | stroke(0, 255, 0); |
152 | triangle(-20, 0, 20, 0, 0, 25); |
153 | rect(110, 0, 140, 20); |
154 | rect(-110, 0, 140, 20); |
155 | } |
156 | void CircularScale() |
157 | { |
158 | float GaugeWidth=800; |
159 | textSize(GaugeWidth/30); |
160 | float StrokeWidth=1; |
161 | float an; |
162 | float DivxPhasorCloser; |
163 | float DivxPhasorDistal; |
164 | float DivyPhasorCloser; |
165 | float DivyPhasorDistal; |
166 | strokeWeight(2*StrokeWidth); |
167 | stroke(255); |
168 | float DivCloserPhasorLenght=GaugeWidth/2-GaugeWidth/9-StrokeWidth; |
169 | float DivDistalPhasorLenght=GaugeWidth/2-GaugeWidth/7.5f-StrokeWidth; |
170 | for (int Division=0;Division<NumberOfScaleMinorDivisions+1;Division++) |
171 | { |
172 | an=SpanAngle/2+Division*SpanAngle/NumberOfScaleMinorDivisions; |
173 | DivxPhasorCloser=DivCloserPhasorLenght*cos(radians(an)); |
174 | DivxPhasorDistal=DivDistalPhasorLenght*cos(radians(an)); |
175 | DivyPhasorCloser=DivCloserPhasorLenght*sin(radians(an)); |
176 | DivyPhasorDistal=DivDistalPhasorLenght*sin(radians(an)); |
177 | line(DivxPhasorCloser, DivyPhasorCloser, DivxPhasorDistal, DivyPhasorDistal); |
178 | } |
179 | DivCloserPhasorLenght=GaugeWidth/2-GaugeWidth/10-StrokeWidth; |
180 | DivDistalPhasorLenght=GaugeWidth/2-GaugeWidth/7.4f-StrokeWidth; |
181 | for (int Division=0;Division<NumberOfScaleMajorDivisions+1;Division++) |
182 | { |
183 | an=SpanAngle/2+Division*SpanAngle/NumberOfScaleMajorDivisions; |
184 | DivxPhasorCloser=DivCloserPhasorLenght*cos(radians(an)); |
185 | DivxPhasorDistal=DivDistalPhasorLenght*cos(radians(an)); |
186 | DivyPhasorCloser=DivCloserPhasorLenght*sin(radians(an)); |
187 | DivyPhasorDistal=DivDistalPhasorLenght*sin(radians(an)); |
188 | if (Division==NumberOfScaleMajorDivisions/2|Division==0|Division==NumberOfScaleMajorDivisions) |
189 | { |
190 | strokeWeight(15); |
191 | stroke(0); |
192 | line(DivxPhasorCloser, DivyPhasorCloser, DivxPhasorDistal, DivyPhasorDistal); |
193 | strokeWeight(8); |
194 | stroke(100, 255, 100); |
195 | line(DivxPhasorCloser, DivyPhasorCloser, DivxPhasorDistal, DivyPhasorDistal); |
196 | } |
197 | else |
198 | { |
199 | strokeWeight(3); |
200 | stroke(255); |
201 | line(DivxPhasorCloser, DivyPhasorCloser, DivxPhasorDistal, DivyPhasorDistal); |
202 | } |
203 | } |
204 | } |
205 | void Axis() |
206 | { |
207 | stroke(255, 0, 0); |
208 | strokeWeight(3); |
209 | line(-115, 0, 115, 0); |
210 | line(0, 280, 0, -280); |
211 | fill(100, 255, 100); |
212 | stroke(0); |
213 | triangle(0, -285, -10, -255, 10, -255); |
214 | triangle(0, 285, -10, 255, 10, 255); |
215 | } |
216 | void ShowAngles() |
217 | { |
218 | textSize(30); |
219 | fill(50); |
220 | noStroke(); |
221 | rect(-150, 400, 280, 40); |
222 | rect(150, 400, 280, 40); |
223 | fill(255); |
224 | Pitch=Pitch/5; |
225 | int Pitch1=round(Pitch); |
226 | Bank=Bank*180/PI; |
227 | int Bank1=round(Bank); |
228 | text("Pitch: "+Pitch1+" Deg", -20, 411, 500, 60); |
229 | text("Bank: "+Bank1+" Deg", 280, 411, 500, 60); |
230 | } |
231 | void Borders() |
232 | { |
233 | noFill(); |
234 | stroke(0); |
235 | strokeWeight(400); |
236 | rect(0, 0, 1100, 1100); |
237 | strokeWeight(200); |
238 | ellipse(0, 0, 1000, 1000); |
239 | fill(0); |
240 | noStroke(); |
241 | rect(4*W/5, 0, W, 2*H); |
242 | rect(-4*W/5, 0, W, 2*H); |
243 | } |
244 | void PitchScale() |
245 | { |
246 | stroke(255); |
247 | fill(255); |
248 | strokeWeight(3); |
249 | textSize(24); |
250 | textAlign(CENTER); |
251 | for (int i=-4;i<5;i++) |
252 | { |
253 | if ((i==0)==false) |
254 | { |
255 | line(110, 50*i, -110, 50*i); |
256 | } |
257 | text(""+i*10, 140, 50*i, 100, 30); |
258 | text(""+i*10, -140, 50*i, 100, 30); |
259 | } |
260 | textAlign(CORNER); |
261 | strokeWeight(2); |
262 | for (int i=-9;i<10;i++) |
263 | { |
264 | if ((i==0)==false) |
265 | { |
266 | line(25, 25*i, -25, 25*i); |
267 | } |
268 | } |
269 | } |
270 | |
271 | } |
https://forum.processing.org/one/topic/artificial-horizon-compass-18-4-2013.html
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1014266 |
Snippet name: | Artificial Horizon+Compass (Processing, WORKS) |
Eternal ID of this version: | #1014266/11 |
Text MD5: | 3d5c8a16fb05ae58c62be6b7d25a2e82 |
Transpilation MD5: | 561c20b5426bce589980bd1f3e6a6f52 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-04-19 15:31:14 |
Source code size: | 6564 bytes / 271 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 455 / 1087 |
Version history: | 10 change(s) |
Referenced in: | [show references] |