Help with drawing

So, I was making a script to draw a rounded rectangle, but when you put Hight and width to 0 and smoothness to 30 it shows a circle insead.

Here the code:

//% block="draw rounded rectangle at $img|x: $x|y: $y|width: $width|height: $height|smoothness: $smooth| color: $c"
    //% c.shadow="colorindexpicker"
    //% inlineInputMode=inline
    //% subcategory="Image"
    //% img.defl=picture
    //% img.shadow=variables_get
    export function RoundedRectangle(img: Image, x: number, y: number, width: number, height: number, smooth: number, c: number) {
        for (let index = 0; index <= 360; index++) {
            img.fillRect(x + Math.sin(index) * smooth, y + Math.cos(index) * smooth, width, height, c)
        }
        img.fillRect(x, y, width, height, c)
    }

If you use blocks then drawing is a LOT easier

Yes, when you’re drawing a sprite, but I think drawing a rounded rectangle (what @Cybercube is trying to draw) is easier in Java?

2 Likes
    //% block="draw rounded rectangle at $img|x: $x|y: $y|width: $width|height: $height|smoothness: $smooth| color: $c"
    //% c.shadow="colorindexpicker"
    //% inlineInputMode=inline
    //% subcategory="Image"
    //% img.defl=picture
    //% img.shadow=variables_get
export function RoundedRectangle(img: Image, x: number, y: number, width: number, height: number, smooth: number, c: number) {
    // Prevent the smoothness radius from breaking if it's larger than the shape itself
    smooth = Math.min(smooth, Math.min(width / 2, height / 2));
    if (smooth < 0) smooth = 0;

    // Draw the central rectangles
    img.fillRect(x + smooth, y, width - 2 * smooth, height, c);
    img.fillRect(x, y + smooth, width, height - 2 * smooth, c);

    // Stamp the 4 corner circles
    if (smooth > 0) {
        img.fillCircle(x + smooth, y + smooth, smooth, c)
        img.fillCircle(x + width - smooth - 1, y + smooth, smooth, c)
        img.fillCircle(x + smooth, y + height - smooth - 1, smooth, c)
        img.fillCircle(x + width - smooth - 1, y + height - smooth - 1, smooth, c)
    }
}

1 Like

it’s actually harder since there’s a drawRectangle already in there, also it’s javascript.

2 Likes

there’s actually more drawing functions in Javascript, also in my POV js is easier in almost anything.

2 Likes

yeah but like u know how to like use it while mine looks like this

1 Like

Easier to understand spaghetti code??? There’s no way that’s easier

1 Like

Oh ok thanks for clearing that up

1 Like

in blocks, comments are weird and I cant separate my lines with more empty lines

1 Like

I mean I remembered a time where you could use grey blocks to get a similar effect

2 Likes