2026. június 10., szerda

Mindössze 6 sor a naprendszer működésének modellezése pythonban


------------
6 sorban
----------
import turtle, math; w=turtle.Screen(); w.setup(858,858); w.bgcolor("black"); w.tracer(0); n=turtle.Turtle("circle"); n.color("yellow"); n.shapesize(3); n.up(); b, p=[], [("gray",.3,45,.47,35),("orange",.7,72,.35,42),("blue",.8,108,.3,78),("red",.5,144,.24,84),("brown",1.5,198,.13,98),("yellow",1.2,252,.1,52),("light blue",.1,306,.07,76),("blue",.1,360,.05,360)]
for c,sz,t,sb,inc in p: pt=turtle.Turtle("circle"); pt.color(c); pt.shapesize(sz); pt.up(); b.append([pt,t,sb,math.radians(inc),0]); h=turtle.Turtle("circle"); h.color("white"); h.shapesize(0.3); h.up(); hs=0
while True:
    for j,d in enumerate(b): d[4]+=d[2]; r=math.radians(d[4]); x,y,i=d[1]*math.cos(r),d[1]*math.sin(r),d[3]; d[0].goto(x-y*0.5,y*math.cos(i)*math.sin(i)+(x+y*math.cos(i)*0.866)*0.5);
    if j==2: h.goto(d[0].xcor()+15*math.cos(hs),d[0].ycor()+15*math.sin(hs)); hs+=0.5
    w.update()
--------------------

Emulálás; https://onecompiler.com/tkinter#draft-a4w4


Nincsenek megjegyzések:

Megjegyzés küldése