OSDN Git Service

Appendix
[psychlops/cpp_document.git] / Psychlops.manual / sample_cpp_file / exam / Canvas_lastFailedFrames()1.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;
3
4 void ullmancylinder() {
5         const int DOTCNT = 15000;
6
7         int dotcnt = 100;
8         double bg_lum = 0.0;
9         double velocity = 1.0;
10         double SOA_pp;
11         int SIZE = 3;
12         int SOA = 1;
13         double CylinderRadius=200;
14         int a1=0;
15         
16         Range rng;
17         Independent << dotcnt   | "Number of Dots" |   1< rng< DOTCNT |  10   | 1000 ;
18         Independent << velocity | "Dot Velocity"   | 0.0<=rng<=10.0   |  0.1 | 0.05;
19         Independent << SOA      | "SOA Frames"     |   1.0<=rng<=60.0     |  1   | 1;
20         Independent << bg_lum   | "Luminance Inv." | 0.0<=rng<=1.0    |  1   | 1;
21         Independent << SIZE     | "Dot Size"       |   0< rng<=10    |  1   | 1;
22         Independent << CylinderRadius|  "Cylinder Size"  |  0< rng<= 400   |  1   | 50;
23
24
25         Canvas canvas(Canvas::fullscreen);
26         Psychlops::Rectangle rect(SIZE,SIZE);
27         Psychlops::Color bgcolor(0), dotcolor(1.0-bg_lum);
28
29         double phase=0.0;
30         double x[DOTCNT], dx[DOTCNT], y[DOTCNT];
31
32         for(int i=0; i<DOTCNT; i++) {
33                 x[i] = Psychlops::random(CylinderRadius*2*PI);
34                 y[i] = Psychlops::random(CylinderRadius*2)+200;
35         }
36         Display::watchFPS();
37         while(!Input::get(Keyboard::spc)) {
38                 bgcolor.set(bg_lum);
39                 dotcolor.set(1.0-bg_lum);
40                 canvas.clear(bgcolor);
41                 rect.resize(SIZE,SIZE);
42
43                 phase += velocity;      
44                 SOA_pp =SOA+1;
45
46                 for(int i=0; i<DOTCNT; i++)     dx[i] = (int)(CylinderRadius*sin(x[i]+SOA_pp*phase/100.0))+canvas.getHcenter();//\8ae\83h\83b\83g\88Ê\92u\82Ì\8cv\8eZ
47                 for(int i=0; i<dotcnt; i++)     rect.centering(dx[i], y[i]).draw(dotcolor);
48                 //\97\8e\82¿\82½\83t\83\8c\81[\83\80\90\94\82ð\95Ô\82µ\82Ü\82·
49                 a1=Display::lastFailedFrames();
50                 if(a1)Display::clear(Color(0.25,0.25,0.25));
51                 Display::showFPS();
52                 canvas.flip(SOA);
53         }
54 }
55
56
57 void psychlops_main()
58 {
59
60         Procedure p;
61         p.setDesign(Procedure::DEMO);
62         p.setProcedure(ullmancylinder);
63         p.run();
64
65 }