# Rotating graphic is changing sizes at random

**URL:** <https://forum.inductiveautomation.com/t/rotating-graphic-is-changing-sizes-at-random/71822>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [March 30, 2023, 12:33pm UTC](https://forum.inductiveautomation.com/t/rotating-graphic-is-changing-sizes-at-random/71822 "2023-03-30T12:33:52Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 5, 2023, 9:05pm UTC](https://forum.inductiveautomation.com/t/rotating-graphic-is-changing-sizes-at-random/71822/26 "2023-05-05T21:05:16Z")

</div>

Well if you want it, here is what I threw together. You of course can add more customization if needed or wanted.

> **repaint script**
>
> ```auto
> from java.awt import Color
> from java.awt import RadialGradientPaint
> from java.awt import MultipleGradientPaint as mgp
> from java.awt.geom import Rectangle2D
> from java.awt.geom import Ellipse2D
> from java.awt.geom import Line2D
> from java.awt.geom import Point2D
> from java.awt import BasicStroke
> from java.awt.geom import Path2D
> import math
> g = event.graphics
> 
> #Watch Body
> 
> bodyOutline = Ellipse2D.Float(event.width * .075, event.height * .115, event.width * .85, event.height * .85)
> bodyShape = Ellipse2D.Float(event.width * .1 ,event.height * .14 , event.width * .8, event.height * .8)
> cX = bodyShape.getX() + bodyShape.getWidth() / 2
> cY = bodyShape.getY() + bodyShape.getHeight() / 2
> radius = bodyShape.width / 2
> 
> #Draw outside
> g.setStroke(BasicStroke(1.0))
> g.setPaint(Color.BLACK)
> g.draw(bodyOutline)
> 
> center = Point2D.Float(cX,cY)
> focus = Point2D.Float((radius - 10) * math.cos(math.pi / 4) + cX,(radius - 10) * math.sin(math.pi / 4) + cY)
> colors = [Color.WHITE,Color.LIGHT_GRAY,Color.GRAY]
> bodyPaint = RadialGradientPaint(center,300,focus, [0.0,0.8,1.0],colors,mgp.CycleMethod.NO_CYCLE)
> g.setPaint(bodyPaint)
> g.fill(bodyOutline)
> 
> #Draw Face
> g.draw(bodyShape)
> g.setPaint(event.source.background)
> g.fill(bodyShape)
> g.setPaint(Color.DARK_GRAY)
> g.draw(bodyShape)
> 
> #Set Font
> g.setFont(event.source.font)
> 
> #Tick Marks
> theta = -math.pi/2
> for tick in xrange(60):
> 	
> tickLength = event.source.MinorTickLength if tick % 5 else event.source.MajorTickLength
> #calculate the start and end points for the tick line
> x1 = radius * math.cos(theta) + cX
> y1 = radius * math.sin(theta) + cY
> x2 = (radius - tickLength) * math.cos(theta) + cX
> y2 = (radius - tickLength) * math.sin(theta) + cY
> 	
> 	
> tickLine = Line2D.Float(x1,y1,x2,y2)
> if tick % 5:
> g.setColor(event.source.MinorTickColor)
> g.setStroke(BasicStroke(event.source.MinorTickWidth))
> else:
> g.setColor(event.source.MajorTickColor)
> g.setStroke(BasicStroke(event.source.MajorTickWidth))
> 		
> g.draw(tickLine)
> 	
> #Draw the tick increment text
> if not tick % 5:
> 		
> 		
> fontMetrics = g.getFontMetrics()
> x2 = (radius - tickLength - (fontMetrics.getHeight() /2.0 + fontMetrics.getAscent()/5)) * math.cos(theta) + cX - (fontMetrics.stringWidth(str(tick)) / 2.0)
> y2 = (radius - tickLength - (fontMetrics.getHeight() /2.0 + fontMetrics.getAscent()/5)) * math.sin(theta) + cY + 4
> g.setColor(event.source.foreground)
> #Uncomment if you would rather it say 60 than 0
> #if tick == 0:
> #	g.drawString("60",x2,y2)
> #else:
> #tab in the next line if you uncomment the above code.
> g.drawString(str(tick),x2,y2)
> 		
> #increment theta to next angle
> theta += math.radians(360/60)
> 
> #Draw the Set-Point hand
> g.setPaint(Color.ORANGE)
> 
> spNeedle = Path2D.Float()
> radPerTick = math.radians(360/60)
> value = event.source.Setpoint
> 
> spNeedle.moveTo((radius-45) * math.cos(value * radPerTick - math.pi / 2) + cX,(radius-45) * math.sin(value * radPerTick - math.pi / 2) + cY)
> spNeedle.lineTo(3 * math.cos(value * radPerTick - math.pi) + cX,3 *math.sin(value * radPerTick - math.pi) + cY)
> spNeedle.curveTo(15 * math.cos(value * radPerTick - 5 * math.pi/4) + cX, 15 * math.sin(value * radPerTick - 5 * math.pi/4) + cY,15 * math.cos(value * radPerTick + math.pi/4) + cX,15 * math.sin(value * radPerTick + math.pi/4) + cY, 3 * math.cos(value * radPerTick) + cX, 3 * math.sin(value * radPerTick) + cY)
> spNeedle.closePath()
> g.fill(spNeedle)
> 
> #Draw the Value-Hand
> value = event.source.Value
> g.setPaint(Color.BLACK)
> vNeedle = Path2D.Float()
> vNeedle.moveTo(radius * math.cos(value * radPerTick - math.pi/2) + cX, radius * math.sin(value * radPerTick - math.pi/2) + cY)
> vNeedle.lineTo(3 * math.cos(value * radPerTick - math.pi) + cX, 3 * math.sin(value * radPerTick - math.pi) + cY)
> vNeedle.curveTo(15 * math.cos(value * radPerTick - 5 * math.pi/4) + cX, 15 * math.sin(value * radPerTick - 5 * math.pi/4) + cY, 15 * math.cos(value * radPerTick + math.pi/4) + cX, 15 * math.sin(value * radPerTick + math.pi/4) + cY, 3 * math.cos(value * radPerTick) + cX, 3 * math.sin(value * radPerTick) + cY)
> vNeedle.closePath()
> g.fill(vNeedle)
> 
> g.setPaint(event.source.SetpointColor)
> 
> #Draw Set Point Text
> fm = g.getFontMetrics()
> g.drawString(str(event.source.Setpoint),cX - fm.stringWidth(str(event.source.Setpoint)) / 2.0, cY + 50 )
> 
> #Draw Value Text
> g.setPaint(event.source.ValueColor)
> g.drawString(str(event.source.Value),cX - fm.stringWidth(str(event.source.Value)) / 2.0, cY + 65 )
> 
> ```

![stopwatch](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f1d4cc17222bbc29ce5c09d32d4c317beebbc1cc.gif)

---

_[View the full topic](https://forum.inductiveautomation.com/t/rotating-graphic-is-changing-sizes-at-random/71822)._
