| 12
 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
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 
 |  
 
var spectral_line = [ 0, 
    7621.0,       // A
    6869.955,      // B
    6562.816,      // C
    5895.944,      // D
    5269.557,      // E
    4861.344,      // F
    4340.477,      // G'
    3968.494      // H
    ];
 
    var refarr = [  /* Reference results.  These happen to
                       be derived from a run on Microsoft 
                       Quick BASIC on the IBM PC/AT. */
 
    "   Marginal ray          47.09479120920   0.04178472683",
    "   Paraxial ray          47.08372160249   0.04177864821",
    "Longitudinal spherical aberration:        -0.01106960671",
    "    (Maximum permissible):                 0.05306749907",
        "Offense against sine condition (coma):     0.00008954761",
        "    (Maximum permissible):                 0.00250000000",
        "Axial chromatic aberration:                0.00448229032",
        "    (Maximum permissible):                 0.05306749907"
                                                    ];
 
                                                    /*  The test case used in this program is the design for a 4 inch
                                                        achromatic telescope objective used as the example in Wyld's
                                                        classic work on ray tracing by hand, given in Amateur Telescope
                                                        Making, Volume 3. */
 
                                                    var testcase = [
                                                    [ 27.05, 1.5137, 63.6, 0.52 ],
                                                    [ -16.68, 1, 0, 0.138 ],
                                                    [ -16.68, 1.6164, 36.7, 0.38 ],
                                                    [ -78.1, 1, 0, 0 ]
                                                    ];
 
                                                    var current_surfaces, paraxial, clear_aperture, aberr_lspher,
                                                    aberr_osc, aberr_lchrom, max_lspher, max_osc, max_lchrom,
                                                    radius_of_curvature, object_distance, ray_height,
                                                    axis_slope_angle, from_index, to_index;
 
var s;                    // Design being traced
var od_sa;                  // Object distance and slope angle
 
var outarr;                 // Computed output of program goes here
 
var niter = 1000;      // Iteration counter
 
//  Display a string on the debug console
 
function show(s)
{
         print( s ,100,300);
}
 
 
/*  Perform ray trace in specific spectral line  */
 
function trace_line(line, ray_h) {
        var i;
 
        object_distance = 0;
        ray_height = ray_h;
        from_index = 1;
 
        for (i = 0; i < current_surfaces; i++) {
                radius_of_curvature = s[i][0];
                to_index = s[i][1];
                if (to_index > 1.0) {
                        to_index = to_index + ((spectral_line[4] -
                                                spectral_line[line]) /
                                        (spectral_line[3] - spectral_line[6])) * ((s[i][1] - 1) /
                                                s[i][2]);
                }
                transit_surface();
                from_index = to_index;
                if (i < current_surfaces) {
                        object_distance = object_distance - s[i][3];
                }
        }
}
 
/*      Calculate passage through surface
 
        If the variable PARAXIAL is true, the trace through the
        surface will be done using the paraxial approximations.
        Otherwise, the normal trigonometric trace will be done.
 
        This subroutine takes the following global inputs:
 
        radius_of_curvature     Radius of curvature of surface
        being crossed.  If 0, surface is
        plane.
 
        object_distance       Distance of object focus from
        lens vertex.  If 0, incoming
        rays are parallel and
        the following must be specified:
 
        ray_height            Height of ray from axis.  Only
        relevant if object_distance == 0
 
        axis_slope_angle        Angle incoming ray makes with axis
        at intercept
 
        from_index        Refractive index of medium being left
 
        to_index          Refractive index of medium being
        entered.
 
        The outputs are the following global variables:
 
        object_distance      Distance from vertex to object focus
        after refraction.
 
        axis_slope_angle      Angle incoming ray makes with axis
        at intercept after refraction.
 */
 
function transit_surface() {
        var iang,            /* Incidence angle */
            rang,            /* Refraction angle */
            iang_sin,            /* Incidence angle sin */
            rang_sin,            /* Refraction angle sin */
            old_axis_slope_angle, sagitta;
 
        if (paraxial) {
                if (radius_of_curvature != 0) {
                        if (object_distance == 0) {
                                axis_slope_angle = 0;
                                iang_sin = ray_height / radius_of_curvature;
                        } else {
                                iang_sin = ((object_distance - radius_of_curvature) /
                                                radius_of_curvature) * axis_slope_angle;
                        }
                        rang_sin = (from_index / to_index) * iang_sin;
                        old_axis_slope_angle = axis_slope_angle;
                        axis_slope_angle = axis_slope_angle + iang_sin - rang_sin;
                        if (object_distance != 0) {
                                ray_height = object_distance * old_axis_slope_angle;
                        }
                        object_distance = ray_height / axis_slope_angle;
                        return;
                }
                object_distance = object_distance * (to_index / from_index);
                axis_slope_angle = axis_slope_angle * (from_index / to_index);
                return
        }
 
        if (radius_of_curvature != 0) {
                if (object_distance == 0) {
                        axis_slope_angle = 0;
                        iang_sin = ray_height / radius_of_curvature;
                } else {
                        iang_sin = ((object_distance - radius_of_curvature) /
                                        radius_of_curvature) * Math.sin(axis_slope_angle);
                }
                iang = Math.asin(iang_sin);
                rang_sin = (from_index / to_index) * iang_sin;
                old_axis_slope_angle = axis_slope_angle;
                axis_slope_angle = axis_slope_angle + iang - Math.asin(rang_sin);
                sagitta = Math.sin((old_axis_slope_angle + iang) / 2);
                sagitta = 2 * radius_of_curvature * sagitta * sagitta;
                object_distance = ((radius_of_curvature * Math.sin(
                                                old_axis_slope_angle + iang)) *
                                (1 / Math.tan(axis_slope_angle))) + sagitta;
                return;
        }
 
        rang = -Math.asin((from_index / to_index) * Math.sin(axis_slope_angle))
                object_distance = object_distance * ((to_index *
                                        Math.cos(-rang)) / (from_index *
                                        Math.cos(axis_slope_angle)));
        axis_slope_angle = -rang;
}
 
//  Format a floating point number as does C "%.11f"
 
function fnum(n) {
        var s = n.toFixed(11);
        if (n >= 0) {
                s = " " + s;
        }
        return s;
}
 
//  Run the benchmark for the specified number of iterations
 
function RunBenchmark() {
        var start, stop;
 
        // Load test case into working array
 
        clear_aperture = 4;
        current_surfaces = 4;
        s = testcase;
 
        axis_slope_angle = 0;
        od_sa = [ [0, 0], [0, 0]];
 
        niter = 1000;
 
        start = new Date();
        for (itercount = 0; itercount < niter; itercount++) {
                for (paraxial = 0; paraxial <= 1; paraxial++) {
 
                        // Do main trace in D light
 
                        trace_line(4, clear_aperture / 2);
                        od_sa[paraxial][0] = object_distance;
                        od_sa[paraxial][1] = axis_slope_angle;
                }
 
                paraxial = 0;
 
                // Trace marginal ray in C
 
                trace_line(3, clear_aperture / 2);
                od_cline = object_distance;
 
                // Trace marginal ray in F
 
                trace_line(6, clear_aperture / 2);
                od_fline = object_distance;
 
                aberr_lspher = od_sa[1][0] - od_sa[0][0];
                aberr_osc = (1.0 - (od_sa[1][0] * od_sa[1][1]) /
                                (Math.sin(od_sa[0][1]) * od_sa[0][0]));
                aberr_lchrom = od_fline - od_cline;
                max_lspher = Math.sin(od_sa[0][1]);
 
                // D light
 
                max_lspher = 0.0000926 / (max_lspher * max_lspher);
                max_osc = 0.0025;
                max_lchrom = max_lspher;
        }
        stop = new Date();
 
        var mstime = stop.getTime() - start.getTime();
        show("Elapsed time in seconds: " + (mstime / 1000).toFixed(3));
        show("Time for 1000 iterations: " + ((mstime / 1000) * (1000.0 / niter)).toFixed(4));
 
        outarr = [
                "   Marginal ray         " + fnum(od_sa[0][0]) + "  " + fnum(od_sa[0][1]),
                "   Paraxial ray         " + fnum(od_sa[1][0]) + "  " + fnum(od_sa[1][1]),
                "Longitudinal spherical aberration:        " + fnum(aberr_lspher),
                "    (Maximum permissible):                " + fnum(max_lspher),
                "Offense against sine condition (coma):    " + fnum(aberr_osc),
                "    (Maximum permissible):                " + fnum(max_osc),
                "Axial chromatic aberration:               " + fnum(aberr_lchrom),
                "    (Maximum permissible):                " + fnum(max_lchrom)
                                                               ];
 
        errors = 0;
        for (i = 0; i < refarr.length; i++) {
                if (refarr[i] != outarr[i]) {
                        var e;
 
                        errors += 1;
                        show("Error in results on line " + (i + 1));
                        show("Expected: " + refarr[i]);
                        show("Received: " + outarr[i]);
                        e = "";
                        for (j = 0; j < refarr[i].length; j++) {
                                if (refarr[i][j] == outarr[i][j]) {
                                        e += " ";
                                } else {
                                        e += "^";
                                }
                        }
                        show("(Errors)  " + e);
                }
        }
 
        if (errors > 0) {
                show("" + errors + " error" + ((errors > 1) ? "s" : "") + " in results.  This is VERY SERIOUS.");
        } else {
                show("No errors in results.");
        }
}
 
 
 
var FN = "/.fonts/";
var test = true;
var tick=0;
var begin=0;
 
 
 
 
 
 
function print(text,x,y) {
        var back = new TRectangle(x, y, 200, 50, 0xFFFFFF);
        var hello = new TText(text, x, y, 0, 'Vera', 22);
        back.setSize(hello.width, hello.height);
 
}
 
 
 
 
 
var a = new Array();
var b = new Array();
 
 
function DisplayPrimeNumbers(nombre) {
        var this_number,divisor,not_prime;
        this_number = 3;
        while(this_number < nombre) {
                divisor = parseInt( this_number / 2);
                not_prime = 0;
                while(divisor > 1) {
                        if(this_number % divisor == 0) {
                                not_prime = 1;
                                divisor = 0;
                        } else {
                                divisor = divisor - 1;
                        }
                }
                if(not_prime == 0) {
                        return this_number;
                } else {
                        return -1
                }
                this_number = this_number + 1;
        }
}
 
 
function bench() {
        var result=0;
        for (var j = 0 ; i < 100000 ; i++ ) {
                for (var i = 0 ; i < 10000 ; i++ ) {
                        a[i] = i*3+7.9+j;
                        b[i] = 7*i+5.7+j;
                }
        }
        for (var j = 0 ; i < 100000 ; i++ ) {
                for (var i = 0 ; i < 10000 ; i++ ) {
                        result += a[i]-b[i] % 10000 + j;
                }
        }
        return result;
}
 
function isPrime(n) {
        prime = true;
        for (var i = 3; i <= Math.sqrt(n); i += 2)
                if (n % i == 0) {
                        prime = false;
                        break;
                }
        if (( n%2 !=0 && prime && n > 2) || n == 2) {
                return n;
        } else {
                return -1;
        }
}
 
var ccres=0;
 
function main()
{
        var bg;
        var obj;
        var deb=0;
        elx.print(DisplayPrimeNumbers(2147483647));
 
        elx.print("Rock n Roll " + elx.version() + "\n");
        elx.include('Cauldron.js');
        ecore_timer_add(1, function () { tick++}, null);
 
        var back = new TRectangle(10, 10, 100, 50, 0xFFFFFF);
        var hello = new TText('Hello World !', 10, 10, 0, 'Vera', 22);
        back.setSize(hello.width, hello.height);
 
        var obj = new TRectangle(50, 50, 250, 200, 0x804000);
 
        var anim = new TAnimator();
        anim.onChange = function() {
                var x = obj.x ;
                var y = obj.y ;
 
                if (begin == 0) {
                        x = 50;
                        y = 50;
                } else if (begin == 1) {
                        x = 100;
                        y = 100;
                } else if (begin == 2) {
                        x = 200;
                        y = 200;
                }
                obj.move(x, y);
        }
 
        anim.setSpeed(1/5);
 
        anim.start();
 
        screen.onKeyup = function(event) {
                switch (event.keyname) {
                        /*   case 'GP/Up' : hello.setStyle('outline', 0xFF0000); break;
                             case 'GP/Down' : hello.setStyle('glow', 0xFF00FF); break;
                             case 's' : hello.setStyle('shadow', 0x0000FF, 128); break;
                             case 'f' :
                             hello.setStyle('shadow', 0xFF0000);
                             evas_object_text_style_set(hello.handle, EVAS_TEXT0YLE_FAR_SHADOW); break;
                             case 'd' :   print("tick : "+tick,200,300);break;*/
                        case 'l' : deb=event.timestamp;
                                   begin=1;
                                   elx.print("debut="+deb + "\n");
                                   print('precedent='+ccres,0,100);
                                    RunBenchmark();
                                   begin=2;
                                   deb = event.timestamp-deb;
                                   print('Temps ecoule : '+deb,0,150);
                                   hello.setStyle('outline', 0xFF0000); 
                                   elx.print("fin="+event.timestamp+" soit "+deb + "\n");
                                   break;
                        default  : screen.quit() 
                }
        }
        screen.main(); 
}
 
main(); | 
Partager