Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProjetZZ1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc BERET
ProjetZZ1
Commits
31e7c17e
Commit
31e7c17e
authored
2 years ago
by
maberet
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des oiseaux et des nuages
parent
8dc29ca2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
travail_individuel/Beret/snakes/main.c
+114
-56
114 additions, 56 deletions
travail_individuel/Beret/snakes/main.c
with
114 additions
and
56 deletions
travail_individuel/Beret/snakes/main.c
+
114
−
56
View file @
31e7c17e
#include
<SDL2/SDL.h>
#include
<math.h>
#include
<stdio.h>
#include
<string.h>
int
main
(
int
argc
,
char
**
argv
)
{
(
void
)
argc
;
(
void
)
argv
;
SDL_Window
*
window_1
=
NULL
;
SDL_Renderer
*
renderer
=
NULL
;
if
(
SDL_Init
(
SDL_INIT_VIDEO
)
!=
0
)
{
SDL_Log
(
"Error : SDL initialisation - %s
\n
"
,
SDL_GetError
());
// l'initialisation de la SDL a échoué
exit
(
EXIT_FAILURE
);}
SDL_DisplayMode
DM
;
SDL_GetCurrentDisplayMode
(
0
,
&
DM
);
/* Création de la fenêtre de gauche */
window_1
=
SDL_CreateWindow
(
"Premier dessin"
,
SDL_WINDOWPOS_CENTERED
,
SDL_WINDOWPOS_CENTERED
,
DM
.
w
*
0
.
66
,
DM
.
h
*
0
.
66
,
SDL_WINDOW_OPENGL
);
if
(
window_1
==
NULL
)
{
SDL_Log
(
"Error : SDL window 1 creation - %s
\n
"
,
SDL_GetError
());
// échec de la création de la fenêtre
SDL_Quit
();
// On referme la SDL
exit
(
EXIT_FAILURE
);
}
renderer
=
SDL_CreateRenderer
(
window_1
,
-
1
,
SDL_RENDERER_ACCELERATED
|
SDL_RENDERER_PRESENTVSYNC
);
if
(
renderer
==
NULL
)
{
SDL_DestroyRenderer
(
renderer
);
// Attention : on suppose que les NULL sont maintenus !!
renderer
=
NULL
;
SDL_DestroyWindow
(
window_1
);
window_1
=
NULL
;};
//draw(renderer);
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
2000
);
SDL_DestroyRenderer
(
renderer
);
// Attention : on suppose que les NULL sont maintenus !!
renderer
=
NULL
;
SDL_DestroyWindow
(
window_1
);
window_1
=
NULL
;
SDL_Quit
();
return
0
;
}
#include
<SDL2/SDL.h>
#include
<math.h>
#include
<stdio.h>
#include
<string.h>
#include
<time.h>
void
draw
(
SDL_Renderer
*
renderer
,
int
temps
)
{
SDL_Rect
rectangle
=
{
0
,
0
,
300
,
200
};
SDL_Rect
rectangle2
=
{(
temps
)
%
(
300
),
150
,
20
,
10
};
int
oiseauxx
[
17
]
=
{
0
,
1
,
2
,
2
,
2
,
3
,
3
,
4
,
1
,
1
,
0
,
0
,
0
,
-
1
,
-
1
,
-
2
,
-
3
};
int
oiseauxy
[
17
]
=
{
0
,
0
,
0
,
1
,
2
,
2
,
3
,
3
,
-
1
,
-
2
,
-
1
,
-
2
,
-
3
,
0
,
1
,
1
,
2
};
srand
(
time
(
NULL
)
);
int
saut
=
rand
()
%
5
;
printf
(
"saut%d
\n
"
,
saut
);
srand
(
time
(
NULL
)
);
int
signe
=
rand
()
%
2
;
printf
(
"signe%d
\n
"
,
signe
);
SDL_SetRenderDrawColor
(
renderer
,
128
,
196
,
255
,
// mode Red, Green, Blue (tous dans 0..255)
255
);
// 0 = transparent ; 255 = opaque
SDL_RenderFillRect
(
renderer
,
&
rectangle
);
SDL_SetRenderDrawColor
(
renderer
,
255
,
255
,
255
,
// mode Red, Green, Blue (tous dans 0..255)
150
);
// 0 = transparent ; 255 = opaque
SDL_RenderFillRect
(
renderer
,
&
rectangle2
);
int
pt
=
0
;
/* tracer un cercle n'est en fait pas trivial, voilà le résultat sans algo intelligent ... */
while
(
pt
<
16
)
{
SDL_SetRenderDrawColor
(
renderer
,
0
,
// quantité de Rouge
0
,
// de vert
0
,
// de bleu
255
);
// opacité = opaque
SDL_RenderDrawPoint
(
renderer
,
(
200
+
temps
/
2
-
oiseauxx
[
pt
])
%
(
300
),
// coordonnée en x
100
-
oiseauxy
[
pt
]);
SDL_SetRenderDrawColor
(
renderer
,
0
,
// quantité de Rouge
0
,
// de vert
0
,
// de bleu
255
);
// opacité = opaque
SDL_RenderDrawPoint
(
renderer
,
(
180
+
temps
/
2
-
oiseauxx
[
pt
])
%
(
300
),
// coordonnée en x
150
-
oiseauxy
[
pt
]);
pt
=
pt
+
1
;}
}
int
main
(
int
argc
,
char
**
argv
)
{
(
void
)
argc
;
(
void
)
argv
;
int
temps
=
0
;
SDL_Window
*
window_1
=
NULL
;
SDL_Renderer
*
renderer
=
NULL
;
if
(
SDL_Init
(
SDL_INIT_VIDEO
)
!=
0
)
{
SDL_Log
(
"Error : SDL initialisation - %s
\n
"
,
SDL_GetError
());
// l'initialisation de la SDL a échoué
exit
(
EXIT_FAILURE
);}
window_1
=
SDL_CreateWindow
(
"Premier dessin"
,
SDL_WINDOWPOS_CENTERED
,
SDL_WINDOWPOS_CENTERED
,
300
,
200
,
SDL_WINDOW_OPENGL
);
if
(
window_1
==
NULL
)
{
SDL_Log
(
"Error : SDL window 1 creation - %s
\n
"
,
SDL_GetError
());
// échec de la création de la fenêtre
SDL_Quit
();
// On referme la SDL
exit
(
EXIT_FAILURE
);
}
renderer
=
SDL_CreateRenderer
(
window_1
,
-
1
,
SDL_RENDERER_ACCELERATED
|
SDL_RENDERER_PRESENTVSYNC
);
if
(
renderer
==
NULL
)
{
SDL_DestroyRenderer
(
renderer
);
// Attention : on suppose que les NULL sont maintenus !!
renderer
=
NULL
;
SDL_DestroyWindow
(
window_1
);
window_1
=
NULL
;};
while
(
temps
<
1000
){
//draw(renderer);
draw
(
renderer
,
temps
);
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
20
);
temps
=
temps
+
1
;
}
SDL_DestroyRenderer
(
renderer
);
// Attention : on suppose que les NULL sont maintenus !!
renderer
=
NULL
;
SDL_DestroyWindow
(
window_1
);
window_1
=
NULL
;
SDL_Quit
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment