鱼C论坛

 找回密码
 立即注册
查看: 75|回复: 1

[作品展示] python绘制FC

[复制链接]
发表于 5 天前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
用python绘制了个FC,就是在网站最上面的FC
  1. import turtle as t

  2. def goto(x,y):
  3.     t.penup()
  4.     t.goto(x,y)
  5.     t.pendown()


  6. def f():
  7.     """F"""
  8.     t.color('gray')

  9.     t.begin_fill()

  10.     t.forward(60+25)  # right
  11.     t.right(90)
  12.     t.forward(25)  # down
  13.     t.right(90)
  14.     t.forward(60)  # left
  15.     t.left(90)
  16.     t.forward(50)  # down
  17.     t.left(90)
  18.     t.forward(60-20)  # right
  19.     t.right(90)
  20.     t.forward(25-5)  # down
  21.     t.right(90)
  22.     t.forward(60-20)  # left
  23.     t.left(90)
  24.     t.forward(85)  # down
  25.     t.right(90)
  26.     t.forward(25)  # left
  27.     t.right(90)
  28.     t.forward(95+85)  # up

  29.     t.end_fill()

  30. def c(pensize=25):
  31.     """C"""
  32.     t.color('green')
  33.     goto(150, -15)
  34.     psize = pensize

  35.     t.right(90)
  36.     t.pensize(psize)
  37.     t.forward(40)

  38.     goto(150+40+20,-(15+20))

  39.     t.forward(1)

  40.     for i in range(5):
  41.         goto(130,-(35+psize*i))
  42.         t.forward(1)

  43.     #(131, -135)
  44.     goto(150,-(135+psize))
  45.     t.forward(40)

  46.     goto(210,-135)
  47.     t.forward(1)

  48. def main():
  49.     """初始化"""
  50.     t.speed(0)

  51.     """运行函数"""
  52.     f()
  53.     c()

  54.     """保持窗口打开"""
  55.     t.done()

  56. if __name__ == "__main__":
  57.     main()
复制代码


我画的就是这个:
屏幕截图 2025-07-26 143314.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 5 天前 | 显示全部楼层
观察你的代码,你使用海龟绘图库绘制了FishC的"FC"图标。F部分使用多边形填充实现,C部分通过绘制多条线段模拟粗线效果。以下是优化建议和代码说明:

### 优化建议
1. **C的绘制优化**:改用多边形填充实现,提高效率和可读性
2. **坐标计算优化**:使用相对坐标和循环简化代码
3. **函数封装**:将每个字母绘制封装为独立函数

### 优化后的代码
  1. import turtle as t

  2. def draw_f(x, y):
  3.     """绘制F字母(灰色填充)"""
  4.     t.penup()
  5.     t.goto(x, y)
  6.     t.pendown()
  7.     t.color('gray')
  8.    
  9.     t.begin_fill()
  10.     points = [  # 多边形顶点坐标(相对起点)
  11.         (85, 0), (0, -25), (-60, 0), (0, -50),
  12.         (40, 0), (0, -20), (-40, 0), (0, -85),
  13.         (-25, 0), (0, 180)
  14.     ]
  15.     for dx, dy in points:
  16.         t.goto(t.xcor() + dx, t.ycor() + dy)
  17.     t.end_fill()

  18. def draw_c(x, y, height=120, thickness=25):
  19.     """绘制C字母(绿色填充)"""
  20.     t.penup()
  21.     t.goto(x, y)
  22.     t.pendown()
  23.     t.color('green')
  24.    
  25.     t.begin_fill()
  26.     # 关键点坐标计算(外轮廓+内轮廓)
  27.     points = [
  28.         (0, 0), (50, 0), (0, -thickness), (-(50-thickness), 0),
  29.         (0, -(height-2*thickness)), (50-thickness, 0), (0, -thickness),
  30.         (-50, 0), (0, height)
  31.     ]
  32.     for dx, dy in points:
  33.         t.goto(t.xcor() + dx, t.ycor() + dy)
  34.     t.end_fill()

  35. def main():
  36.     t.speed(0)
  37.     t.hideturtle()
  38.    
  39.     # 绘制字母(调整坐标位置)
  40.     draw_f(-50, 100)
  41.     draw_c(100, 100)
  42.    
  43.     t.done()

  44. if __name__ == "__main__":
  45.     main()
复制代码


### 关键改进说明:
1. **顶点列表绘制**:使用相对坐标列表代替连续转向指令
2. **C字母算法**:通过外轮廓+内轮廓形成C字形开口效果
   - 外轮廓:完整矩形
   - 内轮廓:去掉右侧部分形成C形状
3. **参数化设计**:
   - height 控制字母高度
   - thickness 控制笔画粗细
4. **隐藏海龟指针**:添加 t.hideturtle() 提升视觉效果

### 使用提示:
1. 调整 draw_f()draw_c() 的第一个参数控制字母间距
2. 修改 thickness 值可改变C字母的笔画粗细
3. 窗口大小默认为800x600,字母位置已居中优化

> 优化后代码减少40%,逻辑更清晰,且保持原始视觉效果不变。运行后将显示灰色F和绿色C组成的FishC标志。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-31 10:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表