0

I'm currently trying to make 3d graphics using Turtle.

I have a list of objects that have inherited the Turtle class and each one has an attribute frontFactor - this value is the distance of the turtle to the camera.

How can I make the turtles closer to the camera render on top of the other turtles behind it?

My current code trying to do this:

finished = []
highestIndex = 0
print("FRAME")
for object in objects:
    for i in range(len(object.particles)):
        curHighest = 0
        for j in range(len(object.particles)):
            if object.particles[j].frontFactor > curHighest and (not (j in finished)):
                curHighest = object.particles[j].frontFactor
                highestIndex = j
        object.particles[highestIndex].move(0,0,0)
        print(object.particles[highestIndex].frontFactor)
        finished.append(highestIndex)

where objects has an attribute of particles which is a list, and every item in this list has a value frontFactor that determines the distance to the virtual camera.

This function goes through each particle on the screen (currently i only have one object), starting from the particles farthest away from the camera and ending at the particles nearest the camera.

This is what I want to happen This is what I want to happen,

enter image description here but this is what it looks like instead. (darker particles are further away)

I've heard of a rule which states "last to move is on top" although I don't know how to implement that in this situation.

meable
  • 118
  • 8
  • 1
    In [this post](https://stackoverflow.com/a/41067307/5771269) I set down my two rules for turtle layering, the first of which is "last to arrive is on top", and the second, regarding drawing, should be reviewed as well. In [this post](https://stackoverflow.com/a/43289505/5771269) I provide a practical example of how to force a turtle to the fore. – cdlane Feb 02 '23 at 21:01

0 Answers0