Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
python_lechner [2011/06/24 13:07] thomas.lechner [gummi-ente] |
python_lechner [2011/06/25 22:20] (aktuell) thomas.lechner [gummi-ente] |
||
---|---|---|---|
Zeile 284: | Zeile 284: | ||
fd(length) | fd(length) | ||
rt(90) | rt(90) | ||
- | end_fill() | + | end_fill() |
circle(radius,120) | circle(radius,120) | ||
| | ||
Zeile 461: | Zeile 461: | ||
exitonclick() | exitonclick() | ||
+ | </code> | ||
+ | |||
+ | <code python rec-logo.py> | ||
+ | from turtle import * | ||
+ | from math import * | ||
+ | |||
+ | r=100 | ||
+ | w=20 | ||
+ | l=200 | ||
+ | |||
+ | def part(): | ||
+ | for i in range(2): | ||
+ | fd(w) | ||
+ | rt(45) | ||
+ | fd(l) | ||
+ | rt(90+45) | ||
+ | |||
+ | def sign(): | ||
+ | color("orange") | ||
+ | begin_fill() | ||
+ | circle(r) | ||
+ | end_fill() | ||
+ | pu() | ||
+ | goto(-2.5*w,r) | ||
+ | pd() | ||
+ | for i in range(3): | ||
+ | pd() | ||
+ | color("white") | ||
+ | begin_fill() | ||
+ | part() | ||
+ | end_fill() | ||
+ | pu() | ||
+ | fd(w*2) | ||
+ | pu() | ||
+ | goto(r,r) | ||
+ | seth(-90) | ||
+ | circle(-r,-270) | ||
+ | |||
+ | def kreis(name): | ||
+ | reset() | ||
+ | begin_poly() | ||
+ | sign() | ||
+ | end_poly() | ||
+ | kreis_form = get_poly() | ||
+ | screen.register_shape(name, kreis_form) | ||
+ | |||
+ | tracer(0) | ||
+ | screen = Screen() | ||
+ | kreis("kreis") | ||
+ | kreis1 = Turtle(shape="kreis") | ||
+ | kreis1.lt(90) | ||
+ | kreis1.color("orange") | ||
+ | kreis1.stamp() | ||
+ | kreis1.clear() | ||
+ | |||
+ | color("orange") | ||
+ | pensize(w) | ||
+ | pd();circle(-r) | ||
+ | tracer(1) | ||
+ | |||
+ | exitonclick() | ||
+ | </code> | ||
+ | |||
+ | ===== autos ===== | ||
+ | |||
+ | [[http://sbox.bgweiz.at/thomas.lechner/10-11/matura/car_1.gif|car_1.gif]] | ||
+ | [[http://sbox.bgweiz.at/thomas.lechner/10-11/matura/car_2.gif|car_2.gif]] | ||
+ | |||
+ | <code python autos.py> | ||
+ | # -*- coding: utf-8 -*- | ||
+ | # Autor: Thomas Lechner | ||
+ | |||
+ | |||
+ | from turtle import * | ||
+ | from datetime import datetime | ||
+ | |||
+ | screen = Screen() | ||
+ | screen.setup(800, 400) | ||
+ | screen.clear() | ||
+ | screen.register_shape("car_1.gif") | ||
+ | |||
+ | global cars, traffic | ||
+ | cars = [] | ||
+ | traffic = True | ||
+ | |||
+ | def street(length, width): | ||
+ | global t | ||
+ | tracer(False) | ||
+ | a=8 | ||
+ | s = Turtle() | ||
+ | s.ht() | ||
+ | s.pensize(8) | ||
+ | s.pu();s.goto(-length/2,-width/2);s.pd() | ||
+ | s.fd(length) | ||
+ | s.pu();s.goto(s.xcor(),s.ycor()+width/2);s.pd() | ||
+ | for i in range(a): | ||
+ | s.bk(length/(2*a)-4) | ||
+ | s.pu() | ||
+ | s.bk(length/(2*a)+4) | ||
+ | s.pd() | ||
+ | s.pu();s.goto(s.xcor(),s.ycor()+width/2);s.pd() | ||
+ | s.fd(length) | ||
+ | t = Turtle(shape="circle") | ||
+ | t.pu() | ||
+ | t.goto(-250,120) | ||
+ | tracer(True) | ||
+ | |||
+ | def car_start(): | ||
+ | tracer(False) | ||
+ | car_start = Turtle(shape="car_1.gif") | ||
+ | car_start.pu() | ||
+ | car_start.goto(500,50) | ||
+ | tracer(True) | ||
+ | return car_start | ||
+ | |||
+ | def car(x,y): | ||
+ | c = car_start().clone() | ||
+ | cars.append(c) | ||
+ | print(cars) | ||
+ | | ||
+ | def space_check(car): | ||
+ | global space | ||
+ | dis = [] | ||
+ | a = 0 | ||
+ | for i in cars: | ||
+ | if car != i and car.xcor() > i.xcor(): | ||
+ | dis.append(car.distance(i.xcor(),i.ycor())) | ||
+ | print(dis) | ||
+ | | ||
+ | for i in dis: | ||
+ | if i < 200: | ||
+ | a = a+1 | ||
+ | if a != 0: | ||
+ | space=False | ||
+ | print(space) | ||
+ | else: | ||
+ | space=True | ||
+ | return space | ||
+ | |||
+ | def trafficlight(x,y): | ||
+ | global traffic | ||
+ | if traffic != True: | ||
+ | traffic=True | ||
+ | t.color("green") | ||
+ | else: | ||
+ | traffic=False | ||
+ | t.color("red") | ||
+ | | ||
+ | def move(i): | ||
+ | space_check(i) | ||
+ | print(space) | ||
+ | if cars.index(i) == 0: | ||
+ | i.bk(2) | ||
+ | elif space == True: | ||
+ | i.bk(2) | ||
+ | |||
+ | def tick(): | ||
+ | screen.tracer(False) | ||
+ | for i in cars: | ||
+ | if traffic == True: | ||
+ | move(i) | ||
+ | elif i.xcor() < -200 or i.xcor() > -180: | ||
+ | move(i) | ||
+ | | ||
+ | if i.xcor() < -500: | ||
+ | i.ht() | ||
+ | cars.remove(i) | ||
+ | |||
+ | screen.tracer(True) | ||
+ | screen.ontimer(tick, 2) | ||
+ | |||
+ | street(800,200) | ||
+ | if __name__ == "__main__": | ||
+ | listen() | ||
+ | onscreenclick(car, 1) | ||
+ | onscreenclick(trafficlight,3) | ||
+ | tick() | ||
+ | mainloop() | ||
</code> | </code> |