Page 1 of 1

[SCRIPT] Rotate v3

Posted: Fri Jun 14, 2013 7:13 pm
by thepolm3
little tool to rotate a map by any angle
Do f1 to save the map
+added option to make rotating optional with a command; rotatemap
Code: Select all
from math import cos,sin,pi
from commands import add,admin

theta=90
degrees=True #degrees or radians
clockwise=True #cloakwise or counter-clockwise
always_rotate=False #rotates every map you load

if degrees:
    theta /= 180 / pi
if clockwise:
    theta = ( 2 * pi ) - theta

@admin
def rotatemap(connection,*args): #this will kick everyone
    global theta
    temp=theta
    if args:
        try:
            theta=int(args[0])
        except Exception:
            return "Invalid degrees"
    if len(args)>1:
        theta /= 180 / pi
    if len(args)>2:
        theta = ( 2 * pi ) - theta
    connection.protocol.rotate_map()
    theta=temp
add(rotatemap)
    

def get_new_coord(x,y,z):
    x,y=x-255,y-255
    x2 = x*cos(theta) - y*sin(theta)
    y2 = x*sin(theta) + y*cos(theta)
    return int(x2+255),int(y2+255),z

def apply_script(protocol,connection,config):
    class RotateProtocol(protocol):

        def rotate_map(self):
            map=self.map
            newmap=map.copy()
            print("Rotating map")
            for x in range(512):
                if x%50==0:
                    print(str(x/5)+"% done")
                for y in range(512):
                    for z in range(64):
                        a,b,c=get_new_coord(x,y,z)
                        solid,colour=newmap.get_point(a,b,c)
                        if solid and 0<x<511>y>0<a<511>b>0:
                            map.set_point(x,y,z,colour)
                        else:
                            if z==63:
                                map.set_point(x,y,z,(0,0,0))
                            else:
                                map.remove_point(x,y,z)
            self.map=map

        def on_map_change(self,map):
            if always_rotate:
                self.rotate_map()
            return protocol.on_map_change(self,self.map)
    return RotateProtocol,connection
hallway 45 degrees
Image

Re: [SCRIPT] Rotate

Posted: Fri Jun 14, 2013 7:44 pm
by Leif_The_Head
That's what I needed (I requested it also xD)

Re: [SCRIPT] Rotate

Posted: Fri Jun 14, 2013 7:45 pm
by Jdrew
great, I was looking for something like this so thanks

Re: [SCRIPT] Rotate

Posted: Fri Jun 14, 2013 7:46 pm
by thepolm3
I'm just working out the kinks in v2, and let me tell you that 45 degree hallway is just Oo

Re: [SCRIPT] Rotate

Posted: Fri Jun 14, 2013 7:51 pm
by Jdrew
thepolm3 wrote:
I'm just working out the kinks in v2, and let me tell you that 45 degree hallway is just Oo
That would be werid as with hallway it kinda has to be straight or else it looks all ugly

Re: [SCRIPT] Rotate

Posted: Fri Jun 14, 2013 7:54 pm
by thepolm3
I know, but thats why its (O_o)
It actually looks quite interesing

Re: [SCRIPT] Rotate v3

Posted: Sat Jun 15, 2013 11:32 am
by thepolm3
I changed it for you leif :)

Re: [SCRIPT] Rotate v3

Posted: Sun Jun 23, 2013 8:50 pm
by Lostmotel
another very usefull script Blue_Happy3
I rotated some kvx files I inserted on a map and exported them back into kv6. Now I have twice as much trees.

Also: A tractor rotated by 45° Blue_Tongue
Image

Re: [SCRIPT] Rotate v3

Posted: Sun Jun 23, 2013 9:53 pm
by thepolm3
That most certainly is an epic tractor

Re: [SCRIPT] Rotate v3

Posted: Thu Jun 27, 2013 4:25 pm
by Buffet_of_Lies
Brilliant!

Re: [SCRIPT] Rotate v3

Posted: Thu Jun 27, 2013 5:22 pm
by KillerShot
Nice!