Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-Dahmane-lynda
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
Lynda Dahmane
AP-Dahmane-lynda
Commits
f7c4d11c
Commit
f7c4d11c
authored
1 year ago
by
Lynda Dahmane
Browse files
Options
Downloads
Patches
Plain Diff
Replace Block.py
parent
42a9c8c8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projet/Block.py
+64
-16
64 additions, 16 deletions
projet/Block.py
with
64 additions
and
16 deletions
projet/Block.py
+
64
−
16
View file @
f7c4d11c
class
Block
:
def
_init_
(
self
,
x
:
int
,
y
,
width
:
int
,
height
:
int
,
color
=
None
):
self
.
x
=
x
self
.
y
=
y
self
.
width
=
width
self
.
height
=
height
self
.
sub_blocs
=
[]
def
__init__
(
self
,
zone
,
couleur
=
None
,
sous_blocs
=
None
):
"""
Initialisation un objet Bloc avec une zone, une couleur et des sous_blocs
"""
self
.
zone
=
zone
self
.
couleur
=
couleur
self
.
sous_blocs
=
sous_blocs
def
est_uniform
(
self
)
->
bool
:
if
self
.
color
is
None
:
if
self
.
sous_blocs
:
if
len
(
self
.
sous_blocs
)
!=
4
:
raise
ValueError
()
if
couleur
is
not
None
:
raise
ValueError
()
self
.
couleur
=
self
.
moyenne_couleurs
()
return
False
for
sub_bloc
in
self
.
sub_blocs
:
if
sub_bloc
.
color
!=
self
.
color
:
return
False
return
True
def
moyenne_couleurs
(
self
):
"""
Renvoie la moyenne des couleurs des sous_blocs
"""
if
not
self
.
sous_blocs
:
return
self
.
couleur
else
:
r
,
g
,
b
=
0
,
0
,
0
for
blocs
in
self
.
sous_blocs
:
r
+=
bloc
.
couleur
[
0
]
g
+=
bloc
.
couleur
[
1
]
b
+=
bloc
.
couleur
[
2
]
return
[
r
/
len
(
self
.
sous_blocs
),
g
/
len
(
self
.
sous_blocs
),
b
/
len
(
self
.
sous_blocs
)]
def
est_uniforme
(
self
)
->
bool
:
"""
Renvoie True si le bloc est uniforme
"""
return
not
self
.
sous_blocs
def
ajouter_sub_bloc
(
self
,
bloc
:
str
):
self
.
sub_blocs
.
append
(
bloc
)
def
est_dans_limites
(
self
,
limites_min
,
limites_max
):
"""
Renvoie True si la zone du bloc est dans les limites spécifiées
"""
x
,
y
=
self
.
zone
[:
2
]
width
,
height
=
self
.
zone
[
2
:]
return
(
x
>=
limites_min
[
0
]
and
x
+
width
<=
limites_max
[
0
]
and
y
>=
limites_min
[
1
]
and
x
+
height
<=
limites_max
[
1
])
def
__str__
(
self
):
"""
Renvoie une représentation en chaine de caractére du bloc
"""
if
self
.
est_uniforme
():
return
f
"
Bloc(uniforme, couleur=
{
self
.
couleur
}
)
"
else
:
return
f
"
Bloc(non_uniforme, couleur=
{
self
.
couleur
}
)
"
...
...
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