dc.drawRectangle() radius and other objects...?

Hi, do they need advice on how to create a radius for a square, then how to draw a straight line horizontally and vertically?

dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
dc.setPenWidth(1.5);
dc.drawRectangle(40, 80, 125, 100);


Thank you

  • hmmm radius for circle inside square?

    r = square_width / 2 (actually square_width should be equal to square_height)

    drawArc(x, y, r, attr, degreeStart, degreeEnd)

    vertical line just a line where start point and end point have the same X coordinate

    horizontal line - the same Y coordinate 

    drawLine(x1, y1, x2, y2)

    in case you want to make pointing cross inside square with circle just draw to lines where vertical x = x_square_left corner + r and horizontal y = square_top_corner +r 

  • Thank you very much, could I ask for a simple code where will everything be to understand the meaning? I am a beginner and I try to create my watchFace.

    Thank you

  • WatchFace with the aim cross? hmmm interesting

  • NO

    rounded squares - edges...

    dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
    dc.setPenWidth(1.5);
    dc.drawRectangle(40, 80, 125, 100);

    Radius xxx???

  •     function drawAimCross(dc){
        	var squareCornerX = 120;
        	var squareCornerY = 180;
        	var squareWidth = 41;
        	var squareHeight = 41;
        	
        	dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
    		dc.setPenWidth(1);
    		dc.drawRectangle(squareCornerX, squareCornerY, squareWidth, squareHeight);
    		
    		//calculating circle center
    		var circleX = squareCornerX + squareWidth / 2;
    		var circleY = squareCornerY + squareHeight /2;
    		
    		//calculating circle radius (actually as we have squareWidth and squareHeight it is not square rather rectangle, but who cares
    		var circleR = squareWidth / 2;
    		
    		//draw the circle
    		dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT);
    		dc.setPenWidth(2);
    		
    		dc.drawCircle(circleX, circleY, circleR);
    		
    		//draw aim cross (center of circle is also center of the aim cross)
    		dc.drawLine(squareCornerX, circleY, squareCornerX + squareWidth, circleY);
    		dc.drawLine(circleX, squareCornerY, circleX, squareCornerY + squareHeight);
        }

  •     function drawAimCross(dc){
        	var squareCornerX = 120;
        	var squareCornerY = 180;
        	var squareWidth = 41;
        	var squareHeight = 41;
        	
        	var roundedRectangleX = 120;
        	var roundedRectangleY = 10;
        	
        	dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
    		dc.setPenWidth(1);
    		dc.drawRectangle(squareCornerX, squareCornerY, squareWidth, squareHeight);
    		
    		//rounded rectangle
    		dc.setColor(Gfx.COLOR_GREEN, Gfx.COLOR_TRANSPARENT);
    		dc.setPenWidth(2);
    		//calculate rounded rectangle radius
    		var rrr = (squareWidth + squareHeight) / 20; // 20 is optional, but should be nice
    		dc.drawRoundedRectangle(roundedRectangleX, roundedRectangleY, squareWidth, squareHeight, rrr);
    		
    		
    		//calculating circle center
    		var circleX = squareCornerX + squareWidth / 2;
    		var circleY = squareCornerY + squareHeight /2;
    		
    		//calculating circle radius (actually as we have squareWidth and squareHeight it is not square rather rectangle, but who cares
    		var circleR = squareWidth / 2;
    		
    		//draw the circle
    		dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT);
    		dc.setPenWidth(2);
    		
    		dc.drawCircle(circleX, circleY, circleR);
    		
    		//draw aim cross (center of circle is also center of the aim cross)
    		dc.drawLine(squareCornerX, circleY, squareCornerX + squareWidth, circleY);
    		dc.drawLine(circleX, squareCornerY, circleX, squareCornerY + squareHeight);
        }

    Just check below 

    //rounded rectangle comment

  • Thank you very much for your help, but I still want to ask if it is possible to create a circle or cubes with animation so that they circulate?

  • Yes, you can animate. You just need to change the size/shape/position over time and update the display as you go.

  • Please help me i want to make an animation on the dial where there will be a square around the whole dial which will replace the seconds.

    This link is broken: developer.garmin.com/.../WatchUi.html

    Thank You