Page 1 sur 1
forme géométrique : astroide
Publié : mer. 13/janv./2021 21:22
par manababel
dessine une forme du type 'astroîde' et un peu plus.
ref :
https://mathcurve.com/courbes2d/astroid/astroid.shtml
Code : Tout sélectionner
Procedure astroide(cx,cy,rayon,ang.f,nb,col=$ffffff)
d=rayon>>2
t.f=0
z2.f=(nb*t)
x1=d*(3*Cos(Radian(t+ang))+(Cos(Radian(z2+ang))))+cx
y1=d*(3*Sin(Radian(t+ang))-(Sin(Radian(z2+ang))))+cy
x0=x1
y0=y1
compt.f=(360/rayon/2)
If compt<0.5:compt=0.5:EndIf
While t<=360
z2.f=(nb*t)
x2.f=Cos(Radian(t+ang))
y2.f=Sin(Radian(t+ang))
x=d*(3*x2+Cos(Radian(z2+ang)))+cx
y=d*(3*y2-Sin(Radian(z2+ang)))+cy
LineXY(x,y,x1,y1,col)
x1=x
y1=y
t=t+compt
Wend
LineXY(x,y,x0,y0,col)
EndProcedure
If OpenWindow(0, 0, 0, 1000, 800, "astroide", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
ii=0
Repeat
Event = WindowEvent()
a.f=ii/1
StartDrawing(WindowOutput(0))
Box(0,0,999,799,0)
astroide(500,400,400,-a,3,$ff)
nb=0
For y=0 To 800 Step 150
For x=0 To 1000 Step 150
astroide(x+50,y,50,a,nb,$ffffff)
nb=Mod(nb+1, 10)
Next
Next
StopDrawing()
Delay(15)
ii=ii+1
ii=Mod(ii,3600)
Until Event = #PB_Event_CloseWindow Or quit=1
CloseWindow(0)
EndIf
Re: forme géométrique : astroide
Publié : jeu. 14/janv./2021 6:38
par kernadec
bjr manababel
Excellent, j'adore merci pour le partage
merci pour le lien il est top
cordialement
Re: forme géométrique : astroide
Publié : jeu. 14/janv./2021 12:22
par vurvur
Merci pour ton code.
Pour plus de fluidité:
Code : Tout sélectionner
InitSprite()
Procedure astroide(cx,cy,rayon,ang.f,nb,col=$ffffff)
d=rayon>>2
t.f=0
z2.f=(nb*t)
x1=d*(3*Cos(Radian(t+ang))+(Cos(Radian(z2+ang))))+cx
y1=d*(3*Sin(Radian(t+ang))-(Sin(Radian(z2+ang))))+cy
x0=x1
y0=y1
compt.f=(360/rayon/2)
If compt<0.5:compt=0.5:EndIf
While t<=360
z2.f=(nb*t)
x2.f=Cos(Radian(t+ang))
y2.f=Sin(Radian(t+ang))
x=d*(3*x2+Cos(Radian(z2+ang)))+cx
y=d*(3*y2-Sin(Radian(z2+ang)))+cy
LineXY(x,y,x1,y1,col)
x1=x
y1=y
t=t+compt
Wend
LineXY(x,y,x0,y0,col)
EndProcedure
OpenWindow(0, 0, 0, 1000, 800, "astroide", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0)+1,WindowHeight(0)+1,1,0,0)
ii=0
SetFrameRate(30)
Repeat
Repeat : e = WindowEvent() : if e = #PB_Event_CloseWindow : end : endif : Until e = 0
a.f=ii/1
StartDrawing(ScreenOutput())
Box(0,0,999,799,0)
astroide(500,400,400,-a,3,$ff)
nb=0
For y=0 To 800 Step 150
For x=0 To 1000 Step 150
astroide(x+50,y,50,a,nb,$ffffff)
nb=Mod(nb+1, 10)
Next
Next
StopDrawing()
Delay(20)
ii=ii+1
ii=Mod(ii,3600)
FlipBuffers()
ForEver
Re: forme géométrique : astroide
Publié : jeu. 14/janv./2021 14:16
par falsam
@manababel : Merci pour ce partage. Par contre ca clignote pas mal.
Une solution pour palier à ce phénomène consiste à créer l'image du résultat puis de l'afficher.
j'ai appliquer une petite correction en ce sens à ton code.
Code : Tout sélectionner
Define Image
Procedure astroide(cx,cy,rayon,ang.f,nb,col=$ffffff)
d=rayon>>2
t.f=0
z2.f=(nb*t)
x1=d*(3*Cos(Radian(t+ang))+(Cos(Radian(z2+ang))))+cx
y1=d*(3*Sin(Radian(t+ang))-(Sin(Radian(z2+ang))))+cy
x0=x1
y0=y1
compt.f=(360/rayon/2)
If compt<0.5:compt=0.5:EndIf
While t<=360
z2.f=(nb*t)
x2.f=Cos(Radian(t+ang))
y2.f=Sin(Radian(t+ang))
x=d*(3*x2+Cos(Radian(z2+ang)))+cx
y=d*(3*y2-Sin(Radian(z2+ang)))+cy
LineXY(x,y,x1,y1,col)
x1=x
y1=y
t=t+compt
Wend
LineXY(x,y,x0,y0,col)
EndProcedure
If OpenWindow(0, 0, 0, 1000, 800, "astroide", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
Image = CreateImage(#PB_Any, 1000, 800)
ii=0
Repeat
Event = WindowEvent()
a.f=ii/1
; Creation de l'image du résultat
StartDrawing(ImageOutput(Image))
Box(0,0,999,799,0)
astroide(500,400,400,-a,3,$ff)
nb=0
For y=0 To 800 Step 150
For x=0 To 1000 Step 150
astroide(x+50,y,50,a,nb,$ffffff)
nb=Mod(nb+1, 10)
Next
Next
StopDrawing()
;Delay(15)
ii=ii+1
ii=Mod(ii,3600)
; Affichage de l'image
StartDrawing(WindowOutput(0))
DrawImage(ImageID(Image), 0, 0)
StopDrawing()
Until Event = #PB_Event_CloseWindow Or quit=1
CloseWindow(0)
EndIf
Re: forme géométrique : astroide
Publié : jeu. 14/janv./2021 15:13
par manababel
Merci pour les modifications.
Je vais poster une autre fonction de ce type mais un peu plus gourmande en ressources.
je dessine tout dans une image comme la version de Falsam, mais l'image cligne encore.
De plus , j'essaie de trouver un moyen pour quitter le programme dès que l'on appuie sur la touche "escape".
Re: forme géométrique : astroide
Publié : ven. 15/janv./2021 10:24
par Mesa
Sur mon pc, l'utilisation des sprites prend 2.5 fois moins de ressources processeur, ce qui est normal car les sprites utilisent les ressources de la carte graphique en priorité.
Code : Tout sélectionner
InitSprite()
Global ppi.f=2*#PI
Procedure astroide(cx,cy,rayon,ang.f,nb,col=$ffffff, Stepp.f=0.08)
;stepp=0.5/ppi
d=rayon>>2
t.f=0
z2.f=(nb*t)
x1=d*(3*Cos(t+ang)+(Cos(z2+ang)))+cx
y1=d*(3*Sin(t+ang)-(Sin(z2+ang)))+cy
x0=x1
y0=y1
compt.f=(#PI/rayon)
If compt<Stepp:compt=stepp:EndIf
While t<=ppi
z2.f=(nb*t)
x2.f=Cos(t+ang)
y2.f=Sin(t+ang)
x=d*(3*x2+Cos(z2+ang))+cx
y=d*(3*y2-Sin(z2+ang))+cy
LineXY(x,y,x1,y1,col)
x1=x
y1=y
t=t+compt
Wend
LineXY(x,y,x0,y0,col)
EndProcedure
OpenWindow(0, 0, 0, 1000, 800, "astroide", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0)+1,WindowHeight(0)+1,1,0,0)
Image = CreateSprite(#PB_Any, 1000, 800)
ii=0
; SetFrameRate(60)
Repeat
Repeat : e = WindowEvent() : If e = #PB_Event_CloseWindow : End : EndIf : Until e = 0
; a.f=ii/ppi
a.f=ii/1; plus rapide
StartDrawing(SpriteOutput(Image))
Box(0,0,999,799,0)
astroide(500,400,400,-a,3,$ff)
nb=0
For y=0 To 800 Step 150
For x=0 To 1000 Step 150
astroide(x+50,y,50,a,nb,$ffffff)
nb=Mod(nb+1, 10)
Next
Next
StopDrawing()
DisplaySprite(Image, 0, 0)
; Delay(50)
ii=ii+1
ii=Mod(ii,3600)
FlipBuffers()
ForEver
Mesa.
Re: forme géométrique : astroide
Publié : ven. 15/janv./2021 12:49
par manababel
Effectivement , l'utilisation des "sprites" est nettement plus rapide.
j'essaierais d'utiliser plus souvent cette méthode.
Merci.