Python Forum
The graphic/simulator is not loading in OOP version
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The graphic/simulator is not loading in OOP version
#1
I transformed my existing code to an OOP version. Now I have the problem that the plantes of my solar system are not loaded anymore. Nothing is loaded. Just a white screen. But I also dont get any errors showing whats wrong. It should be exactly the same just in OOP. So its first the parameters for the program to calculate with. And then the different Planets coming. In the normal Version I shortened it, it just continues till Pluto.

Normal Code:

#array liste von Planeten
    planets = []

    #Sonne
    sun = sphere(pos = vec(0,0,0), radius = s_rad1,texture = "http://i.imgur.com/yoEzbtg.jpg", make_trail = True ) 
    sun.mass = 2e30   
    sun.velocity = vec(0,0,0)

    #Merkur
    mercury = sphere(pos = vec(ae/3,0,0), radius = s_rad1/2, color=color.red, make_trail = True ) 
    mercury.mass = 3.25e23
    mercury.velocity = vec(0,0,-47000)

    #Venus
    venus = sphere(pos = vec(ae/1.6,0,0), radius = s_rad1/1.8, color=color.cyan, make_trail = True ) 
    venus.mass = 4.9e24
    venus.velocity = vec(0,0,-35000)

    #Erde
    earth = sphere (pos = vec(ae, 0, 0), radius = e_rad, texture = "http://i.imgur.com/rhFu01b.jpg", make_trail = True)
    earth.mass = 5.9e24    
    earth.velocity = vec(0,0,-25000)#bewegt sich mit 30000 ms



    #Mars
    mars = sphere (pos = vec(ae*1.52, 0, 0), radius = s_rad1/1.8, make_trail = True, color = color.red)
    mars.mass = 6.4e23    
    mars.velocity = vec(0,0,-24000)#bewegt sich mit 30000 ms

...

planets.extend((mercury,venus,earth,mars,jupiter,saturn,uranus,neptun,pluto))
OOP VERSION:


#array liste von Planeten
planets = []


class Sphere(object):
    def __init__(self, pos, radius, make_trail):
        self.pos = pos
        self.radius = radius
        self.make_trail = make_trail


class Planet(Sphere):
    def __init__(self, pos, radius, make_trail, mass, velocity):
        super().__init__(pos, radius, make_trail)
        self.mass = mass
        self.velocity = velocity


sun = Planet(pos=vec(0,0,0),radius=s_rad1, make_trail=True, mass=2e30, velocity=vec(0,0,0))
mercury = Planet(pos=vec(ae/3,0,0), radius=s_rad1/2, make_trail=True, mass=3.25e23, velocity=vec(0,0,-47000))
venus = Planet(pos=vec(ae/1.6,0,0), radius=s_rad1/1.8, make_trail=True, mass=4.9e24, velocity=vec(0,0,-35000))
earth = Planet(pos=vec(ae,0,0), radius=e_rad, mass=5.9e24, make_trail=True, velocity=vec(0,0,-25000))
mars =  Planet(pos=vec(ae*1.52,0,0), radius=s_rad1/1.8, make_trail=True, mass=6.4e23, velocity=vec(0,0,-24000))
jupiter = Planet(pos=vec(ae*5.18,0,0), radius=s_rad1/1.2, make_trail=True, mass=10e27, velocity=vec(0,0,-9678))
saturn = Planet(pos=vec(ae*9.5,0,0), radius=s_rad1/1.4, make_trail=True, mass=5.7e26, velocity=vec(0,0,-7678))
uranus = Planet(pos=vec(ae*19.13,0,0), radius=s_rad1/1.7, make_trail=True, mass=8.7e25, velocity=vec(0,0,-6772))
neptun = Planet(pos=vec(ae*30,0,0), radius=s_rad1/1.7, make_trail=True, mass=1.02e26, velocity=vec(0,0,-5344))
pluto = Planet(pos=vec(ae*39.37,0,0), radius=s_rad1/2.4, make_trail=True, mass=1.3e22, velocity=vec(0,0,-4740))

planets.extend((mercury,venus,earth,mars,jupiter,saturn,uranus,neptun,pluto))
Reply
#2
(Sep-05-2018, 06:07 PM)Caturix99 Wrote: Now I have the problem that the plantes of my solar system are not loaded anymore.
I don't understand this. Where should the planets be loaded? What your code does is creating 10 Planet instances and append them to the 'planets' list. Do you expect anything else? By the way, the sun is not a planet!
Reply
#3
(Sep-05-2018, 06:13 PM)Gribouillis Wrote:
(Sep-05-2018, 06:07 PM)Caturix99 Wrote: Now I have the problem that the plantes of my solar system are not loaded anymore.
I don't understand this. Where should the planets be loaded? What your code does is creating 10 Planet instances and append them to the 'planets' list. Do you expect anything else? By the way, the sun is not a planet!
This is just an excerpt of my code. There are the variables and functions my solar system is working. But not with the OOP version. And I figured out that when it has to be in this part of the code. I thought I did something wrong with the OOP version. Because the planets are not loaded so I dont see them visually in the simulator, but in the normal version I see them. (And I know that the sun isn't a planet. lol)
Reply
#4
Why is it sphere in the old code and Sphere in the OO version?
Reply
#5
(Sep-05-2018, 07:25 PM)Gribouillis Wrote: Why is it sphere in the old code and Sphere in the OO version?

well this shouldn't be a problem because this is only the name of the class(it doesn't change when I right sphere. But I suppose that the problem is somewhere there because sphere is in VPython a keyword to create a sphere. But I dont think this class knows that it has to create a sphere. I dont know how to do that. or is it just like another attribute and then set it to True?
Reply
#6
The main problem that I see is that you're filling the planets list with objects having a different type, namely the type Planet instead of whatever type was returned by the call to sphere() in the first version. You cannot send an unexpected type of objects in a system and think the system will work as usual. The disturbing fact here is that you don't have an error message, that is to say the system silently ignores your ill-typed instances. I think it is a design flaw in this app.

I think there is not much you can do until you understand what the system exactly expects to find in the planets list.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  elevator simulator...whats the wrong at this code? tasos710 5 2,839 Jun-11-2019, 01:38 AM
Last Post: micseydel
  Embedding Python into a simulator siggi 0 1,071 Apr-24-2019, 07:42 PM
Last Post: siggi
  Can I upload a new version without previously deleting ancient version sylas 6 2,192 Nov-08-2017, 03:26 PM
Last Post: Larz60+
  Graphic of total different connection opened by one ip (per seconds) by time FoxModem56k 0 1,965 May-25-2017, 03:27 PM
Last Post: FoxModem56k

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020