@name Cenn's Other Camera Ranger System

@inputs TakePicture Screen:wirelink
@persist Row Collumn Res ColorDiv Dist Soft
@trigger none

#Orient the chip so that the arrow on the top is pointing down. The ranger comes out the top of
#the chip so make sure it has a clear line of sight.
#Use advanced wire tool to link the Screen wirelink to the wirelink on the wire Digital Screen.
#Wire a button to TakePicture to take a picture :P
#Wire FillColor on the Digital Screen to another button to clear the screen.

interval(1)

if(first() | dupefinished())
{
Row = 0 #Start at 0,0
Collumn = 0

Res = 256 #Sets the screen resolution. Adjust this if you want a higher resolution
#picture. Keep in mind that a higher resolution will take longer to
#create. The max resolution for Digital Screens is 512. At that resolution
#it will take the chip about a minute to produce a complete image. This is
#because there would be 262144 cells on the screen to fill in. Try to keep
#the resolution low, below 32, for video mode.

Dist = 512 #This will adjust the distance the ranger goes out to. Making this bigger
#will allow stuff at greater distances to show up in your image. Use one of
#the choices below.
#16384 8192 4096 2048 1024 512 256

ColorDiv = Dist/256 #Makes the grayscale value between 0 and 255.

Screen[1048569] = 1 #Sets the color mode of the Digital Screen.
Screen[1048572] = Res #Sets the screens height.
Screen[1048573] = Res #Sets the screens width.
}

if(TakePicture) #When TakePicture button is pressed, reset the chip to make it start from
{ #the beginning.
reset()
}

while(opcounter()<Soft)
{
if(Row < Res)
{
if(Collumn < Res)
{
X = ((Collumn / (Res/2)) -1)
Y = ((Row / (Res/2)) - 1)
Cell = Collumn + Row*Res
Color = ranger(Dist,X,Y):distance()
Collumn+= 1
}
if(Collumn == Res)
{
Collumn = 0
Row+= 1
}
}
else{exit()}
if(Row == Res){Row = 0, Collumn = 0} #Uncomment this line to loop for video.
#comment the else line above.

Out1 = rgb2digi(vec(Color/ColorDiv,Color/ColorDiv,Color/ColorDiv),3)
Screen[Cell]= Out1
}
Soft = softQuota()
