Paste #71208: Circle Generator v0.1

Date: 2020/06/22 18:24:52 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


CircleGenerator:
    type: task
    debug: false
    # Centre is the centre of the circle.
    # Radius is the size of the circle.
    # Step size is the distance between each point.
    # Effect is the type of effects to play.
    # Delay is the delay between creating each point.
    definitions: centre|radius|stepsize|effect|delay
    script:
        - if !<[centre].exists>:
            - narrate "<red>A centre point must be specified!"
            - stop
        # Start at 0.
        - define angle 0
        # Default the radius to 1 block.
        - if !<[radius].exists>:
            - define radius 1
        # Default the step size to 0.1 blocks.
        - if !<[stepsize].exists>:
            - define stepsize 0.1
        # Default the effect to a flame.
        - if !<[effect].exists>:
            - define effect flame
        # Select a random effect
        - if <[effect]> == random:
            - define effect <server.particle_types.random>
        # Instantly create if no delay is specified.
        - if !<[delay].exists>:
            - define delay 0
        - define points <list[]>

        # We want to step until the angle is 2 x pi (a full circle is 2 x pi radians.).
        - while <[angle].is[LESS].than[<util.pi.mul[2]>]>:
            # calculate X
            - define x <[radius].mul[<[angle].cos>]>
            # calculate Z (for some stupid reason Y is up and down).
            - define z <[radius].mul[<[angle].sin>]>
            # Add our step size to the total angle.
            - define angle:+:<[stepsize]>
            # Add the point to our list.
            - define points:->:<[centre].add[<[x]>,0,<[z]>]>

        # Delay each step if specified in our run.
        - if <[delay]> != 0:
            # Playeffect at each point individually.
            - foreach <[points]> as:point:
                - playeffect effect:<[effect]> at:<[point]> offset:0 quantity:2
                # Deley between each point.
                - wait <[delay]>t
            - stop
        # If delay is 0 (instant), we create the circle in one hit.
        - playeffect at:<[points]> effect:<[effect]> offset:0 quantity:2