by matref » 22 Nov 2012, 19:45
Franchement, tu trouveras pas grand-chose dedans ... y'a 60 lignes à tout casser et c'est juste une courbe de Bézier avec un plotter fait à la va-vite

- Code: Select all
/* Bezier curves program
Uses the formula for the Bezier curve with 4 control points A to D :
x = Xa * (1 - t)^3 + Xb * 3 * t * (1 - t)^2 + Xc * 3 * t^2 * (1 - t) + Xd * t^3
x = Ya * (1 - t)^3 + Yb * 3 * t * (1 - t)^2 + Yc * 3 * t^2 * (1 - t) + Yd * t^3
*/
#include <os.h>
#include "utils.h"
int main(void) {
char *scrbuf;
double t = 0.0;
int coord[2], current = 0, i = 0;
double controlPoints[4][2] = {
{64.0,120.0},
{128.0,120.0},
{192.0,120.0},
{256.0,120.0}
};
lcd_ingray();
scrbuf = malloc(SCREEN_BYTES_SIZE * sizeof(char));
if(!scrbuf)
{
exit(0);
}
while (!isKeyPressed(KEY_NSPIRE_ESC))
{
clearBuf(scrbuf);
for (t = -6.28; t < 6.28; t += 0.003)
{
coord[0] = controlPoints[0][0] * cube(1 - t) + controlPoints[1][0] * 3 * t * square(1 - t) + controlPoints[2][0] * 3 * square(t) * (1 - t)
+ controlPoints[3][0] * cube(t);
coord[1] = controlPoints[0][1] * cube(1 - t) + controlPoints[1][1] * 3 * t * square(1 - t) + controlPoints[2][1] * 3 * square(t) * (1 - t)
+ controlPoints[3][1] * cube(t);
if(coord[0] >= 0 && coord[0] < 320 && coord[1] >= 0 && coord[1] < 240) setPixelBuf(scrbuf, coord[0], coord[1], 0x00);
}
for(i = 0; i < 9; i++)
{
setPixelBuf(scrbuf, (i % 3) + controlPoints[current][0], (int)(i/3) + controlPoints[current][1], 0x00);
}
refresh(scrbuf);
controlPoints[current][0] += isKeyPressed(KEY_NSPIRE_RIGHT);
controlPoints[current][0] -= isKeyPressed(KEY_NSPIRE_LEFT);
controlPoints[current][1] += isKeyPressed(KEY_NSPIRE_DOWN);
controlPoints[current][1] -= isKeyPressed(KEY_NSPIRE_UP);
current += current < 3 ? isKeyPressed(KEY_NSPIRE_PLUS) : 0;
current -= current > 0 ? isKeyPressed(KEY_NSPIRE_MINUS) : 0;
}
free(scrbuf);
return 0;
}
Dans util.h c'est les fonctions de base : setPixelBuf, clearBuf, square, cube, refresh.
Programmer en hexadécimal, c'est possible ! (tutoriel 82 stats, 82 stats.fr, 83, 83+, 83+.fr, 83+SE, 84+, 84+.fr, 84+ pocket.fr, 84+ SE)Faites donc un tour sur ticalc pour voir mes programmes !
