radar.py

Created by tlake

Created on August 07, 2024

1.05 KB

Displays simulated radar screen


from geolib import *
from math import pi,cos,sin,tan
from random import randint

imax = int(input("N="))*2*pi

_r=min(ppn_w, ppn_h)//2 - 3
_step=0.15

# Center
x0, y0 = ppn_w//2, ppn_h//2

# Radar colors
C=ppn_has_color and (255,170,113,75,50,0) or (0,)+(255,)*5

# black screen
rectangle(0, 0, ppn_w, ppn_h, color=(255*(not ppn_has_color),)*3, fill="full")

# Radar outline
circle(x0,y0,_r+1,ppn_has_color and (0,C[0],0) or (C[0],)*3)

# Object
O=[]

i=0
while i<imax:
  p1=(x0+int(_r*cos(i)),y0+int(_r*sin(i)))
  for j in range(1,len(C)+1):
    p2=(x0+int(_r*cos(i-j*_step)),y0+int(_r*sin(i-j*_step)))
    drawTriangle((x0, y0),p1,p2,ppn_has_color and (0,C[j-1],0) or (C[j-1],)*3)
    p1=p2
  # draw obj
  if randint(0,100)<15:
    tmp=randint(_r//20,_r*19//20)
    O.append([x0+int(tmp*cos(i)),y0+int(tmp*sin(i)),25])
  for io in range(len(O)):
    o=O[io]
    drawTriangle((o[0],o[1]),(o[0]-_r//20,o[1]+_r//20*tan(pi/3)),(o[0]+_r//20,o[1]+_r//20*tan(pi/3)),(o[2]*10,)*3)
    O[io][2]-=1
  if(len(O) and O[0][2]==-1):
    O=O[1:]
  i+=_step
  show_screen()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.