+ Reply to Thread
Results 1 to 8 of 8

Thread: The most complex way to make a sphere...

  1. #1
    Wire Noob Dimencia's Avatar
    Join Date
    Mar 2007
    Location
    North Carolina
    Posts
    25

    Default

    I spent quite a while working this out on paper first, put it in notepad, and gave it a try.

    First a note. If you leave line breaks after something, it will delete two lines down, and copy one. Example:

    Code:
    jmp main;
    
    alterz:
    mov esp,edx;
    Turns into, once you load it in,
    Code:
    jmp main;
    jmp main;
    mov esp,edx;
    , which was quite annoying.

    Anyway, here's the code. I just ran through creating the unit circle, and scaled it according to the Z-position, and ran up and down the Z axis. But this code made it really long , and I know there are probably much easier ways. Heavily commented, so I'm hoping it can help somone out, it pretty much meant that I don't fail at languages, for me =P
    Code:
    CODE;
    // eax is x
    // ebx is y
    // ecx is the counter
    // edx is z
    // esi is the increment
    // The frequency should be very high!
    // edi is the previous z
    // ebp is the altered z
    // esp is a random temporary thing
    // port0 is x
    // port1 is y
    // port2 is z
    // port3 is lifetime
    // port4 is display
    init:
    **mov esi,1; // Set increment to .01 or so
    **div esi,100; // May need to change this to make it faster
    **mov ecx,0; // Initial counter 0
    **fsin eax,ecx; // Set inital x and y
    **fcos ebx,ecx;
    **mov edx,5; // Initial z = 5, in the middle
    **mov edi,4; // Set this lower than z so it will start with increasing
    **mov port3,50; // May need alteration, the fade rate
    **mov port4,1; // Always display
    main:
    **cmp edx,5; // To get the number to multiply x and y by
    **jg alterz;
    **mov ebp,edx; // If it's at 5 or below, just use z
    midmain:
    **add ecx,esi; // Increment the counter
    **fsin eax,ecx; // Get X
    **mul eax,ebp; // Multiply by z (or altered z)
    **fcos ebx,ecx; // Get Y
    **mul ebx,ebp; // Multiply
    **mov port0,eax; // Set them all to their respective ports
    **mov port1,ebx;
    **mov port2,edx;
    **cmp ecx,6.283185; // Compare the counter to twice pi (one full revolution)
    **jg nextz; // If it's past it, we need to change z
    **jmp main; // Otherwise loop again
    nextz:
    **mov esp,edx; // Store edx here temporarily
    **sub esp,edi; // And subtract the previous from the current
    **add edx,esp; // So here, we can add this to both edx
    **add edi,esp; // and edi to increment or decrement, depending on
    **mov ecx,0; // the trend.
    **cmp edx,0; // And now see if it's below 0 or above 10, and change the trend if it is
    **jl incz;
    **cmp edx,10;
    **jg decz;
    **jmp main;
    incz:
    **mov edx,1;
    **mov edi,0;
    **jmp main;
    decz:
    **mov edx,9;
    **mov edi,10;
    **jmp main;
    alterz:
    **mov esp,edx; // Store the Z in an editable variable
    **sub esp,5; // Subtract 5
    **mov ebp,2; // Put 2 in the temporary Z
    **mul ebp,esp; // Multiplies 2 x (Z - 5)
    **mov esp,ebp; // Put that in ESP
    **mov ebp,5; // Put 5 here
    **sub ebp,esp; // And here we have 5 - 2(Z - 5)
    **jmp midmain;
    I also have one very small and odd problem with this code, and I don't understand it at all.
    Sometimes, when it's at a Z value of 1 and 0, or 9 and 10, it will suddenly make a full-width circle, rather than a next-to-0 width circle. Help? Looking at the code, that should simply not happen...

    Edit: Added a bit of structure. xD

    Edit again: Much simpler, same idea, I enjoy making pretty shapes on the holograph thing. It works much better than with timers, too, because they're all out of synch and bleh. Here we are. Perfect cube, and this one works precisely as planned.
    Code:
    // Input: Attach a running timer to Port0
    // Output: Holograph X - Port 0
    //******** Holograph Y - Port 1
    //******** Holograph Z - Port 2
    CODE;
    mov ebx,1;
    main:
    **mov port0,0; // Alternate between four coordinates
    **mov port1,0;
    **halt 0;******// Wait for the timer to think
    **mov port0,1; // You can use 250,000 clock speed if you want, because of this
    **mov port1,0;
    **halt 0;
    **mov port0,1;
    **mov port1,1;
    **halt 0;
    **mov port0,0;
    **mov port1,1;
    **halt 0;
    **add eax,ebx; // Add the incremental, ebx, to Z
    **mov port2,eax; // And output it, of course
    **cmp eax,10; // See if it's at 10 or 0, and alter the incremental
    **jge blarg; // if it is
    **cmp eax,0;
    **jle nub;
    **jmp main;
    blarg:****// I'm tired, give me a break with these labels
    **mov ebx,0;
    **dec ebx; // Roundabout way to get -1 =P
    **jmp main;
    nub:
    **mov ebx,1;
    **jmp main;

  2. #2
    Wire Sofaking tomb332's Avatar
    Join Date
    Mar 2007
    Location
    Birmigham,UK
    Posts
    1,377

    Default

    erm i think i know why its jumping and that is you know you are using ESP? well esp is the stack pointer which is the variable the CPU uses to track where the stacks current location is and shouldent really be messed with. Also a way to make life easyer to read is to declaire some variables at the beginning and use them insted of registers.

    PS to declair vars use this code at the beginning
    Code:
    DATA;
    ****alloc varName;
    ****.....(etc as many as you want)
    CODE;
    (now start your code)
    to access vars just use their name with a # infront eg #varName
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

    Super Easy Wire Download

  3. #3
    Wire Noob Killa-X's Avatar
    Join Date
    Apr 2007
    Posts
    21

    Default

    I already made a sphere doing it my own way
    http://img123.imageshack.us/my.php?image=g...ruct0000us5.jpg

    It's a different way to do this, But hey.
    Light Blue - Sky
    Green - Grass
    Blue - Water
    Red - Lava

    Good luck with your way though.

  4. #4
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default

    That is not a sphere
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  5. #5
    Wire Noob Dimencia's Avatar
    Join Date
    Mar 2007
    Location
    North Carolina
    Posts
    25

    Default

    Ah, I was lazy and I really don't like using the # symbol, so I was hoping since I didn't use the stack at all, ESP would be fine ... I'll go try it with a different variable.

  6. #6
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default

    Its okay if you use ESP, unless you use one of following commands: CALL, PUSH, POP, RET
    Those operate with stack, and using ESP will break everything.

    It all depends on style, for simple tasks that do not need heavy structuring you may even ignore the stack model at all.
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  7. #7
    Wire Noob Megalan's Avatar
    Join Date
    Mar 2007
    Posts
    6

    Default

    Please give adv. duplicator save for this code.

  8. #8
    Wire Noob Dimencia's Avatar
    Join Date
    Mar 2007
    Location
    North Carolina
    Posts
    25

    Default

    To do as much, I would go recreate it myself by copying this into a .txt file, putting it in steam/steamapps/username/garrysmod/garrysmod/data/CPUfiles/blarg.txt , and then recreate it. But I'm lazy, so feel free to do so yourself! And I don't know if it's CPUfiles, but you'll find the one that says CPU. Besides which, it doesn't work too well

+ Reply to Thread

Similar Threads

  1. Complex stuff made easy
    By Black Phoenix in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 16
    Last Post: 01-21-2009, 11:04 AM
  2. Simple things made complex
    By itsbth in forum Finished contraptions
    Replies: 3
    Last Post: 01-21-2009, 01:21 AM
  3. Making a sphere with Holo emitter.
    By CowThing in forum Installation and Malfunctions Support
    Replies: 8
    Last Post: 12-08-2008, 09:02 AM
  4. Help! I need someone to help me with a complex math problem
    By Meatloaftwo in forum Wiremod General Chat
    Replies: 2
    Last Post: 12-01-2007, 10:10 PM
  5. Sphere That Connects Two Wired Transferers?
    By ChAoZz in forum Wiremod Addons & Coding
    Replies: 3
    Last Post: 11-12-2007, 10:35 AM

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