2024.9.29
玩了好几天游戏。
感觉有点灵感了。还想继续玩游戏。
2024.10.4
今天练习阿斯汤加练完从早上10点睡到下午2点.跑到单位玩游戏玩到晚上10点多.
现在回家突然有了灵感
顺便说一句,因为后弯不好,明天加练一次.
然后去丈母娘家.
加油吧
第一章、追求可以外调的函数draw_rec2
- 我在self的基础上如何让它的变量能够被外部调用.
- 在这个代码前self 后面加了一个other_rec利用他来作为输入的入口.也是为了扣题上所说的.
- 但实际的问题却很头疼.
- 1 statement expected,found py:dedemt
- 2 Method 'draw_rec2' may be 'static'
- 不管了实际试一下看看如何
- 只绘制rec1成功
- 奇怪的计算
- 出错的提示![请添加图片描述](https://i-blog.****img.cn/direct/1015ea02ea2840298b124b0d4ff356c1.png)
- 似乎发现点什么??
- TypeError: unsupported operand type(s) for -: 'method' and 'float'
- 成功了原来直接调用可以不用out
- 原来直接调用就可以不用额外做一个,来玩改一下之前Rectangle2D的类
- 可能有些啰嗦,但是大家看到了.对比第一章我是不是去掉了out_x之类的.原来我是可以直接通过私有函数将x,y,widht,height.调用的呀.
- 结果
- 水平问题rec2的位置没有设计好.下集再弄,明早上7点30瑜伽后弯,天呐.
我在self的基础上如何让它的变量能够被外部调用.
def draw_rec2(self, other_rec):
x = other_rec.out_x
y = other_rec.out_y
width_r = other_rec.out_width
height_r = other_rec.out_height
turtle.penup()
turtle.goto(x, y)
turtle.dot(6, "yellow")
turtle.goto(width_r/ 2 + x, height_r/2 + y)
turtle.pendown()
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.right(90)
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.hideturtle()
turtle.done()
在这个代码前self 后面加了一个other_rec利用他来作为输入的入口.也是为了扣题上所说的.
但实际的问题却很头疼.
1 statement expected,found py:dedemt
2 Method ‘draw_rec2’ may be ‘static’
不管了实际试一下看看如何
class Rectangle2D:
def __init__(self, x, y, width, height):
self.__x = x
self.__y = y
self.__width = width
self.__height = height
def get_area(self):
return self.__width * self.__height
def get_perimeter(self):
return (self.__width + self.__height) * 2
def out_x(self):
return self.__x
def out_y(self):
return self.__y
def out_width(self):
return self.__width
def out_height(self):
return self.__height
# 他内带绘画矩形,直接调用的self
def draw_rec1(self):
turtle.penup()
turtle.goto(self.__x, self.__y)
turtle.dot(6, "blue")
turtle.goto(self.__x-self.__width / 2 , self.__height / 2 + self.__y)
turtle.pendown()
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.right(90)
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.hideturtle()
turtle.done()
#此处是调用外部的矩形并且绘画
def draw_rec2(self, other_rec):
x = other_rec.out_x
y = other_rec.out_y
width_r = other_rec.out_width
height_r = other_rec.out_height
turtle.penup()
turtle.goto(x, y)
turtle.dot(6, "yellow")
turtle.goto(x - width_r / 2, height_r / 2 + y)
turtle.pendown()
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.right(90)
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.hideturtle()
turtle.done()
a = Rectangle2D(100, 0, 50, 60)
def main():
#调用它成功
a.draw_rec1()
main()
只绘制rec1成功
第二章、各种问题的展示
- 我在self的基础上如何让它的变量能够被外部调用.
- 在这个代码前self 后面加了一个other_rec利用他来作为输入的入口.也是为了扣题上所说的.
- 但实际的问题却很头疼.
- 1 statement expected,found py:dedemt
- 2 Method 'draw_rec2' may be 'static'
- 不管了实际试一下看看如何
- 只绘制rec1成功
- 奇怪的计算
- 出错的提示![请添加图片描述](https://i-blog.****img.cn/direct/1015ea02ea2840298b124b0d4ff356c1.png)
- 似乎发现点什么??
- TypeError: unsupported operand type(s) for -: 'method' and 'float'
- 成功了原来直接调用可以不用out
- 原来直接调用就可以不用额外做一个,来玩改一下之前Rectangle2D的类
- 可能有些啰嗦,但是大家看到了.对比第一章我是不是去掉了out_x之类的.原来我是可以直接通过私有函数将x,y,widht,height.调用的呀.
- 结果
- 水平问题rec2的位置没有设计好.下集再弄,明早上7点30瑜伽后弯,天呐.
奇怪的计算
篇幅关系仅仅展示增加修改的地方.其他和上面的代码一样.
a = Rectangle2D(100, 0, 50, 60)
b = Rectangle2D(60, 0, 80, 30)
def main():
a.draw_rec1()
a.draw_rec2(b)
main()
出错的提示
似乎发现点什么??
我把draw_rec1的属于self的代码加入到了draw_rec2里刚才所谓的static提示消失了.静态变动态了!!
TypeError: unsupported operand type(s) for -: ‘method’ and ‘float’
成功了原来直接调用可以不用out
def draw_rec2(self, other_rec):
x_1 = other_rec.__x
y_1 = other_rec.__y
width_r = other_rec.__width
height_r = other_rec.__height
turtle.penup()
turtle.goto(self.__x, self.__y)
turtle.dot(6, "blue")
turtle.goto(self.__x - self.__width / 2, self.__height / 2 + self.__y)
turtle.pendown()
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.right(90)
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
原来直接调用就可以不用额外做一个,来玩改一下之前Rectangle2D的类
class Rectangle2D:
def __init__(self, x, y, width, height):
self.__x = x
self.__y = y
self.__width = width
self.__height = height
def get_area(self):
return self.__width * self.__height
def get_perimeter(self):
return (self.__width + self.__height) * 2
def draw_rec1(self):
turtle.penup()
turtle.goto(self.__x, self.__y)
turtle.dot(6, "blue")
turtle.goto(self.__x-self.__width / 2 , self.__height / 2 + self.__y)
turtle.pendown()
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.right(90)
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.hideturtle()
turtle.done()
def draw_rec2(self, other_rec):
x_1 = other_rec.__x
y_1 = other_rec.__y
width_r = other_rec.__width
height_r = other_rec.__height
turtle.penup()
turtle.goto(self.__x, self.__y)
turtle.dot(6, "blue")
turtle.goto(self.__x - self.__width / 2, self.__height / 2 + self.__y)
turtle.pendown()
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.right(90)
turtle.forward(self.__width)
turtle.right(90)
turtle.forward(self.__height)
turtle.penup()
turtle.goto(x_1, y_1)
turtle.dot(6, "yellow")
turtle.goto(x_1 - width_r / 2, height_r / 2 + y_1)
turtle.pendown()
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.right(90)
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.hideturtle()
turtle.done()