Градиентная спираль

 


Давненько маялся с кодом, найденный код Turbo Pascal меня не устраивал. Вчера раскопал код вычисления таблицы для zx и попробовал переписать под 320х200:

If InitSprite() And OpenWindow(0,0,0,640,400,"Spirale",#PB_Window_SystemMenu) And OpenWindowedScreen(WindowID(0),0,0,640,400,0,0,0) 
    
    StartDrawing(ScreenOutput()) 
    
    amp=32*4
For y=0 To 199
  For x=0 To 319
    
    xx=x-160
    yy=y-100
    an=Int( 40*ATan2( xx,yy )  )
    
    ra.a=(xx*xx+yy*yy)>>8
    co.a=an+ra
    co=Int(amp+(amp-1)*Sin(co*#PI/128))
    
    ;Box (x*2,y*2,2,2,RGB(co*4,0,0))
    Box (x*2,y*2,2,2,RGB(co,0,0))
  Next x
Next y
        StopDrawing() 
        FlipBuffers() 
  Repeat
  Until WindowEvent()=#PB_Event_CloseWindow 
EndIf

Дополнение 15-09-2025. другая версия

Procedure.f ATan2_(x.f, y.f)
   Protected angle.f=ATan(y/x)
   If x<0
      angle+3.141592653589793238;#PI
   ElseIf y<0
      angle+6.283185307179586477;2*#PI
   EndIf
   ProcedureReturn angle
EndProcedure
If InitSprite() And OpenWindow(0,0,0,640,400,"Spirale",#PB_Window_SystemMenu) And OpenWindowedScreen(WindowID(0),0,0,640,400,0,0,0) 
  Repeat
    StartDrawing(ScreenOutput()) 
    
For y=-100 To 100
  For x=-160 To 160
    dx.d=x
   dy.f=y
   d.f=Sqr(dx*dx+dy*dy)
   a.f=ATan2(dx, dy)
   
   value.f=(Cos(2*#PI*d/(160/1)+a)+1)/2
   r.a=value*255
;    If r&128=0
;      r=255-r
;    EndIf
   Box ( x*2+320,y*2+200,2,2,r )
  Next x
Next y
        StopDrawing() 
        FlipBuffers() 
;  Repeat
  Until WindowEvent()=#PB_Event_CloseWindow 
EndIf

Комментарии