lew247
 Guru
 Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Posted: 03:09pm 08 Feb 2022 |
Copy link to clipboard |
 Print this post |
|
Can anyone help with this one? I really cannot remember how it was done in teh first place It's "python"
Ive got a compass on a screen thats HRES = 1920 VRES = 1080
and I've now changed the orientation of the screen to portrait mode and altered the resolution so it's now 1080x1920
What I want to do is change the compass code below so the centre of the compass is higher to the top of the screen but I can't figure out how to set the position of X, Y, WID, and CX and CY so I can heep the horizontal centre of the compass but move the vertical centre higher
this is the code if anyone is able to help
def rotateTriangle(angle_deg, pointerRelPoints): angle_rad = angle_deg*2*pi/360 res = [] for (x,y) in pointerRelPoints: xrot = x*cos(angle_rad) - y*sin(angle_rad) yrot = x*sin(angle_rad) + y*cos(angle_rad) res.append((xrot,yrot)) return res
def renderCompassRose(cx, cy, wid): """Render compass rose to screen at given coordinates and size."""
ren = pg.transform.rotozoom(font.render("NE", 1, pg.Color(1,1,1), pg.Color(134,174,230)), -45, 0.9) x = cx+1.1*wid*cos(pi/4)-ren.get_width()//2 y = cy-1.1*wid*sin(pi/4)-ren.get_height()//2 screen.blit(ren, (x,y))
ren = pg.transform.rotozoom(font.render("SE", 1, pg.Color(1,1,1), pg.Color(134,174,230)), -135, 0.9) x = cx+1.1*wid*cos(pi/4)-ren.get_width()//2 y = cy+1.1*wid*sin(pi/4)-ren.get_height()//2 screen.blit(ren, (x,y))
ren = pg.transform.rotozoom(font.render("NW", 1, pg.Color(1,1,1), pg.Color(134,174,230)), 45, 0.9) x = cx-1.1*wid*cos(pi/4)-ren.get_width()//2 y = cy-1.1*wid*sin(pi/4)-ren.get_height()//2 screen.blit(ren, (x,y))
ren = pg.transform.rotozoom(font.render("SW", 1, pg.Color(1,1,1), pg.Color(134,174,230)), 135, 0.9) x = cx-1.1*wid*cos(pi/4)-ren.get_width()//2 y = cy+1.1*wid*sin(pi/4)-ren.get_height()//2 screen.blit(ren, (x,y))
ren = font.render("N", 1, pg.Color(1,1,1), pg.Color(134,174,230)) screen.blit(ren, (cx-ren.get_width()//2, cy-1.15*wid-ren.get_height()//2))
ren = font.render("S", 1, pg.Color(1,1,1), pg.Color(134,174,230)) screen.blit(ren, (cx-ren.get_width()//2, cy+1.15*wid-ren.get_height()//2))
ren = font.render("E", 1, pg.Color(1,1,1), pg.Color(134,174,230)) screen.blit(ren, (cx+1.15*wid-ren.get_width()//2, cy-ren.get_height()//2))
ren = font.render("W", 1, pg.Color(1,1,1), pg.Color(134,174,230)) screen.blit(ren, (cx-1.15*wid-ren.get_width()//2, cy-ren.get_height()//2))
#tick marks, every 5 degrees (360/5 = 72) a = 0.0 while a<2*pi: x1 = cx + cos(a)*(wid-4*HRES//1600) y1 = cy - sin(a)*(wid-4*VRES//900) x2 = cx + cos(a)*(wid+1*HRES//1600) y2 = cy - sin(a)*(wid+1*VRES//900) pg.draw.line(screen, pg.Color('white'), (x1, y1), (x2, y2), 1) a+=2*pi/72
#pointers to cardinal directions a = 0 while a<2*pi: x1 = cx - sin(a)*(wid + 2*HRES//1600) y1 = cy - cos(a)*(wid + 2*VRES//900) x2 = cx + cos(a)*wid*0.11 y2 = cy + sin(a)*wid*0.11 x3 = cx - cos(a)*wid*0.11 y3 = cy - sin(a)*wid*0.11 a += pi/2
#The compass pointer triangle forecastData = forecastObj.getData() skyData = skyDevice.getData() pointerBase = COMPASS_POINTER_BASE_SIZE*HRES//1600 pointerRadius = wid-4*HRES//1600 pointerRelPoints = [(0,-pointerRadius), (-pointerBase/1,0),(pointerBase/2,0)] #coordinates translated to compass center on screen pointerRelPointsRotated = rotateTriangle(skyData.wind_bearing, pointerRelPoints) pointerAbsPoints = [(int(x)+cx,int(y)+cy) for (x,y) in pointerRelPointsRotated] if skyData.wind_speed > 0: pg.draw.polygon(screen, pg.Color('blue'), pointerAbsPoints) pg.draw.circle(screen, pg.Color(134,174,230), (cx, cy), int(wid*0.76)) pg.draw.circle(screen, pg.Color('white'), (cx, cy), int(wid*0.75), 1) |