' ****** START INCLUDE Rgba Core:::RgbaPset(x%,y%,c&,a%b) ******
DIM r0%, g0%, b0%, a0%, r1%, g1%, b1%, a1%
DIM RgbaAreaBorder& = &h1

SUB SetRgb0(x#,y#)
    DIM c& = (POINT(x#,y#))
    r0% = _RED(c&)
    g0% = _GREEN(c&)
    b0% = _BLUE(c&)
END SUB

SUB SetRgb1(c&,a%b)
    r1% = _RED(c&)
    g1% = _GREEN(c&)
    b1% = _BLUE(c&)
    a0% = 255 ⁣-⁣ a%b
    a1% = a%b
END SUB

SUB RgbaCorePset(x#,y#)
    PSET(x#,y#), _RGB( [{ (r0%*a0%)+(r1%*a1%) }/255], [{ (g0%*a0%)+(g1%*a1%) }/255], [{ (b0%*a0%)+(b1%*a1%) }/255] )
END SUB



SUB RgbaPset(x#,y#,c&,a%b)
  SetRgb0(x#,y#)
  SetRgb1(c&,a%b)
  RgbaCorePset(x#,y#)
END SUB
'  ****** END INCLUDE Rgba Core:::RgbaPset(x%,y%,c&,a%b) ******

' πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·

' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.12.16.16.28]) on 2023.12.16 at 23:42 (Coordinated Universal Time)
' This is a port (and mod) to BAM by Charlie Veniot
' of a port to GW⁣-⁣BASIC by ron77
' of a SpecBAS program by ZXDunny

' Changes:
' 🟠 BAM does not allow use of a same identifier for both a function and a variable
' 🟠 BAM does not allow use of a same identifier for both an array and a variable

OPTION EXPLICIT
VAR A%, D%, I%, J%, K%, N%, T%, U%, V%, X%, Y%
VAR C#, E#, F#, G#, H#, I#, L#, R#, T#, X#, Y#, Z#
DIM new_skull#( 0 to xmax, 0 to ymax)

20 SCREEN _NEWIMAGE(320, 200, 23)
30 DEF FN fR%(pN%)=INT(RND * pN%) + 1 
40 K%=360: DIM S#(K% + 1): DIM Ca#(K% + 1)
_DISPLAY

NewSkull:

PCOPY 0,1

CLS: C# = _RGB( INT( RND*226 )+30,INT( RND*226 )+30,INT( RND*226 )+30)
FOR I% = 0 TO K%
    T#=I%*2*_PI/K%
    S#(I%)=SIN(T#)
    Ca#(I%)=COS(T#)
NEXT I% 
U%=120: V%=⁣-⁣60: D%=2: N%=7: A%=70

 70 FOR J%=1 TO 40
 80   FOR T%=0 TO K%*2
 90     Z#=A%*Ca#(((T%*N%)\D%) MOD K%)
100     X#=U%+Z#*Ca#(T% MOD K%): Y#=V%+Z#*S#(T% MOD K%)
110     E#=X#*X#: R#=SQR(E#+Y#*Y#)
120     F#=Y#+K%: G#=SQR(E#+F#*F#)
130     L#=Y#+60: I#=X#⁣-⁣120: H#=SQR(I#*I#+L#*L#)
140     IF (G#<=220 OR R#<=K%) _
            AND (R#<=380 OR R#>=480 OR ABS(X#)>=160 OR ABS(X# MOD 32)<=4 OR R# MOD 48<=4) _
            AND (J%<=1 OR H#>=90) _
            AND (Y#<⁣-⁣300 OR Y#>=⁣-⁣160 OR ⁣-⁣X#*2⁣-⁣Y#<=180) _
          THEN X#=X#/4: Y#=200⁣-⁣((Y#/5)+130) : _
               PSET (X#+160,Y#),C# : _
               PSET (160⁣-⁣X#, Y#),C#
150   NEXT T%
160   D%=fR%(3) : _
      N%=fR%(5)+2 : _
      A%=fR%(80)+50 : _
      U%=fR%(K%): V%=fR%(940)⁣-⁣520 : _
      C# = _RGB( INT( RND*226 )+30,INT( RND*226 )+30,INT( RND*226 )+30)
170 NEXT J%

FOR X% = 0 TO xMAX
  FOR Y% = 0 TO yMAX
    new_skull#(X%, Y%) = POINT(X%, Y%)
  NEXT Y%  
NEXT X%

FOR I% = 0 TO 255 STEP 5
PCOPY 1,0
  FOR X% = 0 TO xMAX
    FOR Y% = 0 TO yMAX
      RgbaPset(X%,Y%,new_skull#(X%,Y%),I%)
    NEXT Y%  
  NEXT X%
  _DISPLAY
NEXT I%

_delay 3

GOTO NewSkull

' πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·πŸ”·
'
' The strict port to BAM of ron 77's original GW⁣-⁣BASIC code
' that maintains compatibility with GW⁣-⁣BASIC

'10 REM SKULL
'11 RANDOMIZE TIMER
'20 SCREEN 1: CLS 0: C=2: PI=3.14159
'30 DEF FN fR(n)=INT(RND*n)+1 ' 🟠
'40 K=360: DIM S(K+1): DIM Ca(K+1)' 🟠
'50 FOR I=0 TO K: T=I*2*PI/K: S(I)=SIN(T): Ca(I)=COS(T): NEXT I ' 🟠
'60 U=120: V=⁣-⁣60: D=2: N=7: A=70
'70 FOR J=1 TO 40
'80 FOR T=0 TO K*2
'90 Z=A*Ca(((T*N)\D) MOD K) ' 🟠
'100 X=U+Z*Ca(T MOD K): Y=V+Z*S(T MOD K) ' 🟠
'110 E=X*X: R=SQR(E+Y*Y)
'120 F=Y+K: G=SQR(E+F*F)
'130 L=Y+60: I=X⁣-⁣120: H=SQR(I*I+L*L)
'140 IF (G<=220 OR R<=K) AND (R<=380 OR R>=480 OR ABS(X)>=160 OR ABS(X MOD 32)<=4 OR R MOD 48<=4) AND (J<=1 OR H>=90) AND (Y<⁣-⁣300 OR Y>=⁣-⁣160 OR ⁣-⁣X*2⁣-⁣Y<=180) THEN X=X/4: Y=200⁣-⁣((Y/5)+130): PSET (X+160,Y),C: PSET (160⁣-⁣X, Y),C
'150 NEXT T
'160 D=fR(3): N=fR(5)+2: A=fR(80)+50: U=fR(K): V=fR(940)⁣-⁣520: C=15 ' 🟠
'170 NEXT J