https://hal.archives-ouvertes.fr/hal-03375509
Revision 6063801811e8f607e9c715f186de95043b4594a8 authored by Software Heritage on 01 September 2018, 00:00:00 UTC, committed by Software Heritage on 13 October 2021, 00:00:00 UTC
0 parent
Tip revision: 6063801811e8f607e9c715f186de95043b4594a8 authored by Software Heritage on 01 September 2018, 00:00:00 UTC
hal: Deposit 1814 in collection hal
hal: Deposit 1814 in collection hal
Tip revision: 6063801
pong.c
/*
* This software is delivered as the Deliverable D2.3 of the ANR
* project Continuum, Ref. Number ANR-15-CE25-0007.
*
* D2.3 - Illustration of system reconfiguration due to varying
* conditions: same-island, and migration
*
* Author: Erven ROHOU
* Copyright (c) Inria
*
* License: GNU AFFERO GENERAL PUBLIC LICENSE v3
*
*/
#include <stdio.h>
#include <string.h>
#define max(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
static const int ball_size = 5;
static unsigned char bg = 0; // black
void pong_init(unsigned char* frame, int w, int h)
{
}
void pong_next(unsigned char* frame, int w, int h)
{
static int x = 0;
static int y = 0;
static int dx = 1;
static int dy = 1;
memset(frame, bg, w*h*4);
#if 0
// Delete previous position
for(int i = max(0, x-ball_size); i <= min(w-1, x+ball_size); i++) {
for(int j = max(0, y-ball_size); j <= min(h-1, y+ball_size); j++) {
frame[(j * w + i) * 4 + 0] = bg;
}
}
#endif
// Move ball
x += dx;
y += dy;
if ((x == 0) || (x == w-1))
dx = -dx;
if ((y == 0) || (y == h-1))
dy = -dy;
// Draw new position
for(int i = max(0, x-ball_size); i <= min(w-1, x+ball_size); i++) {
for(int j = max(0, y-ball_size); j <= min(h-1, y+ball_size); j++) {
frame[(j * w + i) * 4 + 0] = 255; // red
}
}
}
Computing file changes ...