# C24_Core_frames.slf
# 24-cell with fixed 2-color assignment in its core of 4 stacked octahedra
# use sliders to rotate the not-yet defined pairs of pairs of faces.
##########################################################################

############ Some trivial interaction throug sliders ################

tclinit {
  set winName .slfwin

  source SLIDEUI.tcl
  source MATH.tcl

  proc CreateSliders { parent name } {
    set subname "slf_[subst $name]"
    if { $parent == {} } {
	set root .$subname
    } elseif { $parent == "." } {
	set root .$subname
    } else {
	set root $parent.$subname
    }
    toplevel $root

    set lod  [CreateScale $name $root lod   "LOD#"    1       1      4    1       1 horizontal]
    set rotx [CreateScale $name $root rotx "Rot: X"   0    -180    180    1       1 horizontal]
    set roty [CreateScale $name $root roty "Rot: Y"   0    -180    180    1       1 horizontal]
    set size [CreateScale $name $root size   "Size"   0.05    0.01   0.8  0.01     1 horizontal]

    pack  $lod  $rotx $roty  $size    -side top -fill x
  }
  CreateSliders $winName param
}

### DEFINE SOME SURFACE COLORS ################
surface M00 color ( 0.8 1 0.8 ) endsurface
surface M0 color ( 1 0 1) endsurface
surface M1 color ( 1.0 0.0 0.0 ) endsurface
surface M2 color ( 1.0 0.25 0.0 ) endsurface
surface M3 color ( 1.0 0.5 0.0 ) endsurface
surface M4 color ( 1.0 0.75 0.0 ) endsurface
surface M5 color ( 1.0 1.0 0.0 ) endsurface
surface M6 color ( 0.75 1.0 0.0 ) endsurface
surface M7 color ( 0.5 1.0 0.0 ) endsurface
surface M8 color ( 0.25 1.0 0.0 ) endsurface
surface M9 color ( 0.0 1.0 0.0 ) endsurface
surface M10 color ( 0.0 1.0 0.25 ) endsurface
surface M11 color ( 0.0 1.0 0.5 ) endsurface
surface M12 color ( 0.0 1.0 0.75 ) endsurface
surface M13 color ( 0.0 1.0 1.0 ) endsurface
surface M14 color ( 0.0 0.75 1.0 ) endsurface
surface M15 color ( 0.0 0.5 1.0 ) endsurface
surface M16 color ( 0.0 0.25 1.0 ) endsurface
surface M17 color ( 0.0 0.0 1.0 ) endsurface
surface M18 color ( 0.25 0.0 1.0 ) endsurface
surface M19 color ( 0.5 0.0 1.0 ) endsurface
surface M20 color ( 0.75 0.0 1.0 ) endsurface
surface M21 color ( 1.0 0.0 1.0 ) endsurface
surface M22 color ( 1.0 0.0 0.75 ) endsurface
surface M23 color ( 1.0 0.0 0.5 ) endsurface
surface M24 color ( 1.0 0.0 0.25 ) endsurface
surface R  color ( 1.0 0.0 0.0 ) endsurface
surface Y color ( 1.0 1.0 0.0 ) endsurface

point X  (3 0 0 ) endpoint
point A  (-3 0 0 ) endpoint
point Y  (0 3 0 ) endpoint
point B  (0 -3 0 ) endpoint
point Z  (0 0 3 ) endpoint
point C  (0 0 -3 ) endpoint

point xy  (1 1 0) endpoint
point xb  (1 -1 0) endpoint
point ay  (-1 1 0) endpoint
point ab  (-1 -1 0) endpoint
point yz  (0 1 1) endpoint
point yc  (0 1 -1) endpoint
point bz  (0 -1 1) endpoint
point bc  (0 -1 -1) endpoint
point xz  (1 0 1) endpoint
point xc  (1 0 -1) endpoint
point az  (-1 0 1) endpoint
point ac  (-1 0 -1) endpoint

point ix  (0.6 0 0 ) endpoint
point ia  (-0.6 0 0 ) endpoint
point iy  (0 0.6 0 ) endpoint
point ib  (0 -0.6 0 ) endpoint
point iz  (0 0 0.6 ) endpoint
point ic  (0 0 -0.6 ) endpoint


### Define on type of triangle frame each:

(*
point triABCa ( -2.5 -0.25 -0.25 ) endpoint
point triABCb ( -0.25 -2.5 -0.25 ) endpoint
point triABCc ( -0.25 -0.25 -2.5 ) endpoint

face triABC1 ( triABCa A B triABCb ) surface M1  endface
face triABC2 ( triABCb B A triABCa ) surface M1  endface
face triABC3 ( triABCb B C triABCc ) surface M1  endface
face triABC4 ( triABCc C B triABCb ) surface M1  endface
face triABC5 ( triABCc C A triABCa ) surface M1  endface
face triABC6 ( triABCa A C triABCc ) surface M1  endface
*)

object oO ( triABC1 triABC2 triABC3 triABC4 triABC5 triABC6 ) endobject

# Outer Octa: 8
point triABZa ( -2.5 -0.25 0.25 ) endpoint
point triABZb ( -0.25 -2.5 0.25 ) endpoint
point triABZc ( -0.25 -0.25 2.5 ) endpoint

face triABZ1 ( triABZa A B triABZb ) surface M2  endface
face triABZ2 ( triABZb B A triABZa ) surface M2  endface
face triABZ3 ( triABZb B Z triABZc ) surface M2  endface
face triABZ4 ( triABZc Z B triABZb ) surface M2  endface
face triABZ5 ( triABZc Z A triABZa ) surface M2  endface
face triABZ6 ( triABZa A Z triABZc ) surface M2  endface

object oO ( triABZ1 triABZ2 triABZ3 triABZ4 triABZ5 triABZ6 ) endobject

# Outer Flap: 12
point triAZaza ( -2.583333333333333 0.0 0.33333333333333326 ) endpoint
point triAZazb ( -0.33333333333333326 0.0 2.583333333333333 ) endpoint
point triAZazc ( -1.0833333333333333 0.0 1.0833333333333333 ) endpoint

face triAZaz1 ( triAZaza A Z triAZazb ) surface M3  endface
face triAZaz2 ( triAZazb Z A triAZaza ) surface M3  endface
face triAZaz3 ( triAZazb Z az triAZazc ) surface M3  endface
face triAZaz4 ( triAZazc az Z triAZazb ) surface M3  endface
face triAZaz5 ( triAZazc az A triAZaza ) surface M3  endface
face triAZaz6 ( triAZaza A az triAZazc ) surface M3  endface

object oF ( triAZaz1 triAZaz2 triAZaz3 triAZaz4 triAZaz5 triAZaz6 ) endobject

# Outer Tip: 24
point triAabaza ( -2.666666666666667 -0.08333333333333331 0.08333333333333331 ) endpoint
point triAabazb ( -1.1666666666666667 -0.8333333333333333 0.08333333333333331 ) endpoint
point triAabazc ( -1.1666666666666667 -0.08333333333333331 0.8333333333333333 ) endpoint

face triAabaz1 ( triAabaza A ab triAabazb ) surface M4  endface
face triAabaz2 ( triAabazb ab A triAabaza ) surface M4  endface
face triAabaz3 ( triAabazb ab az triAabazc ) surface M4  endface
face triAabaz4 ( triAabazc az ab triAabazb ) surface M4  endface
face triAabaz5 ( triAabazc az A triAabaza ) surface M4  endface
face triAabaz6 ( triAabaza A az triAabazc ) surface M4  endface

object oT ( triAabaz1 triAabaz2 triAabaz3 triAabaz4 triAabaz5 triAabaz6 ) endobject

# Inner Tip: 24
point triabaziaa ( -0.9666666666666667 -0.8333333333333333 0.08333333333333331 ) endpoint
point triabaziab ( -0.9666666666666667 -0.08333333333333331 0.8333333333333333 ) endpoint
point triabaziac ( -0.6666666666666666 -0.08333333333333331 0.08333333333333331 ) endpoint

face triabazia1 ( triabaziaa ab az triabaziab ) surface M5  endface
face triabazia2 ( triabaziab az ab triabaziaa ) surface M5  endface
face triabazia3 ( triabaziab az ia triabaziac ) surface M5  endface
face triabazia4 ( triabaziac ia az triabaziab ) surface M5  endface
face triabazia5 ( triabaziac ia ab triabaziaa ) surface M5  endface
face triabazia6 ( triabaziaa ab ia triabaziac ) surface M5  endface

object iT ( triabazia1 triabazia2 triabazia3 triabazia4 triabazia5 triabazia6 ) endobject

# Inner Flap: 12
point triabiaiba ( -0.8833333333333333 -0.8833333333333333 0.0 ) endpoint
point triabiaibb ( -0.5833333333333333 -0.1333333333333333 0.0 ) endpoint
point triabiaibc ( -0.1333333333333333 -0.5833333333333333 0.0 ) endpoint

face triabiaib1 ( triabiaiba ab ia triabiaibb ) surface M6  endface
face triabiaib2 ( triabiaibb ia ab triabiaiba ) surface M6  endface
face triabiaib3 ( triabiaibb ia ib triabiaibc ) surface M6  endface
face triabiaib4 ( triabiaibc ib ia triabiaibb ) surface M6  endface
face triabiaib5 ( triabiaibc ib ab triabiaiba ) surface M6  endface
face triabiaib6 ( triabiaiba ab ib triabiaibc ) surface M6  endface

object iF ( triabiaib1 triabiaib2 triabiaib3 triabiaib4 triabiaib5 triabiaib6 ) endobject

# Cub-Octa faces: 8
point tribzxbxza ( 0.16666666666666663 -0.9166666666666666 0.9166666666666666 ) endpoint
point tribzxbxzb ( 0.9166666666666666 -0.9166666666666666 0.16666666666666663 ) endpoint
point tribzxbxzc ( 0.9166666666666666 -0.16666666666666663 0.9166666666666666 ) endpoint

face tribzxbxz1 ( tribzxbxza bz xb tribzxbxzb ) surface M9  endface
face tribzxbxz2 ( tribzxbxzb xb bz tribzxbxza ) surface M9  endface
face tribzxbxz3 ( tribzxbxzb xb xz tribzxbxzc ) surface M9  endface
face tribzxbxz4 ( tribzxbxzc xz xb tribzxbxzb ) surface M9  endface
face tribzxbxz5 ( tribzxbxzc xz bz tribzxbxza ) surface M9  endface
face tribzxbxz6 ( tribzxbxza bz xz tribzxbxzc ) surface M9  endface

object CO ( tribzxbxz1 tribzxbxz2 tribzxbxz3 tribzxbxz4 tribzxbxz5 tribzxbxz6 ) endobject

# Inner Octa: 8
point triixiyiza ( 0.5 0.04999999999999999 0.04999999999999999 ) endpoint
point triixiyizb ( 0.04999999999999999 0.5 0.04999999999999999 ) endpoint
point triixiyizc ( 0.04999999999999999 0.04999999999999999 0.5 ) endpoint

face triixiyiz1 ( triixiyiza ix iy triixiyizb ) surface M13  endface
face triixiyiz2 ( triixiyizb iy ix triixiyiza ) surface M13  endface
face triixiyiz3 ( triixiyizb iy iz triixiyizc ) surface M13  endface
face triixiyiz4 ( triixiyizc iz iy triixiyizb ) surface M13  endface
face triixiyiz5 ( triixiyizc iz ix triixiyiza ) surface M13  endface
face triixiyiz6 ( triixiyiza ix iz triixiyizc ) surface M13  endface

object iO ( triixiyiz1 triixiyiz2 triixiyiz3 triixiyiz4 triixiyiz5 triixiyiz6 ) endobject




group regpoly
  instance oO  surface M1  endinstance
  instance oF  surface M4  endinstance
  instance oT  surface M7  endinstance
  instance iT  surface M10 endinstance
  instance iF  surface M13  endinstance
  instance CO  surface M16 endinstance
  instance iO  surface M19 endinstance
endgroup 


group assembly
  instance regpoly
  endinstance
  instance regpoly
    rotate (0 1 0) (180)
    surface M7
    lod {expr ($param_lod > 1) * $SLF_FULL } 
  endinstance
  instance regpoly
    rotate (1 0 0) (180)
    surface M13
    lod {expr ($param_lod > 2) * $SLF_FULL } 
  endinstance
  instance regpoly
    rotate (0 0 1) (180)
    surface M19
    lod {expr ($param_lod > 3) * $SLF_FULL } 
  endinstance
endgroup

########### RENDERING THE ABOVE GEOMETRY  ###########

group world
  instance assembly   
    scale( {expr $param_size} {expr $param_size} {expr $param_size} )
  endinstance

  instance amb
    id main_amb
  endinstance
  instance sun
    id left_sun
    rotate (0 1 0) (-45)
    rotate (0 0 1) (-60)
  endinstance
endgroup

light amb
  type SLF_AMBIENT
  color (0.3 0.3 0.3)
endlight

light sun
  type SLF_DIRECTIONAL
  color (0.9 0.9 0.9)
endlight

camera cam
   projection SLF_PERSPECTIVE
  frustum ( -0.2 -0.2 -4 ) ( 0.2 0.2 -0.01 )
endcamera

group gCam
  instance cam
    id iCam
    translate ( 0.0 0.0 1.0 )
  endinstance
endgroup

window win
  background (0.7 0.8 0.9)
endwindow

viewport vp win
endviewport

render vp gCam.iCam.cam world  
  light world.left_sun.sun
  light world.main_amb.amb
endrender

#################################################