+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Langton's Ants - TalkingGoose

  1. #1
    Wire Noob TalkingGoose's Avatar
    Join Date
    Jan 2010
    Posts
    18

    Default Langton's Ants - TalkingGoose

    This is an Expression 2 chip that emulates 'Langton's Ants'. This isn't useful, Just kinda 'pretty'.

    This isn't perfect, nor is it exactly like 'Langton's Ants'. It was mainly just a test of my abilities and some practise.

    I thought that this was pretty cool so I decided to upload a video.



    And here is the code:
    -EDITED- (Now spawns each prop, one at a time, the old way used to just spam the props unless the server allowed all 100 props to spawn at once, Fail on my part.)
    Code:
    @name Langtons Ant - [TalkingGoose]
    @persist N Direction X Y MultX PNum Printed
    @persist [Yellow,Black,Red,Green,Blue]:vector [Grid,AllProps]:array
    interval(100)
    if(first())
    {
        ###INITIALIZATION###
        print("Langtons Ant - Made by TalkingGoose")
        print("Langtons Ant will Take 35 seconds to load.")
        print("Please wait...")
    
        #Create grid and posistions
        for(X=1,10)
        {
            for(Y=1,10)
            {
                N++
                Grid[N,vector2]=vec2(X,Y)
            }
        }
    
        #Setup colors
        Yellow = vec(255,255,0)
        Black = vec(0,0,0)
        Red = vec(255,0,0)
        Green = vec(0,255,0)
        Blue = vec(0,0,255)
        
        #Stop spawn effect
        propSpawnEffect(0)
        
        #Set starting position and direction
        X = 5
        Y = 5
        Direction=1
        
        #Create 'Ant'
        holoCreate(0)
        holoScaleUnits(0,vec(1,1,5))
        holoColor(0,Black)
        
        #Setup ready for prop spawning
        timer("NextProp",350)
        N=0
        Printed=0
        
        runOnLast(1)
        ####################
    }
    
    ###PROP DELETION###
    if(last())
    {
        for(N=1,100)
        {
            AllProps[N,entity]:propDelete()
        }
    }
    ###################
    
    ###PROP SPAWNING###
    #Check if timer allows prop to spawn
    if(clk("NextProp"))
    {
        #Time until next execution
        timer("NextProp",350)
        
        #Continue until all props have spawned
        if(N!=100)
        {
            N++
            #Set attributes of prop and add to array
            Prop = propSpawn("models/hunter/plates/plate.mdl",entity():pos()+vec(0,0,30)+(vec(Grid[N,vector2])*3),ang(0,0,0),1)
            Prop:setColor(Blue)
            AllProps:pushEntity(Prop)
        }
        elseif(!Printed)
        {
            print("All "+AllProps:count()+" now spawned. Continuing with main code.")
            Printed=1
        }
    }
    ###################
    
    ###Don't execute main code unless all props are spawned###
    if(AllProps:count()==100)
    {
            
        ###BOUNDRIES###
        if(X>=11)
        {
            X = 1
        }
        
        if(X<=0)
        {
            X = 10
        }
        
        if(Y>=11)
        {
            Y = 1
        }
        
        if(Y<=0)
        {
            Y = 10
        }
        ###############
        
        
        ###MOVE DIRECTION###
        if(AllProps[PNum,entity]:getColor()==Blue)
        {
            #Color current prop
            AllProps[PNum,entity]:setColor(Green)
            
            #Move to next prop depending on direction
            if(Direction==1)
            {
                X+=1
            }
            
            if(Direction==2)
            {
                Y-=1
            }
            
                if(Direction==3)
            {
                X-=1
            }
            
                if(Direction==4)
            {
                Y+=1
            }
            Direction+=1
        }
        elseif(AllProps[PNum,entity]:getColor()==Green)
        {
            #Color current prop
            AllProps[PNum,entity]:setColor(Blue)
            
            #Move to next prop depending on direction
            if(Direction==1)
            {
                X-=1
            }
            
            if(Direction==2)
            {
                Y+=1
            }
            
                if(Direction==3)
            {
                X+=1
            }
            
                if(Direction==4)
            {
                Y-=1
            }
            Direction-=1
        }
        
        #Correct Direction
        if(Direction>4)
        {
            Direction = 1
        }
        elseif(Direction<1)
        {
            Direction = 4
        }
        ####################
        
        
        ###CORRECT PLACEMENT###
        #Get where the ant should go on the X axis
        AntX=Grid[X*10,vector2]:x()
        #Get where the ant should go on the Y axis
        AntY=Grid[Y,vector2]:y()
        
        #Translate information to props
        CX = ((AntX*10)+1)-10
        PNum = (CX+(AntY-1))
        
        #Move ant
        holoPos(0,AllProps[PNum,entity]:massCenter())
        #######################
        
        
        ####DEBUG###
        #print("Pos: "+AntX+","+AntY)
        #print("Correct X: "+CX)
        #print("Prop: "+PNum)
        #print("Direction: "+Direction)
        #print("X: "+X)
        #print("Y: "+Y)
        #print("\n")
        #print("\n")
        ############
    }
    This code requires prop core to be enabled so make sure you have it.
    Last edited by TalkingGoose; 08-24-2010 at 12:01 PM. Reason: Edit E2 code

  2. #2
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,662
    Blog Entries
    1

    Default Re: Langton's Ants - TalkingGoose

    Looks pretty nice, good job.

  3. #3
    Wirererer SoundKiller777's Avatar
    Join Date
    Dec 2008
    Location
    United Kingdom
    Posts
    191

    Default Re: Langton's Ants - TalkingGoose

    Quote Originally Posted by Drunkie View Post
    Looks pretty nice, good job.
    ^ This

    +rep for been unique.

  4. #4
    Wire Noob TalkingGoose's Avatar
    Join Date
    Jan 2010
    Posts
    18

    Default Re: Langton's Ants - TalkingGoose

    Quote Originally Posted by Drunkie View Post
    Looks pretty nice, good job.
    Quote Originally Posted by SoundKiller777 View Post
    ^ This

    +rep for been unique.
    Thanks. <3

  5. #5
    Wire Sofaking Jack37's Avatar
    Join Date
    Jul 2009
    Location
    In front of Tatra T6A5
    Posts
    780

    Default Re: Langton's Ants - TalkingGoose

    Also +rep from me, it's pretty as you said


    Wanna add me?:


    My Apps: Adv. Dupe -> E2 Code

  6. #6
    Wirererer failcake's Avatar
    Join Date
    Jul 2009
    Location
    In Aperture Science Laboratories
    Posts
    298

    Default Re: Langton's Ants - TalkingGoose

    Still trying to figure out what Langton's Ants is, lol. But anyways, great work.

  7. #7
    Wire Noob TalkingGoose's Avatar
    Join Date
    Jan 2010
    Posts
    18

    Default Re: Langton's Ants - TalkingGoose

    Quote Originally Posted by failcake View Post
    Still trying to figure out what Langton's Ants is, lol. But anyways, great work.
    Thanks! ^_^

    And if you're still wondering... Here's the video I got the inspiration from:


  8. #8
    Wire Sofaking emspike's Avatar
    Join Date
    Feb 2008
    Posts
    911

    Default Re: Langton's Ants - TalkingGoose

    It's really cool that you made it, but theres not really enough room for the "highway" attractor, so it feels pointless :/.

    EDIT: Do it on a digital screen :3

  9. #9
    Wire Noob TalkingGoose's Avatar
    Join Date
    Jan 2010
    Posts
    18

    Default Re: Langton's Ants - TalkingGoose

    Quote Originally Posted by emspike View Post
    It's really cool that you made it, but theres not really enough room for the "highway" attractor, so it feels pointless :/.

    EDIT: Do it on a digital screen :3
    I felt the same way when I originally finished it, I plan to revisit this and make a V2 on a digital screen, Mostly because as you said the highway could be possible on that because of the larger resolution (This is only 10x10), but also because the props can lag a server rather a lot I liked the look of a 3D board though.

    I might start on that soon as I've nearly finished the thing I was currently working on, So keep an eye out.

  10. #10
    ส็็็็็็็็็็็็็็็็ส็็ ็็็็็ Dav1d's Avatar
    Join Date
    May 2009
    Posts
    1,118

    Default Re: Langton's Ants - TalkingGoose

    The ants in This version of the powder/sand game/toy are langton's ants, and very fun to watch.
    Excelent work on this by the way, maybe add support for more colours and a larger grid?

+ Reply to Thread
Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots