Wow this is the first scanner i have seen with 3d color.
Pictures:
This is a picture of what the exact code below can make (On the left obviously. It cant make those props)
Below is a picture of the same set of props but with a code rewrite to make it work for a 512x512 screen
Description:
This code will use ranger functions to plot pixels on a digital screen (128x128) depending on the props infront of the E2 chip. So in effect its a scanner of props that then shows what they look like on a digital screen.
Set-up:
1. Create a digital screen with the Height and Width set to 128.
2. Spawn the E2 chip on your choice of prop, or on the ground OR on the screen. It doesnt matter
3: Get out the "Expression 2 - Wirelink" tool In Wire - Tools and left click on the digital screen with it
4. Get out the Wire tool and wire the Ds [WIRELINK] input on the E2 to the digital screen's link [WIRELINK] output
5. Place whatever you put the E2 chip on such that the E2 chip faces a contraption/prop/whatever
6. Press E or whatever you have the Use key bound to and the scan will commence
7. ENJOY YOUR PICTURE
Other Details:Code:@name Digital Scanner Colour (Dingo) @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
The Light Direction is currently from the E2 chip. I may change this at some point :mellow:
If you're exceeding the hard quota increase the interval
You can change the range of the scan where it says so in the code
Try not to mess with the other lines unless you know what you're doing ^_^
The code uses a ranger trace so it'll show what the props hitbox looks like which is not always exactly what see when you look at the prop, as you can see with the breen globe above.
PS:
I would appreciate any help with optimization. Thanks in advance
[EDIT]: Newer, messier, less optimised, slower code. It now has Shadows, light sources and NO alpha blending since I killed it somehow
Code:@name Digital Scanner Colour (Dingo) @inputs Ds:wirelink @persist Y Range E:entity O:entity LightA:array LCount Mul interval(100) if(first() | changed(Ds)){ Range = 1500 Ds[1048569]=3 E = entity() Y = 129 O = owner() findIncludePlayerProps(O) } if(O:keyUse()){ Ds[1048574]=1 Y = 0 findByModel("models/hunter/misc/sphere025x025.mdl") LightA = findToArray() LCount = LightA:count() } for(X = Mul*64,(Mul+1)*64){ #Loop code from X = 0 to X = 128 if(Y>128){ exit() } Ranger = ranger(Range,(X-64)/128,(int(Y)-64)/128) Ent = Ranger:entity() TotL = 0 TotS = 0 Dist = Ranger:distance() Pos = Ranger:position() if(LCount){ for(I = 1,LCount){ LDir = (LightA:entity(I):pos() - Pos):normalized() TotL += abs(LDir:dot(Ranger:hitNormal())) rangerFilter(LightA) rangerFilter(Ent) LRanger = rangerOffset(LightA:entity(I):pos(),Pos) TotS += (LRanger:hit() ? 0.8 : 1 ) if( I == LCount){ AvgL = TotL/LCount AvgS = TotS/LCount } } } DistSc = -(Dist/Range)+1 if(Ent:type():find("player")){FColor = (Ent:getColor() == vec(255,255,255)) ? teamColor(Ent:team()) : Ent:getColor()} elseif(!Ent:type():find("_") & Ranger:hit()){FColor = vec(0,255,0)} else{FColor = Ranger:entity():getColor()} Shade = FColor*DistSc*AvgL*AvgS DsColor = rgb2digi(Shade,3) Ds[X+ int(Y)*128]= DsColor } Mul = (Mul == 1 ? 0 : 1) Y+=0.5![]()
Last edited by Dingo2; 02-09-2010 at 03:59 AM. Reason: Adding newer code
Wow this is the first scanner i have seen with 3d color.
Yeah, but with the fact that its in color, your kinda loosing the distance perspective. But its cool.
+rep
New server IP: 89.238.160.17:27018
Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
Unsmart: I doubt the intelligence of some people.
Drunkie: Nobody could have said that any better than Unsmart.
Unsmart: Solece, I totally did your mom yesterday
Solece: Who hasnt
Divran: there are more retarded people than there are clever people in this world
The screen does darken the colours to black the further away the point the ranger trace hits. At least it should be, I'd say its because the props are quite close and the range is to big for the darkening to kick in much
New server IP: 89.238.160.17:27018
Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
Unsmart: I doubt the intelligence of some people.
Drunkie: Nobody could have said that any better than Unsmart.
Unsmart: Solece, I totally did your mom yesterday
Solece: Who hasnt
Divran: there are more retarded people than there are clever people in this world
i have a fix for the tick quota,
Code:@name Digital Scanner Colour (Dingo) @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 } X=0 while(X <,128){ #Loop code from X = 0 to X = 128 if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {continue} 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 X++ #Plot pixel } Y++ #Goto next line
useing a while loop and
if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {continue}
will make it so if the loop gets close to the tick quota, itl skip the code for 1 cycle and resume on the next, if its still within the orange area, itl skip again, but it will do so very fast and i have yet to get it to the hard quota
Looking at that I'd say it would still add one to the Y value and therefore skip the rest of the digital screen line? [EDIT] Nvm I see it says continue now
Regardless I'll put something similar in. Thankyou
[EDIT2] Well for some reason if I use what you've got there, it exceeds the quota instantly and with a for loop it takes a a little bit but it still exceeded ...
Not sure whats going on
Last edited by Dingo2; 01-28-2010 at 05:03 AM.
I wonder why noone ever reads the docs on this. minquota() and maxquota() return how much is left of their respective quota, not the absolute size of the quota. Correct usage is to exit your loops if these functions get lower than a constant. Ideally the constant should be slightly more than the quota cost of one loop execution.
Edit: To illustrate, compareandCode:@persist A runOnTick(1) while(1){A++ if (minquota() < 150) {break} }
The former stabilizes at 97% usage of the E2's capabilities, while the latter stops at a mere 40% (with default quotas).Code:@persist A runOnTick(1) while(1){A++ if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {break} }
I can wire anything directly into anything! I'm the Professor!
-Professor Hubert Farnsworth
Why use 97% when you can perfectly run at 100%?
I've always used this method and it runs perfectly at 100%.Code:while(opcounter()<5000){A++}
Because 5000 won't be the softquota for all servers at all times?
I can wire anything directly into anything! I'm the Professor!
-Professor Hubert Farnsworth
Bookmarks