forme géométrique : conchoîde de rosace

Programmation d'applications complexes
manababel
Messages : 135
Inscription : jeu. 14/mai/2020 7:40

forme géométrique : conchoîde de rosace

Message par manababel »

ref : https://mathcurve.com/courbes2d/conchoi ... sace.shtml

Code : Tout sélectionner

Procedure conchoide(cx,cy,r.f,a.f,n,d=1,e.f=10,col=$ffffff)
  ; conchoide de rosace"
  

  If e<1:e=1:EndIf
  If e>50:e=50:EndIf
  e=e/10
  If n<1:n=1:EndIf
  
  If d<1:d=1:EndIf
  If d>8:d=8:EndIf
  
  If r<1:ProcedureReturn:EndIf
    
    dist.f=(1.0+e)
    r2.f=r/dist

    a=Mod(a,360.0)
    x0.f=Cos(Radian(a))*dist*r2+cx
    y0.f=Sin(Radian(a))*dist*r2+cy
	  mx.f=x0
	  my.f=y0
    
    n1.f=n/d
    
    compt.f=(360/(r*4))
    If compt<0.5:compt=0.5:EndIf
    
    nb=360*d
    i.f=0
    While i<nb
        i1.f=Mod((i+a),(360))
        i2.f=Mod((i*n1),(360))
        dist.f=(1.0+e*Cos(Radian(i2)))*r2 ; a modifier pour avoir des triangle
        x1.f=Cos(Radian(i1))*dist+cx
        y1.f=Sin(Radian(i1))*dist+cy
        LineXY(x0,y0,x1,y1,col)
        y0=y1
        x0=x1
        i=i+compt
     Wend
     LineXY(x0,y0,mx,my,col)

EndProcedure

Global lg = 800
Global ht = 600

If OpenWindow(0, 0, 0, lg, ht, "conchoîde", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  
  Image = CreateImage(#PB_Any, lg, ht)
  
  angle.f=0

  Repeat
    Event = WindowEvent()
    
    StartDrawing(ImageOutput(Image))
    Box(0,0,lg,ht,0)
    nombre=1
    div=1

    For y=25 To ht Step 50
      For x=25 To lg/2 Step 50
        conchoide(x,y,20,angle,nombre,div,10)
        div=Mod(div+1,9)
        If div=0:div=1:EndIf
      Next
      div=1
      nombre=Mod(nombre+1,10)
      If nombre=0:nombre=1:EndIf
    Next
    
    nombre=1
    div=1
    sp.f=0.1
    For y=25 To ht Step 50
      For x=lg/2+25 To lg Step 50
        conchoide(x,y,20,angle,nombre,div,sp)
        div=Mod(div+1,9)
        If div=0:div=1:EndIf
        sp=Mod(sp+0.2,5)
      Next
      div=1
      nombre=Mod(nombre+1,10)
      If nombre=0:nombre=1:EndIf
    Next
    
    conchoide(lg/2,ht/2,ht/2,angle,3,1,10,255)
    conchoide(lg/2,ht/2,ht/2,angle,3,1,0.5,$ff00)
    
    StopDrawing()
    
    StartDrawing(WindowOutput(0))
    DrawImage(ImageID(Image), 0, 0)
    StopDrawing()
    angle=Mod(angle+0.9,360)

   
  Until Event = #PB_Event_CloseWindow Or quit=1
  
  FreeImage(#PB_All)

CloseWindow(0)

EndIf