Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:15:32+00:00 2026-05-13T09:15:32+00:00

I am a newb in Visual module in python, not really understand how does

  • 0

I am a newb in Visual module in python, not really understand how does it assign a value to an objects.
say

from visual import *
stars=[]
galaxies=[]    
for i in range(10):
   stars+=[sphere('pos,radius,color.....')]
for j in range(20):
   galaxies+=[sphere('pos,radius,color......')]
for k in range(30):
   stars[k].pos=position[k] 
   galaxies[k].pos=G_position[k]

i just can not understand, normally, when python read this code, the list would be fully finished after the for loop, but after import visual module, those spheres can show up on screen and update their positions by each iteration of the last for loop!…

or my question may also link to what and where the “show()”,”print” “start the animation” statement in the visual module and how does it work? how may I use it?

kind of like if I add print state with in the for loop or after it finished.

Thanks alot in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:15:32+00:00Added an answer on May 13, 2026 at 9:15 am

    First things first. Your code uses list concatenation to add stuff to the list. It is better to use the .append() method of lists. Also, the last loop could iterate directly on the objects instead of using an index. It is more elegant and easy to understand this way.

    The pseudo-code below is equivalent to yours, but with the above corrections applied:

    from visual import *
    stars = []
    galaxies = []    
    for i in  range(10):
       stars.append(sphere(...))
    for j in range(20):
       galaxies.append(sphere(...))
    for star, galaxy, starpos, galaxypos in zip(stars, galaxies, 
                                                position, G_position):
       star.pos = starpos
       galaxy.pos = galaxypos
    

    With that out of the way, I can explain how visual works.

    Visual module updates the screen as soon as the object is changed. The animation is done by that alteration, in realtime, there’s no need for a show() or start_animation() – it happens as it goes. An example you can run on python command line:

    >>> from visual import sphere
    >>> s = sphere()
    

    That line creates a sphere, and a window, and shows the sphere in the window already!!!

    >>> s.x = -100
    

    That line changes the sphere position on x axis to -100. The change happens immediatelly on the screen. Just after this line runs, you see the sphere appear to the left of the window.

    So the animation happens by changing the values of the objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 384k
  • Answers 384k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is just an educated guess. I think it's because… May 14, 2026 at 11:15 pm
  • Editorial Team
    Editorial Team added an answer Well, since you're tying into an array, I'd just check… May 14, 2026 at 11:15 pm
  • Editorial Team
    Editorial Team added an answer I started to dig into how this all works and… May 14, 2026 at 11:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.