File: pimage.html

package info (click to toggle)
roxen 1.2beta2-2
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 16,948 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,787; cpp: 377
file content (124 lines) | stat: -rw-r--r-- 3,124 bytes parent folder | download | duplicates (3)
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
<!-- -*-pike-*- -->

<body bgcolor=white text=black>

<pimage nocache>
object draw()
{
  return Clock(30,2200, Dial(), "#aa9999", 54);
}
</pimage>


<pimage notrans>
object draw()
{
  return Clock(30,0, Roxen(), "#bb7700");
}
</pimage>

<p>
<br clear=left>
<p>

<pimage nocache>
#20 "pimage.html"
#define HEIGHT 59*2
#define WIDTH 145*2

object roxen_image;
int frame_no= 7;
mapping vertical_wiggly_images = ([]);
// The number of vertical wigglie frames (what to call them?).
#define STEPS 20

// A white and a black image. Pasted with an alpha value over the
// image to generate shadow and highlight regions
object highlight = image(1,HEIGHT,255,255,255);
object shadow = image(1,HEIGHT+4,0,0);

object frame()
{
  float offset, doffset, oldoffset;
  int cache_index;
  object  current;
  frame_no++;

  cache_index = frame_no % STEPS ;
  int ys = roxen_image->ysize();
  int xs = roxen_image->xsize();
  
  if(vertical_wiggly_images[ cache_index ])
    current = vertical_wiggly_images[ cache_index ]->copy();
  else
  {
    // Generate a new image for one wiggly direction, and add highlights.
    // The magic numbers (15, 14 etc) have beed manualy adjusted.
    //  There are no deep thoughts behinds them....
    current = roxen_image->copy();
    for(int i=15; i<xs-14; i++)
    {
      offset = (sin((frame_no/(float)STEPS+i*0.01) * 2*3.1415)*10);
      doffset = offset - oldoffset;
      oldoffset = offset;
      current->paste(current->copy(i,0,i,ys-4), i, (int)offset);
      if(doffset < 0.0)
	current->paste_alpha(highlight,255+(int)(doffset*99),i,(int)offset+18);
      else
	current->paste_alpha(shadow,255-(int)(doffset*300), i,(int)offset+14);
    }
    vertical_wiggly_images[ cache_index ] = current->copy();
  }

  // Move the lines around in the X-direction.
  for(int i=0; i<ys; i++)
  {
    int offset = (int)(sin(((float)frame_no*10+(float)i*20)/360.0)*6);
    if(offset > 0)
      current->paste(current->copy(0,i,xs-offset,i),offset,i);
    else
      current->paste(current->copy(-offset,i,xs+offset+1,i),0,i);
  }

  return current->scale(0.5);
}

object draw()
{
  // Generate a Roxen logotype image, scale it to 50%.
  roxen_image = Roxen();
  // Use white ink.
  roxen_image->setcolor(@parse_color("darkgreen"));
  // Add a white border around the roxen logotype
  roxen_image = roxen_image->copy(-2,-2,roxen_image->xsize()+2,roxen_image->ysize()+2);
  // Use black ink
  roxen_image->setcolor(255,255,255);
  // Generate some empty space around the image. The sizes are quite arbitary
  roxen_image = roxen_image->copy(-15,-15,WIDTH+19,HEIGHT+20)->image;
  // Start an animation, the function 'frame' will be called with a delay of
  // 0.0 seconds (you guessed it, this is _really_ a CPU hog...) when somewone
  // is watching the image (not otherwise, though)
  return Anim(frame, 0.0);
}
</pimage>

<p>
<table bgcolor=black border=0 cellspacing=0 cellpadding=1>
<tr><td><pimage notrans>
   float q=1.0;
   int t()
   {
     if(q<=100.0) q+=0.1; else q=0.0;
     return (int)(q);
   }

   object draw()
   {
     return Progress( t );
   }
</pimage></td></tr>
</table>

      
</body>