Skip to content

Instantly share code, notes, and snippets.

@TalhaAkkas
Created April 1, 2011 17:53
Show Gist options
  • Save TalhaAkkas/898552 to your computer and use it in GitHub Desktop.
Save TalhaAkkas/898552 to your computer and use it in GitHub Desktop.
py in 3D
from math import *
class space ():
def __init__(self):
self.point_list = []
self.lines_list = []
self.screen_list = []
outter_space = space()
def plus(x, y):
return x + y
def minus(x, y):
return x - y
def distance(point, point1):
if type(point1) == tuple:
x = point.x - point1[0]
y = point.y - point1[1]
z = point.z - point1[2]
return (x**2 + y**2 + z**2)**0.5
x = point.x - point1.x
y = point.y - point1.y
z = point.z - point1.z
return (x**2 + y**2 + z**2)**0.5
class point():
def __init__(self, x, y, z, space):
space.point_list.append(self)
self.space = space
self.x = x
self.y = y
self.z = z
self.connected = []
self.shadow_list = []
def connect(self, point):
self.connected.append(point)
point.connected.append(self)
def get_angle(self, x, y = "", z = ""):
if x == self.x:
return 0
if (type(y) == int) or (type(y) == float):
return atan((self.y - y)/(self.x - x))
if (type(z) == int) or (type(z) == float):
return atan((self.z - z)/(self.x - x))
raise ValueError
class lines(point):
def __init__(self, angle_xy, angle_xz, point = point(0,0,0,outter_space)):
self.space = point.space
self.space.lines_list.append(self)
self.x = point.x
self.y = point.y
self.z = point.z
self.xy = angle_xy
self.xz = angle_xz
self.disty = self.y - (self.x * (sin(self.xy)))
self.distz = self.z - (self.x * (sin(self.xz)))
try:
self.space.point_list.remove(point)
except:
pass
class shadow(point):
def __init__(self,point,screen):
point.shadow_list.append(self)
screen.shadow_list.append(self)
self.point = point
self.screen = screen
self.set_reference_point()
self.set_rate()
self.x = (self.point.x - self.screen.x)*self.rate
self.y = (self.point.y - self.screen.y)*self.rate
self.z = (self.point.z - self.screen.z)*self.rate
try:
self.space.point_list.remove(self)
except:
pass
def set_reference_point(self):
y = self.get_reference_y()
z = self.get_reference_z()
x = self.get_reference_x()
self.reference_point = (x, y, z)
def get_reference_y(self):
r = ((sin(self.screen.main_line.xy)*self.point.x+self.point.y+self.screen.main_line.disty)**2)**0.5
x = ((tan(self.screen.main_line.xy)**2 * r**2) / (tan(self.screen.main_line.xy)**2 - 1)) + self.point.x
# bu satır hata vermezse ben
return x*tan(self.screen.main_line.xy)
def get_reference_z(self):
r = ((sin(self.screen.main_line.xz)*self.point.x + self.point.z+self.screen.main_line.distz)**2)**0.5
x = ((tan(self.screen.main_line.xz)**2 * r**2) / (tan(self.screen.main_line.xz)**2 - 1)) + self.point.x
# bu satır hata vermezse
return x*tan(self.screen.main_line.xz)
def get_reference_x(self):
r = ((sin(self.screen.main_line.xz)*self.point.x + self.point.z+self.screen.main_line.distz)**2)**0.5
return ((tan(self.screen.main_line.xz)**2 * r**2) / (tan(self.screen.main_line.xz)**2 - 1)) + self.point.x
def set_rate(self):
self.rate = distance(self.screen, self.screen.central_point) / distance(self.screen, self.reference_point)
class screen(lines):
def __init__(self, width, height, line):
self.space = line.space
self.space.screen_list.append(self)
self.lookat = bool(1)
self.main_line = line
self.x = line.x
self.y = line.y
self.z = line.z
self.xy = line.xy
self.xz = line.x
self.shadow_list = []
if self.lookat:
if width>height:
self.get_central_point(plus, width)
else :
self.get_central_point(plus, height)
else:
if width>height:
self.get_central_point(minus, height)
else :
self.get_central_poin.t(minus, height)
self.line_xy = lines(self.xy-radians(90), self.xz, self.central_point)
# ekranın x eksenini oluşturacak doğru
self.line_xz = lines(self.xy, self.xz-radians(90), self.central_point)
# ekranın y eksenini oluşturacak doğru
def get_central_point(self, operand, great):
great = (great/2)
y = operand(self.y, great * sin(self.xy))
xz = great * cos(self.xy)
x = operand(self.x, xz * cos(self.xz))
z = operand(self.z, xz * sin(self.xz))
self.central_point = point(x, y, z, self.space)
def ask_angle(self, x, y = "", z = ""):
if type(y) == int:
return self.central_point.get_angle(x,y = y) == self.xy
return self.central_point.get_angle(x,z = z) == self.xz
def value_of_x(self, point):
#if self.ask_angle(point.x, z = point.z):
return (point.z - self.central_point.z) * cos(self.xz)
print "value_of_x"
raise UnboundLocalError((point.z - self.central_point.z) * cos(self.xz))
def value_of_y(self, point):
#if self.ask_angle(point.x, y = point.y):
return (point.y - self.central_point.y) * cos(self.xy)
print "value_of_y"
raise UnboundLocalError()
def take_picture(self):
point_on_screen = []
connections_on_screen = []
for i in self.space.point_list:
shadw = shadow(i, self)
coordinate = (self.value_of_x(shadw),self.value_of_y(shadw))
point_on_screen.append(coordinate)
for j in i.connected:
try:
connection = (self.space.point_list.index(i),self.space.point_list.index(j))
connections_on_screen.append(connection)
except:
pass
return point_on_screen, connections_on_screen
from evet import *
from interface import *
def get_smallest(liste):
try :smallest = liste[0][0]
except IndexError: return
for i in liste:
for no in range(2):
if i[no] < smallest:
smallest = i[no]
return smallest
def get_smallest_x(liste):
try :smallest = liste[0][0]
except IndexError: return
for i in liste:
if i[0] < smallest:
smallest = i[0]
return smallest
def get_smallest_y(liste):
try :smallest = liste[0][0]
except IndexError: return
for i in liste:
if i[1] < smallest:
smallest = i[1]
return smallest
def get_biggest(liste):
biggest = liste[0][0]
for i in liste:
for no in range(2):
if i[no] > biggest:
biggest = i[no]
return biggest
def eleminate_useless(liste):
extra = get_smallest(liste)
liste = list(liste)
for i in range(len(liste)):
liste[i] = list(liste[i])
liste[i][0] = liste[i][0] - (extra + 200)
liste[i][1] = liste[i][1] - (extra + 200)
return liste
def balance(liste):
small = get_smallest(liste)
small_x = get_smallest_x(liste)
small_y = get_smallest_y(liste)
big = get_biggest(liste)
rate = 400 / (big - small)
for i in range(len(liste)):
liste[i] = list(liste[i])
liste[i][0] = liste[i][0] + (liste[i][0] - small_x) * rate
liste[i][1] = liste[i][1] + (liste[i][1] - small_y) * rate
return liste
class face():
def __init__(self):
self.file_name = ""
self.basic()
self.show_borders()
self.loop = True
self.my_space = space()
self.drag_rabbit = rabbit()
self.author = "talhaakkas"
t.title("sag tiklayarak bilgi alabilirsiniz - programdan cikmak icin F1 e basin %s" % (self.author))
self.temp =""
self.screen=""
self.selected_camera = ""
self.selected_point = ""
self.khelp = ""
self.focus = 0
t.penup()
t.shape("square")
t.hideturtle()
def main(self):
i = 0
j = 0
while self.loop:
if i > 250: self.clear(); i = 0; self.khelp = ""; self.help = ""
i += 1
self.my_update()
t.ondrag(self.on_drag)
t.onrelease(self.on_release)
t.onscreenclick(self.on_click, btn = 1)
t.onscreenclick(self.on_left_click, btn = 3)
t.onkey(self.exitfrom, "F1")
t.update()
t.listen()
t.title(self.help + " - " + self.khelp + " - " + self.author)
def my_update(self):
self.update_camera_screen()
self.update_screen(self.xy_screen, 0, 1)
self.update_screen(self.xz_screen, 0, 2)
self.update_screen(self.yz_screen, 1, 2)
def clear(self):
for i in self.screen_parts:
i.rabbit.body.clear()
self.my_update()
def update_camera_screen(self):
if not self.selected_camera:
return
try:
self.my_space.screen_list.index(self.selected_camera)
except:
return
liste = self.selected_camera.take_picture()
liste = list(liste)
if self.focus:
for i in range(self.focus):
liste = self.focus_camera(liste)
for i in liste[0]:
if not self.camera_screen.is_in((i[0] + self.camera_screen.get_central_point(0)), (i[1] + self.camera_screen.get_central_point(1))): print i;continue
self.camera_screen.rabbit.jump((i[0] + self.camera_screen.get_central_point(0), i[1] + self.camera_screen.get_central_point(1)))
self.camera_screen.rabbit.arti(5)
for i in liste[1]:
if not ((self.camera_screen.is_in((liste[0][i[0]][0] + self.camera_screen.get_central_point(0)), (liste[0][i[0]][1] + self.camera_screen.get_central_point(1)))) and self.camera_screen.is_in(liste[0][i[1]][0] + self.camera_screen.get_central_point(0), liste[0][i[1]][1] + self.camera_screen.get_central_point(1))): continue
self.camera_screen.rabbit.jump((liste[0][i[0]][0]+ self.camera_screen.get_central_point(0), liste[0][i[0]][1] + self.camera_screen.get_central_point(1)))
self.camera_screen.rabbit.body.setpos(liste[0][i[1]][0]+ self.camera_screen.get_central_point(0), liste[0][i[1]][1] + self.camera_screen.get_central_point(1))
self.camera_screen.rabbit.arti(5)
def focus_camera(self, liste):
liste[0] = eleminate_useless(liste[0])
liste[0] = balance(liste[0])
return liste
def update_screen(self, aream, first_no, second_no):
for i in self.my_space.point_list:
cords = [i.x, i.y, i.z]
aream.rabbit.jump((cords[first_no] + aream.x1, cords[second_no] + aream.y1))
aream.rabbit.arti(5)
for i in self.my_space.point_list:
for j in i.connected:
cords = [i.x, i.y, i.z]
cords2 = [j.x, j.y, j.z]
aream.rabbit.jump((cords[first_no] + aream.x1, cords[second_no] + aream.y1))
aream.rabbit.body.setpos((cords2[first_no] + aream.x1, cords2[second_no] + aream.y1))
for i in self.my_space.screen_list:
cords = [i.x, i.y, i.z]
angles = [degrees(i.xy),degrees(i.xz),degrees(atan(cos(i.xy)/cos(i.xz)))]
deg = 0
if first_no == 0 and second_no == 1:
deg = angles[0]
elif first_no == 0 and second_no == 2:
deg = angles[1]
elif first_no == 1 and second_no == 2:
deg = angles[2]
if i == self.selected_camera:
aream.rabbit.body.pencolor("red")
aream.rabbit.jump((cords[first_no] + aream.x1, cords[second_no] + aream.y1))
aream.rabbit.draw_camera(20,deg)
aream.rabbit.body.setheading(0)
aream.rabbit.body.pencolor("black")
if self.selected_point:
selected_cords = [self.selected_point.x, self.selected_point.y, self.selected_point.z]
aream.rabbit.body.pencolor("red")
aream.rabbit.jump((selected_cords[first_no] + aream.x1, selected_cords[second_no] + aream.y1 - 5))
aream.rabbit.body.setheading(0)
aream.rabbit.body.circle(5)
aream.rabbit.body.pencolor("black")
def basic(self):
t.setup(width = 1250, height = 650, startx = 50, starty = 20)
t.tracer(10)
self.camera_screen = area(-560, -60, 250, -250)
self.xy_screen = area(-10, 290, 310,10)
self.xz_screen = area(-10, 290, -10, -310)
self.yz_screen = area(310, 610, -10, -310)
self.control_panel = area(310, 610, 310, 10)
self.camera_screen.help = "en son secilen kameradan cekilecek goruntuyu gosterir"
self.xy_screen.help = "xy eksenindeki goruntuyu gosterir"
self.xz_screen.help = "xz eksenindeki goruntuyu gosterir"
self.yz_screen.help = "yz eksenindeki goruntuyu"
self.camera_screen.action = self.camera_screen.where_is_this
self.xy_screen.action = self.xy_screen.where_is_this
self.xz_screen.action = self.xz_screen.where_is_this
self.yz_screen.action = self.yz_screen.where_is_this
self.screen_parts = [self.camera_screen, self.xy_screen, self.xz_screen, self.yz_screen, self.control_panel]
self.place_control_panel()
self.help = ""
def show_borders(self):
self.camera_screen.show_borders()
self.xy_screen.show_borders()
self.xz_screen.show_borders()
self.yz_screen.show_borders()
self.control_panel.show_borders()
def place_control_panel(self):
self.control_panel.place_button(10,250)
self.control_panel.button_list[0].set_photo("simgeler\\dosya_islemleri.gif")
self.control_panel.place_button(70,250)
self.control_panel.button_list[1].set_photo("simgeler\\nokta_islemleri.gif")
self.control_panel.place_button(130,250)
self.control_panel.button_list[2].set_photo("simgeler\\kamera_islemleri.gif")
self.control_panel.place_button(190,250)
self.control_panel.button_list[3].set_photo("simgeler\\cizim_islemleri.gif")
self.control_panel.place_button(250,250)
self.control_panel.button_list[4].set_photo("simgeler\\animasyon_islemleri.gif")
self.control_panel.dosya_panel = panel(self.control_panel.x1 - 10 ,
self.control_panel.x1 + 30,
self.control_panel.y1 + 10,
self.control_panel.y1 + 240)
self.control_panel.nokta_panel = panel(self.control_panel.x1 + 50,
self.control_panel.x1 + 90,
self.control_panel.y1 + 10,
self.control_panel.y1 + 240)
self.control_panel.kamera_panel = panel(self.control_panel.x1 + 110,
self.control_panel.x1 + 150,
self.control_panel.y1 + 10,
self.control_panel.y1 + 240)
self.control_panel.cizim_panel = panel(self.control_panel.x1 + 170,
self.control_panel.x1 + 210,
self.control_panel.y1 + 10,
self.control_panel.y1 + 240)
self.control_panel.animasyon_panel = panel(self.control_panel.x1 + 230,
self.control_panel.x1 + 270,
self.control_panel.y1 + 10,
self.control_panel.y1 + 240)
self.control_panel.panel_list = [self.control_panel.dosya_panel,
self.control_panel.nokta_panel,
self.control_panel.kamera_panel,
self.control_panel.cizim_panel,
self.control_panel.cizim_panel,
self.control_panel.animasyon_panel]
self.place_dosya_panel()
self.place_nokta_panel()
self.place_kamera_panel()
self.place_cizim_panel()
def place_dosya_panel(self):
self.control_panel.dosya_panel.place_button(20,200)
self.control_panel.dosya_panel.button_list[0].help = "yeni dosya"
self.control_panel.dosya_panel.button_list[0].action = self.yeni_dosya
self.control_panel.dosya_panel.button_list[0].set_photo("simgeler\\yeni_dosya.gif")
self.control_panel.dosya_panel.place_button(20,160)
self.control_panel.dosya_panel.button_list[1].help = "kayit ac"
self.control_panel.dosya_panel.button_list[1].action = self.kayit_ac
self.control_panel.dosya_panel.button_list[1].set_photo("simgeler\\kayit_ac.gif")
self.control_panel.dosya_panel.place_button(20,120)
self.control_panel.dosya_panel.button_list[2].help = "kaydet"
self.control_panel.dosya_panel.button_list[2].action = self.dosya_kaydet
self.control_panel.dosya_panel.button_list[2].set_photo("simgeler\\kaydet.gif")
self.control_panel.dosya_panel.place_button(20,80)
self.control_panel.dosya_panel.button_list[3].help = "farkli kaydet"
self.control_panel.dosya_panel.button_list[3].action = self.dosya_kaydet
self.control_panel.dosya_panel.button_list[3].set_photo("simgeler\\farkli_kaydet.gif")
def place_nokta_panel(self):
self.control_panel.nokta_panel.place_button(20,200)
self.control_panel.nokta_panel.button_list[0].help = "yeni nokta"
self.control_panel.nokta_panel.button_list[0].action = self.yeni_nokta
self.control_panel.nokta_panel.button_list[0].set_photo("simgeler\\yeni_nokta.gif")
self.control_panel.nokta_panel.place_button(20,160)
self.control_panel.nokta_panel.button_list[1].help = "nokta sec "
self.control_panel.nokta_panel.button_list[1].action = self.nokta_sec
self.control_panel.nokta_panel.button_list[1].set_photo("simgeler\\nokta_sec.gif")
self.control_panel.nokta_panel.place_button(20,120)
self.control_panel.nokta_panel.button_list[2].help = "nokta bagla"
self.control_panel.nokta_panel.button_list[2].action = self.nokta_bagla
self.control_panel.nokta_panel.button_list[2].set_photo("simgeler\\nokta_bagla.gif")
self.control_panel.nokta_panel.place_button(20,80)
self.control_panel.nokta_panel.button_list[3].help = "baglanti kopar"
self.control_panel.nokta_panel.button_list[3].action = self.baglanti_kopar
self.control_panel.nokta_panel.button_list[3].set_photo("simgeler\\baglanti_kopar.gif")
self.control_panel.nokta_panel.place_button(20,40)
self.control_panel.nokta_panel.button_list[4].help = "nokta sil"
self.control_panel.nokta_panel.button_list[4].action = self.nokta_sil
self.control_panel.nokta_panel.button_list[4].set_photo("simgeler\\nokta_sil.gif")
def place_kamera_panel(self):
self.control_panel.kamera_panel.place_button(20,200)
self.control_panel.kamera_panel.button_list[0].help = "yeni kamera"
self.control_panel.kamera_panel.button_list[0].action = self.yeni_kamera
self.control_panel.kamera_panel.button_list[0].set_photo("simgeler\\yeni_kamera.gif")
self.control_panel.kamera_panel.place_button(20,160)
self.control_panel.kamera_panel.button_list[1].help = "kamera sec"
self.control_panel.kamera_panel.button_list[1].action = self.kamera_sec
self.control_panel.kamera_panel.button_list[1].set_photo("simgeler\\kamera_sec.gif")
self.control_panel.kamera_panel.place_button(20,120)
self.control_panel.kamera_panel.button_list[2].help = "kamera ayarla"
self.control_panel.kamera_panel.button_list[2].action = self.kamera_ayarla
self.control_panel.kamera_panel.button_list[2].set_photo("simgeler\\kamera_ayarla.gif")
self.control_panel.kamera_panel.place_button(20,80)
self.control_panel.kamera_panel.button_list[3].help = "kamera sil"
self.control_panel.kamera_panel.button_list[3].action = self.kamera_sil
self.control_panel.kamera_panel.button_list[3].set_photo("simgeler\\kamera_sil.gif")
self.control_panel.kamera_panel.place_button(20,40)
self.control_panel.kamera_panel.button_list[4].help = "odakla"
self.control_panel.kamera_panel.button_list[4].action = self.on_focus
self.control_panel.kamera_panel.button_list[4].set_photo("simgeler\\focus.gif")
def place_cizim_panel(self):
self.control_panel.cizim_panel.place_button(20,200)
self.control_panel.cizim_panel.button_list[0].help = "kutu cizim"
self.control_panel.cizim_panel.button_list[0].action = self.kutu_ciz
self.control_panel.cizim_panel.button_list[0].set_photo("simgeler\\kutu_cizim.gif")
self.control_panel.cizim_panel.place_button(20,160)
self.control_panel.cizim_panel.button_list[1].help = "cizgi cizim"
self.control_panel.cizim_panel.button_list[1].action = self.cizgi_ciz
self.control_panel.cizim_panel.button_list[1].set_photo("simgeler\\cizgi_cizim.gif")
def yeni_dosya(self):
self.my_space = space()
self.selected_camera = ""
self.clear()
def dosya_kaydet(self):
self.help = "lütfen konsola bakin"
if self.file_name:
ad = self.file_name
else:
ad = raw_input("lütfen kayit dosyasi icin bir isim girin")
self.file_name = ad
self.save(ad)
def farkli_kaydet(self):
self.help = "lütfen konsola bakin"
ad = raw_input("lütfen kayit dosyasi icin bir isim girin")
self.file_name = ad
self.save(ad)
def save(self,ad):
dosya = open(ad + ".mtb", "w")
dosya.write("point_list\n")
for i in self.my_space.point_list:
dosya.write("\t%s\t%s\t%s\n" % (i.x, i.y, i.z))
dosya.write("\t%s\n" % (map(lambda x:self.my_space.point_list.index(x), i.connected)))
dosya.write("lines_list\n")
for i in self.my_space.lines_list:
dosya.write("\t%s\t%s\t%s\t%s\t%s\n" % (i.x, i.y, i.z, i.xy, i.xz))
dosya.write("camera_list\n")
for i in self.my_space.screen_list:
dosya.write("\t%s\t%s\t%s\t%s\t%s\n" % (i.x, i.y, i.z, i.xy, i.xz))
dosya.close()
def kayit_ac(self):
self.yeni_dosya()
self.help = "lütfen konsola bakin"
ad = raw_input("lütfen acilacak dosyanin isimini girin")
try :
dosya = open(ad + ".mtb","r")
except:
self.help = "kayit bulunamadi"
return
self.file_name = ad
satirlar = dosya.readlines()
phase = "point_list"
phase_dic = {'point_list':self.new_point,
'lines_list':self.new_line,
'camera_list':self.new_camera, }
connections = []
for i in satirlar:
satir = i.lstrip()
satir = satir.rstrip()
if satir == 'point_list':
phase = satir
continue
elif satir == 'lines_list':
phase = satir
continue
elif satir == 'camera_list':
phase = satir
continue
connections.append(phase_dic[phase](satir))
while True:
try: connections.remove(None)
except:break
for i in range(len(connections)):
for j in range(len(connections[i])):
self.my_space.point_list[i].connect(self.my_space.point_list[int(connections[i][j])])
def new_camera(self, string):
if string == 'point_list' or string == 'lines_list' or string == 'camera_list':
return
temp = string.split()
x = float(temp[0])
y = float(temp[1])
z = float(temp[2])
xy = float(temp[3])
xz = float(temp[4])
temp = point(x, y, z, self.my_space)
temp_line = lines(xy, xz, temp)
screen(100, 100, temp_line)
def new_line(self, string):
if string == 'point_list' or string == 'lines_list' or string == 'camera_list':
return
temp = string.split()
x = float(temp[0])
y = float(temp[1])
z = float(temp[2])
xy = float(temp[3])
xz = float(temp[4])
temp = point(x, y, z, self.my_space)
lines(xy, xz, temp)
def new_point(self, string):
if string == 'point_list' or string == 'lines_list' or string == 'camera_list':
return
if string[0] == "[":
string = string[1:len(string)-1]
liste = string.split(", ")
return liste
else:
temp = string.split()
x = float(temp[0])
y = float(temp[1])
z = float(temp[2])
point(x, y, z, self.my_space)
def kutu_ciz(self):
liste = range(8)
self.yeni_nokta()
first = self.selected_point
liste[0] = (first)
self.yeni_nokta()
second = self.selected_point
liste[6] = (second)
liste[1] = point(second.x, first.y, first.z, self.my_space)
liste[2] = point(second.x, second.y, first.z, self.my_space)
liste[3] = point(first.x, second.y, first.z, self.my_space)
liste[4] = point(first.x, first.y, second.z, self.my_space)
liste[5] = point(second.x, first.y, second.z, self.my_space)
liste[7] = point(first.x, second.y, second.z, self.my_space)
# yazılırsa bağıntı görülecektir print "{0} : {1} {2} {3} {4}".format(i,(3 - i ) % 8, (i + 4) % 8, (i + 1) % 8 ,i - 1)
for i in range(8):
liste[i].connect(liste[(3 - i ) % 8])
liste[i].connect(liste[(i + 4) % 8])
if i % 2:
liste[i].connect(liste[i - 1])
else:
liste[i].connect(liste[(i + 1) % 8])
self.clear()
def on_focus(self):
if self.focus < 5:
self.focus += 1
self.help = "focus %s" % (self.focus)
else:
self.help = "focus off"
self.focus = 0
self.clear()
def cizgi_ciz(self):
self.yeni_nokta()
first = self.selected_point
self.yeni_nokta()
second = self.selected_point
first.connect(second)
self.clear()
def yeni_kamera(self):
x, y, z = self.get_point_cords()
pointx = point(x, y, z, self.my_space)
x1, y1, z1 = self.get_point_cords()
line = lines(pointx.get_angle(x1, y = y1), pointx.get_angle(x1,z = z1), pointx)
self.selected_camera = screen(100,100,line)
self.help = "{0}, {1}, {2} kordinatlarinda {3} {4} acılarında".format(x,y,z, degrees(line.xy), degrees(line.xz) )
self.clear()
def kamera_sec(self):
falior = True
x, y, z = self.get_point_cords()
for i in self.my_space.screen_list:
if distance(i, (x, y, z)) < 25:
self.selected_camera = i
falior = False
self.clear()
break
if falior:
self.help = "bir nokta secilemedi lutfen tekrar deneyin".format(x,y,z)
return
def kamera_sil(self):
the_camera = self.selected_camera
if type(the_camera) == str:
return
while True:
try:
self.my_space.screen_list.remove(the_camera)
except ValueError:
break
self.selected_point = ""
self.clear()
def kamera_ayarla(self):
the_camera = self.selected_camera
self.kamera_sil()
x, y, z = the_camera.x, the_camera.y, the_camera.z
pointx = point(x, y, z, self.my_space)
x1, y1, z1 = self.get_point_cords()
line = lines(pointx.get_angle(x1, y = y1), pointx.get_angle(x1,z = z1), pointx)
self.selected_camera = screen(100,100,line)
self.help = "{0}, {1}, {2} kordinatlarinda {3} {4} acılarında".format(x,y,z, degrees(line.xy), degrees(line.xz) )
self.clear()
def yeni_nokta(self):
x, y, z = self.get_point_cords()
self.selected_point = point(x, y, z, self.my_space)
self.clear()
self.temp = ""
self.help = "{0}, {1}, {2} kordinatlarinda bir nokta olusturuldu".format(x,y,z)
def nokta_sec(self):
falior = True
x, y, z = self.get_point_cords()
for i in self.my_space.point_list:
if distance(i, (x, y, z))< 5:
self.selected_point = i
self.help = "{0}, {1}, {2} kordinatlarindaki nokta secildi".format(x,y,z)
falior = False
self.clear()
break
if falior:
self.help = "bir nokta secilemedi lutfen tekrar deneyin".format(x,y,z)
return
def nokta_bagla(self):
first_point = self.selected_point
self.nokta_sec()
second_point = self.selected_point
if second_point != first_point and type(second_point) != str and type(first_point) != str:
first_point.connect(second_point)
self.clear()
def baglanti_kopar(self):
first_point = self.selected_point
self.nokta_sec()
second_point = self.selected_point
self.cut_connections(first_point, second_point)
def cut_connections(self, first_point, second_point):
if second_point == first_point:
return
while True:
try:
first_point.connected.remove(second_point)
except ValueError:
break
while True:
try:
second_point.connected.remove(first_point)
except ValueError:
break
self.clear()
def nokta_sil(self):
the_point = self.selected_point
if type(the_point) == str:
return
while the_point.connected:
self.cut_connections(the_point, the_point.connected[len(the_point.connected) - 1])
while True:
try:
self.my_space.point_list.remove(the_point)
except ValueError:
break
self.selected_point = ""
self.clear()
def on_drag(self, x, y):
print x,y
for i in self.screen_parts:
if i.is_in(x, y):
i.clicked((x - i.x1), (y - y1))
def exitfrom(self):
self.loop = False
def on_release(self,x,y):
self.clear()
def on_click(self,x,y):
t.setpos(x+2,y+2)
for i in self.screen_parts:
if i.is_in(x, y) and (i != self.control_panel):
self.temp = (i.clicked(x, y), self.screen_parts.index(i))
elif i.is_in(x, y) and (i == self.control_panel):
for j in self.control_panel.panel_list:
for k in j.button_list:
if k.is_in(x,y):
k.clicked()
t.title(self.help + " - " + self.khelp + " - " + self.author)
def on_left_click(self, x, y):
for i in self.screen_parts:
if i.is_in(x, y) and (i != self.control_panel):
self.khelp = i.help
elif i.is_in(x, y) and (i == self.control_panel):
for j in self.control_panel.panel_list:
for k in j.button_list:
if k.is_in(x,y):
self.khelp = k.help
t.title(self.help + " - " + self.khelp + " - " + self.author)
def get_point_cords(self):
x = ""
y = ""
z = ""
i = 0
while type(x) == str or type(y) == str or type(z) == str:
if i > 500 : return
t.ondrag(self.on_drag)
t.onrelease(self.on_release)
t.onscreenclick(self.on_click, btn = 1)
t.onscreenclick(self.on_left_click, btn = 3)
t.onkey(self.exitfrom, "F1")
t.update()
t.listen()
#self.screen_parts = [self.camera_screen, self.xy_screen, self.xz_screen, self.yz_screen, self.control_panel]
if self.temp:
if self.temp[1] == 1:
x = self.temp[0][0]
y = self.temp[0][1]
elif self.temp[1] == 2:
x = self.temp[0][0]
z = self.temp[0][1]
elif self.temp[1] == 3:
y = self.temp[0][0]
z = self.temp[0][1]
self.temp = ""
self.clear()
return x, y, z
a=face()
a.main()
import turtle
t = turtle
def get_bigger(x):
if x[0] > x[1]:
return 0
return 1
class rabbit():
def __init__(self):
self.body = turtle.clone()
self.body.ht()
def dash(self, x, y):
# kucuk sapmalar iceriyor
pos = [self.body.xcor(), self.body.ycor()]
road = [x - pos[0], y - pos[1]]
dr = [(abs(road[0]) + 0.0001)/(road[0] + 0.0001), (abs(road[1]) + 0.0001)/(road[1] + 0.0001)]
bigger = get_bigger((abs(road[0]),abs(road[1])))
for i in range(abs(int((road[bigger] / 10) - 1))):
pos = [self.body.xcor(), self.body.ycor()]
if bigger:
self.body.setpos(pos[0] + ((5 * (abs(road[0]) / abs(road[1]))) * dr[0]),
pos[1] + (5 * dr[1]))
self.jump((pos[0] + ((10 * (abs(road[0]) / abs(road[1]))) * dr[0]),
pos[1] + (10 * dr[1])))
else:
self.body.setpos(pos[0] + (5 * dr[0]),
pos[1] + ((5 * (abs(road[1]) / abs(road[0]))) * dr[1]))
self.jump((pos[0] + (10 * dr[0]),
pos[1] + ((10 * (abs(road[1]) / abs(road[0]))) * dr[1])))
if bigger:
self.body.setpos(pos[0] + (road[0] % (abs(road[0]*2) / abs(road[1]))) * dr[0],
pos[1] + (road[1] % 10) * dr[1])
else:
self.body.setpos(pos[0] + (road[0] % 10) *dr[0],
pos[1] + (road[1] % (abs(road[1] * 2) / abs(road[0]))) * dr[1])
def undo(last_move):
move_dic = {"jump":3, "arti":7, "draw_camera":12,}
self.body.undo(move_dic[last_move])
def jump(self,i):
self.body.penup()
self.body.setpos(i)
self.body.pendown()
def arti(self,x):
self.body.forward(x)
self.body.backward(x*2)
self.body.forward(x)
self.body.left(90)
self.body.forward(x)
self.body.backward(x*2)
self.body.forward(x)
def draw_camera(self, x, head):
self.body.setheading(head)
self.body.penup()
self.body.backward(x)
self.body.left(45)
self.body.pd()
self.body.forward(x)
self.body.backward(x)
self.body.right(90)
self.body.forward(x)
self.body.backward(x/2)
self.body.left(135)
self.body.forward(x)
def goto(tupl):
points = tupl[0]
connects = tupl[1]
for i in points:
self.jump(i)
self.arti()
class area():
def __init__(self,x1,x2,y1,y2):
if x1 > x2:
x1,x2 = x2,x1
if y1 > y2:
y1,y2 = y2,y1
self.x1 = x1
self.x2 = x2
self.y1 = y1
self.y2 = y2
self.rabbit = rabbit()
self.button_list = []
self.action = ""
def is_in(self,x,y):
return ((self.x1 < x < self.x2) and (self.y1 < y < self.y2))
def where_is_this(self, x, y):
return ((x - self.x1) , (y - self.y1))
def clicked(self, *args):
return self.action(*args)
def get_central_point(self,x):
if x:
return (self.y1 + self.y2)/2
return (self.x1 + self.x2)/2
def show_borders(self):
self.rabbit.jump((self.x1,self.y1))
self.rabbit.body.setpos(self.x1,self.y2)
self.rabbit.body.setpos(self.x2,self.y2)
self.rabbit.body.setpos(self.x2,self.y1)
self.rabbit.body.setpos(self.x1,self.y1)
def place_button(self, x, y, height = 40 , widht = 40):
self.button_list.append(button(x+self.x1, y+self.y1, height, widht))
class button(area):
def __init__(self, x, y, height, widht):
self.x1 = x
self.y1 = y
self.x2 = x + widht
self.y2 = y + height
self.rabbit = rabbit()
self.rabbit.jump(((self.x1+self.x2)/2,(self.y1+self.y2)/2))
self.rabbit.body.showturtle()
def set_photo(self, adres):
turtle.register_shape(adres)
self.rabbit.body.shape(adres)
class panel(area):
def __init__(self, x1, x2, y1, y2):
if x1 > x2:
x1,x2 = x2,x1
if y1 > y2:
y1,y2 = y2,y1
self.x1 = x1
self.x2 = x2
self.y1 = y1
self.y2 = y2
self.button_list = []
self.is_visible = True
self.show_panel()
self.rabbit = rabbit()
def show_panel(self):
self.is_visible = True
for i in self.button_list:
i.rabbit.body.showturtle()
def hide_panel(self):
self.is_visible = False
for i in self.button_list:
i.rabbit.body.hideturtle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment