Skip to content

Commit

Permalink
Merge pull request #4 from FewerElk/V1
Browse files Browse the repository at this point in the history
  • Loading branch information
FewerElk committed Mar 9, 2023
2 parents 18fc6ed + a5d1a23 commit 2ba3070
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 86 deletions.
5 changes: 4 additions & 1 deletion errors.py → Python_3D_Libs_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class CubePointsError(Object3DError):
pass

class PointError(Exception):
pass
pass

class NotTestedCodeWarning(Warning):
pass
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Python-3DLibs
This project will be a python librairy who allow you to create easily 3D app.
I NEED HELP FOR THIS PROJECT !
This project will be a python librairy who allow you to create easily 3D app.
2 changes: 1 addition & 1 deletion object3D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Classe of 3D objects"""
from errors import *
from Python_3D_Libs_errors import *

class Object3D(object):
def __init__(self, points, color, id_='DO NOT TOUCH IT !'):
Expand Down
99 changes: 20 additions & 79 deletions screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#IMPORT
from tkinter import *
import object3D #Dev in the project
from errors import *
from Python_3D_Libs_errors import *

class Screen(object):
"""Screen is a class who create a Tk screen, and who can have 3d objects."""
Expand All @@ -26,7 +26,9 @@ def __init__(self, width, height, title, background="white", type3d="num", lock=
self.lock = lock
self.showgrid = showgrid

#Spectator values :
self.zoom = 1

#Spectator values :ignore
self.x = 0
self.y = 0
self.z = 0
Expand Down Expand Up @@ -74,65 +76,6 @@ def showgridf(self):
if self.showgrid == False:
self.showgrid = True

def allow_move(self):
self.screen.bind("<B2-Motion>", self.move)
self.last_x = 0
self.last_y = 0

def move(self, event):
x = event.x
y = event.y
#Determine the type of the event
if x < self.last_x:
etx = "Left"
elif x > self.last_x:
etx = "Right"
else:
etx = None
if y < self.last_y:
ety = "Up"
elif y > self.last_y:
ety = "Down"
else:
ety = None

#Move
if etx == "Left":
v = self.last_x - x
self.move_l(v)
if etx == "Right":
v = x - self.last_x
self.move_r(v)
if ety == "Up":
v = self.last_y - y
self.move_u(v)
if ety == "Down":
v = y - self.last_y
self.move_d(v)

self.last_x = x
self.last_y = y

self.reload()
self.allow_move()


def move_l(self, value):
print("I go to the left with value {0}".format(value))
self.x += value

def move_r(self, value):
print("I go to the right with value {0}".format(value))
self.x -= value

def move_u(self, value):
print("I go to the up with value {0}".format(value))
self.y -= value

def move_d(self, value):
print("I go to the down with value {0}".format(value))
self.y += value

def mainloop(self):
mainloop()

Expand All @@ -146,10 +89,9 @@ def add_object(self, object3d):


def reload(self):
"""Reload the Screen."""
"""Reload the Screen : show modifications"""
self.list_points = []
self.priority = []
#self.set_priority()
self.screen.destroy()
self.screen = Canvas(self.screen_f, width=self.width, height=self.height, bg=self.bc)
self.screen.pack()
Expand All @@ -165,14 +107,8 @@ def reload(self):
if not(len(x) == 2):
raise PointError("A point hasn't got 3 coords.")


self.build()

def set_priority(self):
"""Give the priority of visual (what I show or not)"""
pass

def convertise(self, point3d, perspective="//"):
def convertise(self, point3d, perspective="()"):
"""Convertise points 3d to a points 2d.
Arguments:
- point 3d : the point 3d (tuple of the 3 axis)
Expand All @@ -191,16 +127,26 @@ def _convertise_parallel(self, point3d):
"""Convertise a 3d point to a 2d point with the rules of the isometric perspective.
Arguments :
- point3d : the point3d who will be convertised."""
return (point3d[0]/(point3d[2]*self.x+1.5),
point3d[1]/(point3d[2]+self.y+1.5)) #will be changed, it is for a test.
raise NotTestedCodeWarning("This method wasn't tested / coded ! Please check the version of the librairie.")

def _convertise_humain(self, point3d):
"""Convertise a 3d point to a 2d point with the rules of the "humain" perspective.
Arguments :
- point3d : the point3d who will be convertised."""
return ((point3d[0] + point3d[2]/2)*self.zoom,
(point3d[1] + point3d[2]/2)*self.zoom)
factor = (point3d[2] / 10) * self.zoom
return ((point3d[0] * factor),
(point3d[1] * factor))

def set_zoom(self, zoom):
"""Modify the zoom factor.
Arguments :
- zoom : the new zoom factor --> float (0 < zoom)"""
self.zoom = zoom


def build(self, mode="//"):
def build(self, mode="()"):
"""Build all the 3d object into the screen"""
for i in self.list_object:
#convert edges
Expand Down Expand Up @@ -229,9 +175,4 @@ def build(self, mode="//"):
def get_id(self):
"""Return a new id for a new 3D object."""
return len(self.list_object) + 1

def addframe(self):
"""Add a "border" to the screen"""
p1 = self.convertise((0, 0, 0))
p2 = self.convertise((self.width, self.height, 0))
self.screen.create_rectangle(p1[0], p1[1], p2[0], p2[1], outline="black")

5 changes: 2 additions & 3 deletions testfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from object3D import *

if __name__ == "__main__":
print("DO NOT USE IT LIKE THAT ! It is a module of a librairie !")
module = Screen(410, 410, "yo le test")
a = object3D.Cube([(10, 10, 10), (20, 10, 10), (20, 10, 20), (10, 10, 20), (10, 20, 20), (10, 20, 10), (20, 20, 10), (20, 20, 20)], color="blue", id_=module.get_id())
module.add_object(a)
module.allow_move()
module.addframe()
module.addquitbutton("EXIT")
module.set_zoom(5)
module.build()
module.mainloop()

0 comments on commit 2ba3070

Please sign in to comment.