@name Digital Scanner Colour (Erza)
@inputs Ds:wirelink
@persist Y Range E:entity O:entity

interval(100)       #Increase if hard quota is exceeded

if(first() | changed(Ds)){ 
    Range = 500     #Set the range of the Ranger trace here
    Ds[1048569]=3   #Changes Number Format to RRRGGGBBB
    E = entity()
    Y = 129
    O = owner()
}

if(O:keyUse()){
    Ds[1048574]=1   #Clears Digital Screen
    Y = 0           #Reset Y Value
}
    
    for(X = 0,128){ #Loop code from X = 0 to X = 128
        if(Y>128){
            exit()      #When done stop the for loop until reset
        }
    Ranger = ranger(Range,(X-64)/64,(Y-64)/64)                              #Set up Ranger with X Y skew
    LDir = (E:pos()-Ranger:position()):normalized()                         #Find the Light Direction
    DistSc = (Range - Ranger:distance())/Range                               #Generate a variable between 0 and 1 to darken into the distance
    Shade = Ranger:entity():getColor()*DistSc*LDir:dot(Ranger:hitNormal())  #Get the Shaded Colour of the pixel
    Clr = rgb2digi(Shade,3)                                                 #Turn Shade into the correct format
    Ds[X+ Y*128]= Clr                                                       #Plot pixel
}

Y++   #Goto next line
