4 char * textString = "Let it snow!";
5 define backgroundColor = Color { 10, 0, 60 };
10 background = backgroundColor;
14 borderStyle = sizable;
19 font = { "Comic Sans MS", 40, true };
20 useSharedMemory = true;
22 ColorAlpha * screen, * screenBuffer;
28 Snowing() { RandomSeed((uint)(GetTime() * 100000)); ((GuiApplication)__thisModule).timerResolution = 60; }
41 void OnRedraw(Surface surface)
43 Bitmap bitmap = ((LFBDisplay)display.driverData).bitmap;
45 if(buffer.width != bitmap.width || buffer.height != bitmap.height)
48 int len = strlen(textString);
49 stride = bitmap.stride;
50 buffer.Allocate(null, bitmap.width, bitmap.height, stride, pixelFormat888, false);
51 surface.TextExtent(textString, strlen(textString), &tw, &th);
55 screen = (ColorAlpha*)bitmap.picture + (surface.offset.y * stride) + surface.offset.x;
56 screenBuffer = (ColorAlpha*)buffer.picture + (surface.offset.y * stride) + surface.offset.x;
57 surface.background = backgroundColor;
58 surface.Area(0,0, w-1, h-1);
59 surface.WriteText((clientSize.w - tw)/2, (clientSize.h - th)/2, textString, len);
62 XSync(IS_XGetDisplay()); // TODO: Need an API for this...
65 memcpy(buffer.picture, bitmap.picture, buffer.sizeBytes);
72 for(y = lastLine; y >= 0; y--)
74 int offset = y * stride;
75 bool isLastLine = true;
76 for(x = 0; x < w; x++, offset++)
78 if(screen[offset].color == white)
83 if(isLastLine) lastLine = y-1;
85 memcpy(bitmap.picture, buffer.picture, buffer.sizeBytes);
92 for(c = 0; c < NUMFLAKES; c++)
93 screenBuffer[GetRandom(0, w-1)] = white;
95 bool SnowTo(int offset, int add)
98 if(screen[add].color != backgroundColor)
100 screenBuffer[add] = white;
101 screenBuffer[offset] = backgroundColor;
104 void SnowDown(int offset)
106 if(offset < (h-2)*stride + w)
108 bool atLeft = (offset % stride) <= 0;
109 bool atRight = (offset % stride) >= w - 1;
110 switch(GetRandom(0, 2))
113 if(!SnowTo(offset, stride))
115 if(GetRandom(0, 4) == 0)
118 (!atLeft && SnowTo(offset, stride-1)) || (!atRight && SnowTo(offset, stride+1));
120 (!atRight && SnowTo(offset, stride+1)) || (!atLeft && SnowTo(offset, stride-1));
124 case 1: (!atLeft && SnowTo(offset, stride-1)) || (GetRandom(0, 4) == 0 && SnowTo(offset, stride)) || (!atRight && SnowTo(offset, stride+1)); break;
125 case 2: (!atRight && SnowTo(offset, stride+1)) || (GetRandom(0, 4) == 0 && SnowTo(offset, stride)) || (!atLeft && SnowTo(offset, stride-1)); break;