~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to packages/extra/ptc/examples/hicolor.pp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
Ported to FPC by Nikolay Nikolov (nickysn@users.sourceforge.net)
 
3
}
 
4
 
 
5
{
 
6
 HiColor example for OpenPTC 1.0 C++ Implementation
 
7
 Copyright (c) Glenn Fiedler (ptc@gaffer.org)
 
8
 This source code is in the public domain
 
9
}
 
10
 
 
11
Program HiColorExample;
 
12
 
 
13
{$MODE objfpc}
 
14
 
 
15
Uses
 
16
  ptc;
 
17
 
 
18
Var
 
19
  console : TPTCConsole;
 
20
  surface : TPTCSurface;
 
21
  format : TPTCFormat;
 
22
  pixels : Pshort16;
 
23
  width, height : Integer;
 
24
  i : Integer;
 
25
  x, y, r, g, b : Integer;
 
26
 
 
27
Begin
 
28
  format := Nil;
 
29
  surface := Nil;
 
30
  console := Nil;
 
31
  Try
 
32
    Try
 
33
      { create console }
 
34
      console := TPTCConsole.Create;
 
35
 
 
36
      { create format }
 
37
      format := TPTCFormat.Create(16, $F800, $07E0, $001F);
 
38
 
 
39
      { open the console }
 
40
      console.open('HiColor example', format);
 
41
 
 
42
      { create surface matching console dimensions }
 
43
      surface := TPTCSurface.Create(console.width, console.height, format);
 
44
 
 
45
      { loop until a key is pressed }
 
46
      While Not console.KeyPressed Do
 
47
      Begin
 
48
        { lock surface }
 
49
        pixels := surface.lock;
 
50
        Try
 
51
          { get surface dimensions }
 
52
          width := surface.width;
 
53
          height := surface.height;
 
54
 
 
55
          { draw random pixels }
 
56
          For i := 1 To 100 Do
 
57
          Begin
 
58
            { get random position }
 
59
            x := Random(width);
 
60
            y := Random(height);
 
61
 
 
62
            { get random color }
 
63
            r := Random(256);
 
64
            g := Random(256);
 
65
            b := Random(256);
 
66
 
 
67
            { draw color [r,g,b] at position [x,y] }
 
68
            pixels[x + y * width] := ((r And $00F8) Shl 8) Or
 
69
                                     ((g And $00FC) Shl 3) Or
 
70
                                     ((b And $00F8) Shr 3);
 
71
          End;
 
72
        Finally
 
73
          { unlock surface }
 
74
          surface.unlock;
 
75
        End;
 
76
 
 
77
        { copy to console }
 
78
        surface.copy(console);
 
79
 
 
80
        { update console }
 
81
        console.update;
 
82
      End;
 
83
    Finally
 
84
      console.close;
 
85
      console.Free;
 
86
      surface.Free;
 
87
      format.Free;
 
88
    End;
 
89
  Except
 
90
    On error : TPTCError Do
 
91
      { report error }
 
92
      error.report;
 
93
  End;
 
94
End.