« Soya/Python base 4 » : différence entre les versions

Contenu supprimé Contenu ajouté
Seb.bernery (discussion | contributions)
mAucun résumé des modifications
Seb.bernery (discussion | contributions)
mAucun résumé des modifications
Ligne 27 :
# première pièce.
 
# RunDémarrez thele tutorial ifsi youvous don'tne understandcomprennez wellpas whatce isqu'est thela caterpillarchenille.
 
 
# ImportImportation the Soyadu module de Soya.
 
import sys, os, os.path, random, soya
Ligne 37 :
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
 
# Création de la scène.
# Creates a scene.
 
scene = soya.World()
 
# CaterpillarHead isest thela classclasse forpour thela headtête ofde thela caterpillarchenille.
# ItC'est isidentique identicalà tola theclasse Head classde ofla lessonleçon base basic-3.py, exceptexcepté le nom thede classla nameclasse.
# Alors je ne commente pas !
# So... no comment!
 
class CaterpillarHead(soya.Body):
Ligne 61 :
 
 
# AUne CaterpillarPiece isest aune piecepièce ofdu thecorps bodyde ofla the caterpillarchenille.
# ItCa followssuit anotherd'autres objectobjets -- thela previouspièce pieceprécédente, orou the headtête forpour thela first onepremière.
 
class CaterpillarPiece(soya.Body):
# TheLe constructorconstructeur takesprend two2 arguments : thele parent and theet previousla pieceprécédente ofpièce bodydu thatcorps
# weque mustnous followdevons suivre.
# SimilarlySimilaire toà thela headtête, wenous definedéfinissons aun speedvecteur vectorde vitesse.
def __init__(self, parent, previous):
Ligne 78 :
soya.Body.begin_round(self)
# WeNous rotatestournons theune caterpillarpièce piecede sola aschenille itpour looksqu'il towardregarde thele previousmorceau pieceprécédent.
self.look_at(self.previous)
# TheLa distance_tométhode methoddistance_to returnsretourne theune distance betweenentre two2 positionpositions.
# IfSi wenous aresommes tootrop closeprès todu themorceau previousprécédent piecedu of bodycorps, wenous paramétrons setla thevitesse speed'sà Z to= 0.0,
# andet thusainsi thela speedvitesse isdu avecteur nullest vectornulle : thiscette pièce n'a piecepas node longerlongs movesmouvements.
# ElseSinon, wenous resetremettons thela speed'svitesse à Z to= -0.2.
if self.distance_to(self.previous) < 1.5: self.speed.z = 0.0
else: self.speed.z = -0.2
# advance_time isest identicalidentique to thea CaterpillarHead ones.
def advance_time(self, proportion):
Ligne 99 :
 
# Création de la tête de la chenille.
# Creates a caterpillar head.
 
caterpillar_head = CaterpillarHead(scene)
caterpillar_head.rotate_y(90.0)
 
# Création de 10 pièces de corps de la chenille.
# Creates 10 caterpillar piece of body.
 
previous_caterpillar_piece = caterpillar_head
Ligne 111 :
previous_caterpillar_piece.x = i + 1
# CreatesCréation ade lightla lampe.
 
light = soya.Light(scene)
light.set_xyz(2.0, 5.0, 0.0)
 
# Création de la caméra.
# Creates a camera.
 
camera = soya.Camera(scene)
Ligne 126 :
 
 
# ForPour information, thela caterpillartexture texturesde werela donechenille inà theété réalisée avec Gimp, andet thele model werea été généré
# avec ce code (regardez le tutorial sur le modelage pour le comprendre) :
# generated with this code (see modeling-*.py to understand it) :
 
# import soya.sphere
Ligne 144 :
# caterpillar .save()
# caterpillar_head.save()