Last active
September 2, 2022 19:38
-
-
Save horvatha/1eb6a5ea811bdbc81a0744cea77551dd to your computer and use it in GitHub Desktop.
Egy egyenlő oldalú háromszöget nagyít. Az egyik oldalfelező van mindig középen, és két csúcs az egyik átló mentén helyezkedik el. Egy olyan koordinátarendszert használok, ahol a közepe az origó, a tengelyek -1-től egyig mennek. A háromszög csúcsa 1-szeres nagyítás esetén: [(1, 1), (-1, -1), (-sqrt(3), sqrt(3))]. A nagyítást 0.01 és 1.21 között v…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
from microbit import * | |
s3 = sqrt(3) | |
pattern0 = [(1, 1), (-1, -1), (-s3, s3)] | |
def magnify_by(n): | |
def transf(x, y): | |
return n * x, n * y | |
return transf | |
def transform_to_m1_1(x, y): | |
"""az origót középre rakja, és elrendezi, hogy a tengelyek -1 és 1 közé essenek""" | |
unit = 2 | |
return unit * x + unit, unit * y + unit | |
def dist(p1, p2): | |
x1, y1 = p1 | |
x2, y2 = p2 | |
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 | |
def plot_points(*points): | |
image = [] | |
for x in range(0, 5): | |
for y in range(0, 5): | |
p0 = (x, y) | |
distances = [dist(p, p0) for p in points] | |
dst = min(distances) | |
brightness = int(max(0, 1 - dst**2) * 9) | |
image.append(str(brightness)) | |
image.append(":") | |
image = image[:-1] | |
image_sting = "".join(image) | |
return Image(image_sting) | |
def plot_moving_pattern(pattern0, sleep_time): | |
for i in range(121): | |
pattern = [magnify_by(i / 100)(x, y) for x, y in pattern0] | |
pattern = [transform_to_m1_1(x, y) for x, y in pattern] | |
display.show(plot_points(*pattern)) | |
sleep(sleep_time) | |
while True: | |
plot_moving_pattern(pattern0, sleep_time=5) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Az egyik oldalfelező van mindig középen, és két csúcs az egyik átló mentén helyezkedik el. Egy olyan koordinátarendszert használok, ahol a közepe az origó, a tengelyek -1-től egyig mennek. A háromszög csúcsa 1-szeres nagyítás esetén: [(1, 1), (-1, -1), (-sqrt(3), sqrt(3))]. A nagyítást 0.01 és 1.21 között változtatom. A tengelyek irányának kitalálását mindenkire rábízom.