Changeset 3219 for libcaca


Ignore:
Timestamp:
Nov 2, 2008, 9:17:00 PM (11 years ago)
Author:
bsittler
Message:

convert to PHP and make executable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/truecolor.php

    • Property svn:executable set to *
    r3218 r3219  
     1#!/usr/bin/php5
     2<?php
    13/*
    2  *  truecolor     truecolor canvas features
     4 *  truecolor     truecolor canvas features
     5 *  Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
     6 *
     7 *  This file is a Php port of "examples/truecolor.c"
     8 *  which is:
    39 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
    4  *                All Rights Reserved
     10 *                All Rights Reserved
    511 *
    612 *  $Id$
     
    1319 */
    1420
    15 #include "config.h"
    16 
    17 #if !defined(__KERNEL__)
    18 #   include <stdio.h>
    19 #endif
    20 
    21 #include "caca.h"
    22 
    23 int main(int argc, char *argv[])
    24 {
    25     caca_canvas_t *cv;
    26     caca_display_t *dp;
    27 
    28     int x, y;
    29 
    30     cv = caca_create_canvas(32, 16);
    31     if(cv == NULL)
    32     {
    33         printf("Failed to create canvas\n");
    34         return 1;
    35     }
    36 
    37     dp = caca_create_display(cv);
    38     if(dp == NULL)
    39     {
    40         printf("Failed to create display\n");
    41         return 1;
    42     }
    43 
    44     for(y = 0; y < 16; y++)
    45         for(x = 0; x < 16; x++)
    46     {
    47         uint16_t bgcolor = 0xff00 | (y << 4) | x;
    48         uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8);
    49 
    50         caca_set_color_argb(cv, fgcolor, bgcolor);
    51         caca_put_str(cv, x * 2, y, "CA");
    52     }
    53 
    54     caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE);
    55     caca_put_str(cv, 2, 1, " truecolor libcaca ");
    56 
    57     caca_refresh_display(dp);
    58 
    59     caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
    60 
    61     caca_free_display(dp);
    62     caca_free_canvas(cv);
    63 
    64     return 0;
     21$cv = caca_create_canvas(32, 16);
     22if(!$cv) {
     23        die("Failed to create canvas\n");
    6524}
    6625
     26$dp = caca_create_display($cv);
     27if(!$dp) {
     28        die("Failed to create display\n");
     29}
     30
     31for($y = 0; $y < 16; $y++)
     32        for($x = 0; $x < 16; $x++)
     33        {
     34                $bgcolor = 0xff00 | ($y << 4) | $x;
     35                $fgcolor = 0xf000 | ((15 - $y) << 4) | ((15 - $x) << 8);
     36               
     37                caca_set_color_argb($cv, $fgcolor, $bgcolor);
     38                caca_put_str($cv, $x * 2, $y, "CA");
     39        }
     40
     41caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
     42caca_put_str($cv, 2, 1, " truecolor libcaca ");
     43
     44caca_refresh_display($dp);
     45
     46caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
     47
     48?>
Note: See TracChangeset for help on using the changeset viewer.