
moi et les math...
Code : Tout sélectionner
#PI = 3.14159265
InitSprite()
InitKeyboard()
OpenScreen(800, 600, 32, "")
Procedure Engrenage(x.l, y.l, r1.f, r2.f, p.f)
a.f
a2.f
StartDrawing(ScreenOutput())
Repeat
a = a2
a2 + p
b + 1
If b > 1 : b = 0 : EndIf
If b
xp1 = r1 * Cos(a) + x
yp1 = r1 * Sin(a) + y
xp2 = r2 * Cos(a2) + x
yp2 = r2 * Sin(a2) + y
Else
xp1 = r1 * Cos(a2) + x
yp1 = r1 * Sin(a2) + y
xp2 = r2 * Cos(a) + x
yp2 = r2 * Sin(a) + y
EndIf
LineXY(xp1, yp1, xp2, yp2, RGB(180, 150, 250))
Plot(xp, yp, RGB(200, 200, 200))
Until a >= 2 * #PI
StopDrawing()
EndProcedure
div = 8
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) : div + 1 : EndIf
If KeyboardPushed(#PB_Key_Down) : div - 1 : EndIf
ClearScreen(0, 0, 0)
Engrenage(400, 300, 100, 200, #pi / div)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 3.81
;
; Explication du programme :
; Dessiner un engrenage
Procedure Engrenage(x.l, y.l, Rayon.l, RayonAlesage.l, NbDents.l, HauteurDent.l, Couleur.l)
StartDrawing(ImageOutput())
DrawingMode(4)
Circle(x, y, Rayon - HauteurDent, Couleur) ; on dessine l'engrenage
Circle(x, y, RayonAlesage, Couleur) ; on dessine le trou de l'engrenage
DrawingMode(0)
FillArea(x, y + RayonAlesage + 2, Couleur, Couleur) ; on rempli l'engrenage
LargeurDent = Int(Rayon * 3 / 5 * Sin(#PI / NbDents) + 0.5) ; on détermine la largeur d'une dents
For n = 1 To NbDents ; on passe en revue toutes les dents
Cos.f = Cos(n * 2 * #PI / NbDents) ; Calcul du cos de l'angle
Sin.f = Sin(n * 2 * #PI / NbDents) ; Calcul du sin de l'angle
; Point haut gauche de la dent
PosX1 = Int(x + Rayon * Cos + LargeurDent / 2 * Sin + 0.5)
PosY1 = Int(y + Rayon * Sin - LargeurDent / 2 * Cos + 0.5)
; Point haut droit de la dent
PosX2 = Int(x + Rayon * Cos - LargeurDent / 2 * Sin + 0.5)
PosY2 = Int(y + Rayon * Sin + LargeurDent / 2 * Cos + 0.5)
; Point bas gauche de la dent
PosX3 = Int(x + (Rayon - HauteurDent - 2) * Cos + LargeurDent * Sin + 0.5)
PosY3 = Int(y + (Rayon - HauteurDent - 2) * Sin - LargeurDent * Cos + 0.5)
; Point bas droit de la dent
PosX4 = Int(x + (Rayon - HauteurDent - 2) * Cos - LargeurDent * Sin + 0.5)
PosY4 = Int(y + (Rayon - HauteurDent - 2) * Sin + LargeurDent * Cos + 0.5)
; Dessin du contour de la dent
LineXY(PosX1, PosY1, PosX2, PosY2, Couleur)
LineXY(PosX1, PosY1, PosX3, PosY3, Couleur)
LineXY(PosX4, PosY4, PosX2, PosY2, Couleur)
; Remplissage de la dent
FillArea(Int(x + (Rayon - HauteurDent / 2) * Cos + 0.5), Int(y + (Rayon - HauteurDent / 2) * Sin + 0.5), Couleur, Couleur)
Next
StopDrawing()
EndProcedure
;- Exemple
; Création de la fenêtre et dela GadgetList
If OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget, "Test") = 0 Or CreateGadgetList(WindowID()) = 0
End
EndIf
; Création de l'image
CreateImage(0, 300, 300)
StartDrawing(ImageOutput())
Box(0, 0, 300, 300, RGB(255, 255, 255))
StopDrawing()
; On dessine l'engrenage
Engrenage(150, 150, 120, 40, 16, 30, 0)
; On affiche l'image
ImageGadget(0, 0, 0, 300, 300, UseImage(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_EventCloseWindow
End
Code : Tout sélectionner
#PI = 3.14159265
InitSprite()
InitKeyboard()
OpenScreen(800, 600, 32, "")
Procedure Engrenage(x.l, y.l, r1.f, r2.f, p.f, an.f, pr.f)
a.f
a2.f
StartDrawing(ScreenOutput())
Repeat
Repeat
a + pr
If b
xp1 = r1 * Cos(a + an) + x
yp1 = r1 * Sin(a + an) + y
Else
xp1 = r2 * Cos(a + an) + x
yp1 = r2 * Sin(a + an) + y
EndIf
Plot(xp1, yp1, RGB(200, 180, 255))
Until a > a2 + p
If b
xp2 = r2 * Cos(a + an) + x
yp2 = r2 * Sin(a + an) + y
Else
xp2 = r1 * Cos(a + an) + x
yp2 = r1 * Sin(a + an) + y
EndIf
LineXY(xp1, yp1, xp2, yp2, RGB(200, 180, 255))
a2.f + p
a.f = a2
b + 1
If b > 1 : b = 0 : EndIf
Until a2 >= 2* #PI
StopDrawing()
EndProcedure
div = 8
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) : div + 1 : EndIf
If KeyboardPushed(#PB_Key_Down) : div - 1 : EndIf
ClearScreen(0, 0, 0)
a.f + 0.01
If a > 2 * #Pi : a = 0 : EndIf
Engrenage(400, 300, 125, 200, #pi / div, a, 0.001)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Code : Tout sélectionner
#PI = 3.14159265
InitSprite()
InitKeyboard()
OpenScreen(800, 600, 32, "")
Procedure Engrenage(x.l, y.l, r1.f, r2.f, p.f, an.f, pr.f)
a.f
a2.f
StartDrawing(ScreenOutput())
Repeat
Repeat
a + pr
If b
xp1 = r1 * Cos(a + an) + x
yp1 = r1 * Sin(a + an) + y
Else
xp1 = r2 * Cos(a + an) + x
yp1 = r2 * Sin(a + an) + y
EndIf
Plot(xp1, yp1, RGB(200, 180, 255))
Until a > a2 + p
If b
xp2 = r2 * Cos(a + an) + x
yp2 = r2 * Sin(a + an) + y
Else
xp2 = r1 * Cos(a + an) + x
yp2 = r1 * Sin(a + an) + y
EndIf
LineXY(xp1, yp1, xp2, yp2, RGB(200, 180, 255))
a2.f + p
a.f = a2
b + 1
If b > 1 : b = 0 : EndIf
Until a2 >= 2* #PI
StopDrawing()
EndProcedure
div = 8
Repeat
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Up) : div + 1 : EndIf
If KeyboardReleased(#PB_Key_Down) : div - 1 : EndIf
ClearScreen(0, 0, 0)
a.f + 0.01
If a > 2 * #Pi : a = 0 : EndIf
Engrenage(330, 300, 50, 75, #pi / div, a, 0.001)
Engrenage(470, 300, 50, 75, #pi / div, -a, 0.001)
Engrenage(470, 440, 50, 75, #pi / div, a, 0.001)
Engrenage(330, 160, 50, 75, #pi / div, -a, 0.001)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Code : Tout sélectionner
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) : div + 1 : EndIf
If KeyboardPushed(#PB_Key_Down) : div - 1 : EndIf <-- ici
ClearScreen(0, 0, 0)
a.f + 0.01
If a > 2 * #Pi : a = 0 : EndIf
Engrenage(400, 300, 125, 200, #pi / div, a, 0.001)
par rapport à ici --------------------^