Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

comment creer un economiseur d ecran pour mac os x

Aucune réponse
Avatar
serge.john.swilting
ja i le texte de matrix screen saver pour pc linux et j aimerais l adapter
pour mac os x

comment faire

/* -*- C -*-
* matrix_saver.c: Screen saver based on "The Matrix"
* Copyright (C) 1999 Andrew Arensburger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/* matrix_saver
*
* This is a screen saver inspired by an effect in the 1999 movie,
* "The Matrix". It was more immediately inspired by a cool display
* hack, 'cmatrix', by Chris Allegretta. I wound up not using any of
* his code, but I guess this is still in some sense based on his
* work.
*
* $Id: matrix_saver.c,v 1.4 2001/02/18 14:23:02 arensb Exp $
*
* 28apr99 amcl
* Converted lkm to kld.
*/

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/consio.h>
#include <sys/fbio.h>

#include <machine/pc/display.h>

#include <dev/fb/fbreg.h>
#include <dev/fb/splashreg.h>
#include <dev/syscons/syscons.h>

static u_short *window;
static int blanked;

/* Columns:
* The screen saver displays a number of falling columns. Each column
* consists of an optional head (a white "&"), some random characters
* above that, and some blanks above that.
*
* 'lengths[x]' gives the total length of the column at x.
*
* 'tails[x]' is initially always less than 'lengths[x]', and gives
* the number of blanks that terminate the column. 'lengths[x]' is
* decremented each time the column is dropped, so when 'lengths[x]'
* becomes less than 'tails[x]', we should draw a blank, rather than a
* random character.
*
* 'speeds[x]' gives the speed of the screen column at x. See the
* "speeds" comment, below.
*/
static char *lengths = NULL;
static char *tails = NULL;
static char *speeds = NULL;

/* Speeds:
* Each column has a speed in the range 0..NUM_SPEEDS-1. The higher
* the speed, the faster the column falls. The array 'beat_map',
* below, is fairly magical, and has been specially set up for a
* length of 16. So don't change NUM_SPEEDS without studying this
* code.
*
* Think of the main loop (matrix_saver()) as counting beats, at 16
* beats per measure: 0, 1, 2, ...15, 0, 1, 2, ... 15, and so forth.
* The simple thing to do would be to drop each column if its speed is
* greater than or equal to the current beat. But this looks jerky and
* ugly: a column with a speed of 7, for instance, stays immobile for
* 8 beats, then drops 8 columns quickly; what we really want is for
* it to drop one line every other beat. A column with a speed of 3
* should drop by one line every four beats, and so forth.
*
* The 'beat_map' array defines when each column falls: a column falls
* if its speed is greater than or equal to beat_map[beat]. Thus, on
* beat 0, all columns fall whose speed is >= 15; on beat 1, all
* columns fall whose speed is >= 7, and so forth.
*
* XXX - I wish 'beat_map' weren't so magical. If you find a quick way
* to generate it arithmetically (possibly something involving Grey
* codes or standard dithering algorithms), please let me know.
*/
#define NUM_SPEEDS 16
static char beat_map[NUM_SPEEDS] = {
15, 7, 11, 3, 13, 5, 9, 1,
14, 6, 10, 2, 12, 4, 8, 0,
};

/* Convenience macro: the point on the screen at (x, y). Usable either
* as an lvalue or rvalue.
*/
#define SCREEN(x,y) \
*((u_short *) window + ((y) * scp->xsize) + (x))

/* This macro returns a screen value. The bottom part is a random
* character between '!' and '~'.
* The top half is the color. This function looks funky, but the
* effect is that characters closer to the bottom tend to be brighter
* than the ones at the top, so it looks sorta-kinda like the column
* fades out toward its top.
*/
#define COL_CHAR \
(sc->scr_map[(random() % ('~'+1 - '!')) + '!'] | \
((((random() % 10) < (lengths[x] - tails[x])) ? \
FG_LIGHTGREEN : FG_GREEN) << 8))

/* matrix_saver
* Main loop for the screen saver. Most of this is voodoo code.
*/
static int
matrix_saver(video_adapter_t *adp, int blank)
{
sc_softc_t *sc;
scr_stat *scp;
static char beat = 0; /* Current beat. See comment above */
int x, y;

sc = sc_find_softc(adp, NULL);
if (sc == NULL)
return EAGAIN;
scp = sc->cur_scp;

beat++;
beat %= NUM_SPEEDS;

if (blank) {
if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
return EAGAIN;
if (blanked == 0) {
/* Initialize the screen saver */
window = (u_short *)adp->va_window;
blanked = 1;

/* clear the screen and set the border color */
sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
(FG_LIGHTGREY | BG_BLACK) << 8);
(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
sc_set_border(scp, 0);

/* Generate the bottoms of the columns, at the
* top of the screen */
for (x = 0; x < scp->xsize; x++)
SCREEN(x, 0) = COL_CHAR;
}

/* Drop and update each column in turn. */
for (x = 0; x < scp->xsize; x++)
{
if (beat_map[(int) beat] > speeds[x])
/* The current column does not drop on
* this beat. See the "speeds"
* comment, above.
*/
continue;

/* Columns' speeds occasionally change */
if ((random() % 100) == 0)
speeds[x] = random() % NUM_SPEEDS;

/* Drop this column by one space */
for (y = scp->ysize -1; y > 0; y--)
SCREEN(x,y) = SCREEN(x,y-1);

if (lengths[x] <= 0)
{
/* Start a new trail */
if ((random() % 5) == 0)
/* A new trail has a 1 in 5
* chance of having a white
* head ("&").
*/
SCREEN(x, 0) = sc->scr_map['&'] |
(FG_WHITE << 8);
else
SCREEN(x, 0) = COL_CHAR;

/* Pick the length of the inter-trail
* space first, then add to that value
* to get the total length; this
* ensures that trails are never
* empty.
* The numbers here are chosen for
* esthetic value. Go ahead and tweak
* them.
*/
tails[x] = random() % 30;
lengths[x] = tails[x] + (random() % 10) + 5;
} else {
/* We're continuing an existing trail,
* not starting a new one.
*/
if (lengths[x] < tails[x])
/* Draw the inter-trail space */
SCREEN(x, 0) =
sc->scr_map[' '] |
(FG_BLACK << 8);
else
SCREEN(x, 0) = COL_CHAR;
lengths[x]--;
}
}
} else /* Turn off the screen saver */
blanked = 0;

return 0;
}

static int
matrix_init(video_adapter_t *adp)
{
int i;
sc_softc_t *sc;
scr_stat *scp;

sc = sc_find_softc(adp, NULL);
if (sc == NULL)
return EAGAIN;
scp = sc->cur_scp;

/* Allocate the 'lenghts', 'tails' and 'speeds' arrays. They
* have as many entries as there are columns on the screen.
*/
if ((lengths = malloc(scp->xsize, M_DEVBUF, M_WAITOK)) == NULL)
return -1;
if ((tails = malloc(scp->xsize, M_DEVBUF, M_WAITOK)) == NULL)
return -1;
if ((speeds = malloc(scp->xsize, M_DEVBUF, M_WAITOK)) == NULL)
return -1;
for (i = 0; i < scp->xsize; i++)
{
lengths[i] = random() % 20;
tails[i] = (random() % 30) + 5;
speeds[i] = random() % NUM_SPEEDS;
}

return 0;
}

static int
matrix_term(video_adapter_t *adp)
{
free(lengths, M_DEVBUF);
free(tails, M_DEVBUF);
free(speeds, M_DEVBUF);

return 0;
}

static scrn_saver_t matrix_module = {
"matrix_saver", matrix_init, matrix_term, matrix_saver, NULL,
};

SAVER_MODULE(matrix_saver, matrix_module);

Réponses