orbita.py

Created by cpaulof

Created on February 23, 2023

2.35 KB


# Título #####################################################
#
#   Orbita V 0.21 (versao experimental)
#   
##############################################################
#
#  Carlos Paulo A. Freitas (cpaulof@gmail.com)
#  https://zonaexacta.blogspot.com
#  https://sites.google.com/view/cpaulof-prog-calc
#
############################################################## 
import time
import kandinsky
from math import *
#Cores: vou deixar 8 cores
F=255
cores = [
 [0,0,0], #0 preto
 [F,F,F], #1 branco
 [F,0,0], #2 vermelho
 [0,F,0], #3 verde
 [0,0,F], #4 azul
 [F,0,F], #5 violeta
 [F,F,0], #6 vermelho+verde=
 [0,F,F], #7
 [204,153,0] #8
]
LARGURA=320
ALTURA=240
Display = [LARGURA,ALTURA]
X_MIN = -2.5
X_MAX = 2.5
deltaX=(X_MAX-X_MIN)/(LARGURA-1)
Y_MIN =-ALTURA/2*(X_MAX-X_MIN)/LARGURA
Y_MAX = ALTURA/2*(X_MAX-X_MIN)/LARGURA
VY=(Y_MAX-Y_MIN)/2
deltaY=(Y_MAX-Y_MIN)/(ALTURA-1)
PLOT_POINTS=360 #número de pontos a utilizar para fazer o plot de um gráfico
n=10
RO=1 #raio da órbita
RS=0.3 #raio do Sol
R=0.1 #raio do planeta
################################
def plot(x,y,cor):
  c = int(LARGURA*((x - X_MIN)/(X_MAX - X_MIN))) 
  l = int(ALTURA*(1-(y - Y_MIN)/(Y_MAX - Y_MIN))) 
  if(0 <= l < ALTURA):
    if(0 <= c < LARGURA):
      col = kandinsky.color(cores[cor][0],cores[cor][1],cores[cor][2])
      kandinsky.set_pixel(c,l,col)
################################
def fill_rect(x,y,L,A,cor):
  c = int(LARGURA*((x - X_MIN)/(X_MAX - X_MIN))) 
  l = int(ALTURA*(1-(y - Y_MIN)/(Y_MAX - Y_MIN)))
  _L = int(L*(LARGURA+0.0)/(X_MAX - X_MIN))
  _A = int(A*(ALTURA+0.0)/(Y_MAX - Y_MIN))
  kandinsky.fill_rect(c,l,_L,_A,cores[cor])       
################################
def circunf(xc,yc,r,cor):
  h=2*pi/PLOT_POINTS
  for i in range(PLOT_POINTS):
    t=i*h
    x,y=xc+r*cos(t),yc+r*sin(t)
    plot(x,y,cor)
#################################
def circulo(xc,yc,r,cor):
  vertices=[]
  o=2*pi/(4*n)
  for i in range(n):
   a=i*o
   l=r*cos(a)
   h=r*sin(a)
   x=xc-l
   y=yc+h
   vertices.append((x,y,2*l,2*h))
  for v in vertices:
   fill_rect(v[0],v[1],v[2],v[3],cor)     

kandinsky.fill_rect(0,0,LARGURA,ALTURA,cores[0])
d=2*pi/36
#Sol
circulo(0,0,RS,8)
while 1==1:
  for i in range(36):
     theta=(i-1)*d
     fill_rect(RO*cos(theta)-R,RO*sin(theta)+R,2*(R+deltaX),2*(R+deltaX),0)
     #circunf(0,0,RO,2)
     theta=i*d
     circulo(RO*cos(theta),RO*sin(theta),R,3)
     time.sleep(0.08)  

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.