Skip to content

Examples

B1j2754 edited this page Dec 14, 2024 · 1 revision

Examples:

Simple Demo

while(mouse()) {
    if (mouse()) {
    say("yup")
    } else {
        if (mouse()) {
            say("yup")
        } else {
            move(2)
        }
        say("yup")
    }
    say("nope")
}

Mandelbrot Set

# Chatgpt's: Mandelbrot set
whenFlag() {
    penClear() # Erase everything from the screen
    setfx("ghost", 100) # Hide the sprite to avoid blocking the view, while still allowing it to be 
    clearCounter()

    # Initialize variables
    setvar($resolution, 1) # Control the resolution (higher = coarser grid, lower = finer grid)
    setPenSize($resolution) # Adjust the pen size based on resolution

    gotoXY(-150, 150) # Start position for drawing (top-left corner)

    hexPen("#000000") # Black for points in the set
    setPen("brightness", 100)
    penDown()

    # Constants for the Mandelbrot set
    setvar($maxIterations, 100)
    setvar($xMin, -2.0)
    setvar($xMax, 1.0)
    setvar($yMin, -1.5)
    setvar($yMax, 1.5)

    # Calculate grid dimensions
    setvar($width, divide(300, $resolution))  # Horizontal steps
    setvar($height, divide(300, $resolution)) # Vertical steps

    # Initialize grid position variables
    setvar($steps, 0)     # Vertical step (Y-axis)
    setvar($stepsX, 0)    # Horizontal step (X-axis)

    repeat($height) {
        # Calculate the Y-coordinate for the current row
        setvar($y, add($yMax, multiply(divide($steps, $height), subtract($yMin, $yMax))))
        setvar($stepsX, 0) # Reset horizontal steps for each row

        repeat($width) {
            # Calculate the X-coordinate for the current column
            setvar($x, add($xMin, multiply(divide($stepsX, $width), subtract($xMax, $xMin))))

            # Reset variables for the Mandelbrot iteration
            setvar($zRe, 0)
            setvar($zIm, 0)
            setvar($iter, 0)
            setvar($zMagnitude, 0)

            while(and(lt($iter, $maxIterations), lt($zMagnitude, 4))) {
                setvar($zReTemp, subtract(multiply($zRe, $zRe), multiply($zIm, $zIm)))
                setvar($zIm, add(multiply(2, multiply($zRe, $zIm)), $y))
                setvar($zRe, add($zReTemp, $x))
                setvar($zMagnitude, add(multiply($zRe, $zRe), multiply($zIm, $zIm))) # Magnitude calculation
                changeVar($iter, 1)
            }

            # Determine pixel color
            if (equals($iter, $maxIterations)) {
                hexPen("#000000") # Black for points in the set
            } else {
                setPen("brightness", multiply(100, divide($iter, $maxIterations))) # Grayscale gradient
            }

            # Move to the correct position and draw the pixel
            gotoXY(add(-150, multiply($stepsX, $resolution)), subtract(150, multiply($steps, $resolution)))
            penDown()
            move($resolution) # Draw the pixel with adjusted size
            penUp()

            changeVar($stepsX, 1) # Increment X step
        }

        changeVar($steps, 1) # Increment Y step
    }

    penUp()
    timeSay("Mandelbrot Set Complete", 1) # Display the message for 3 seconds
}

Syntax All-Block Test

whenFlag(){
    clearcounter()
    setSize(5)
    gotoXY(0,0)
    penclear()
    pendown()
    setpen("brightness",50)
    hexpen("#96d056")
    point(90)
    setvar($steps,0)
    listdeleteall(@positions)
    listadd("",@positions) # somth
    while(not(touching("_edge_"))){
        changevar($steps,1)
        move($steps)
        turn(subtract(360,$steps))
        incrcounter()
        listadd("",@positions) # somth else
        if (mouse()) {
            timesay("You have clicked your mouse. This means that you went to your mouse and use your pointer finger to click it. (maybe) (maybe not)  This means that you went to your mouse and use your pointer finger to click it. (maybe) (maybe not)",0.5) # this is a comment test
        } else {
            say("Ur not clicking ur mouse")
        } # 1
    } # 2
} # 3

whenkey("space"){ # 2nd part pls work
    say("hiiiiiii") # cmonnn lesgo
    sendbroadcast("doobee") # This is hypotheoretically useless. Just like the word "hypotheoretically"
}

whentouching("_mouse_"){
    say("ouch. you hit me") # or whatev
}

Clone this wiki locally