主頁 > 後端開發 > turtle畫哆啦A夢(不止一個哦 多個有趣的畫)

turtle畫哆啦A夢(不止一個哦 多個有趣的畫)

2021-02-06 12:01:51 後端開發

有趣的turtle庫

      • 前言
      • 彩色螺旋線
        • 效果
      • 太陽花
        • 效果
      • 國旗
        • 效果
      • 玫瑰花
        • 效果
      • 彩色樹
        • 效果
      • 隨機櫻花樹
        • 效果
      • 圓舞曲
        • 效果
      • 哆啦A夢
        • 效果
      • 時鐘
        • 效果

前言

聽說有人找畫哆啦A夢的原始碼,分享python turtle庫 幾個有趣的原始碼



彩色螺旋線

from turtle import *
speed(9)            # 畫筆速度
pensize(2)			# 畫筆的寬度
bgcolor("black")		# 畫布背景色
colors = ["red","yellow","purple","blue"]	# 定義畫筆線色
for x in range(400):		# 回圈一次 畫一條線 
    forward(2*x) 	        # 向當前方向前進n像素
    color(colors[x % 4])	# 根據求余 調整畫筆線色
    left(91)                # 向左旋轉91度

mainloop()

效果



太陽花

import turtle
turtle=turtle.Turtle()
screen=turtle.getscreen()
turtle.color('red', 'yellow')
turtle.begin_fill()
for i in range(50):
    turtle.forward(200)
    turtle.left(170)
turtle.end_fill()
turtle.done()

效果

在這里插入圖片描述


國旗

from turtle import *

screensize(2000, 2000, 'white')  # 設定畫布大小
speed(9)
# 繪制旗面
pencolor('red')
# pu()
goto(-300, -200)
pd()
fillcolor('red')
begin_fill()
for i in range(0, 2):
    fd(600)
    lt(90)
    fd(400)
    lt(90)
end_fill()

# 繪制大五角星
pu()
pencolor('yellow')
goto(-260, 120)
pd()
fillcolor('yellow')
begin_fill()
for i in range(0, 5):
    fd(113.137)  # 大星一劃的邊長
    rt(144)
end_fill()

# 繪制四個小五角星
list1 = [(-100, 160), (-60, 120), (-60, 60), (-100, 20)]  # 四個五角星的中心坐標
list2 = [31.98, 8.13, -15.59, -38.66]  # 相對角度0的后退1.111需要左轉的角度

for j in range(0, 4):
    seth(0)  # 這是龜頭角度為0
    pu()
    goto(list1[j])  # 定位到五角星中心
    lt(list2[j])  # 旋轉角度,以背向指向大五角星的角尖
    bk(20)  # 從五角星中心到指向大五角星的角尖(龜倒著爬)退一個小圓半徑
    lt(18)  # 五角星的半角角度
    pd()
    begin_fill()
    for i in range(0, 5):
        fd(113.137 / 3)  # 小星一劃的邊長
        rt(144)
    end_fill()
pu()
ht()
done()

效果



玫瑰花

import turtle
import time
turtle.speed(5)
# 設定初始位置  
turtle.penup()  
turtle.left(90)  
turtle.fd(200)  
turtle.pendown()  
turtle.right(90)
# 花蕊 
turtle.fillcolor("red")  
turtle.begin_fill()  
turtle.circle(10,180)  
turtle.circle(25,110)  
turtle.left(50)  
turtle.circle(60,45)  
turtle.circle(20,170)  
turtle.right(24)  
turtle.fd(30)  
turtle.left(10)  
turtle.circle(30,110)  
turtle.fd(20)  
turtle.left(40)  
turtle.circle(90,70)  
turtle.circle(30,150)  
turtle.right(30)  
turtle.fd(15)  
turtle.circle(80,90)  
turtle.left(15)  
turtle.fd(45)  
turtle.right(165)  
turtle.fd(20)  
turtle.left(155)  
turtle.circle(150,80)  
turtle.left(50)  
turtle.circle(150,90)  
turtle.end_fill()  

# 花瓣1  
turtle.left(150)  
turtle.circle(-90,70)  
turtle.left(20)  
turtle.circle(75,105)  
turtle.setheading(60)  
turtle.circle(80,98)  
turtle.circle(-90,40)  

# 花瓣2  
turtle.left(180)  
turtle.circle(90,40)  
turtle.circle(-80,98)  
turtle.setheading(-83)  

# 葉子1  
turtle.fd(30)  
turtle.left(90)  
turtle.fd(25)  
turtle.left(45)  
turtle.fillcolor("green")  
turtle.begin_fill()  
turtle.circle(-80,90)  
turtle.right(90)  
turtle.circle(-80,90)  
turtle.end_fill()  
turtle.right(135)  
turtle.fd(60)  
turtle.left(180)  
turtle.fd(85)  
turtle.left(90)  
turtle.fd(80)  

# 葉子2  
turtle.right(90)  
turtle.right(45)  
turtle.fillcolor("green")  
turtle.begin_fill()  
turtle.circle(80,90)  
turtle.left(90)  
turtle.circle(80,90)  
turtle.end_fill()  
turtle.left(135)  
turtle.fd(60)  
turtle.left(180)  
turtle.fd(60)  
turtle.right(90)  
turtle.circle(200,60) 
turtle.done()

效果



彩色樹

# 這個比較復雜,畫的時間較長

from turtle import *
# 設定色彩模式是RGB:
colormode(255)
lt(90)
lv = 14
l = 120
s = 45
width(lv)
# 初始化RGB顏色:
r = 0
g = 0
b = 0
pencolor(r, g, b)
penup()
bk(l)
pendown()
fd(l)
def draw_tree(l, level):
    global r, g, b
    # save the current pen width
    w = width()
    # narrow the pen width
    width(w * 3.0 / 4.0)
    # set color:
    r = r + 1
    g = g + 2
    b = b + 3
    pencolor(r % 200, g % 200, b % 200)
    l = 3.0 / 4.0 * l
    lt(s)
    fd(l)
    if level < lv:
        draw_tree(l, level + 1)
    bk(l)
    rt(2 * s)
    fd(l)
    if level < lv:
        draw_tree(l, level + 1)
    bk(l)
    lt(s)
    # restore the previous pen width
    width(w)
speed("fastest")
draw_tree(l, 4)
done()

效果

在這里插入圖片描述



隨機櫻花樹

# 每次運行 樹的形狀是隨機的
import turtle as T
import random
import time

# 畫櫻花的軀干(60,t)
def Tree(branch, t):
    time.sleep(0.0005)
    if branch > 3:
        if 8 <= branch <= 12:
            if random.randint(0, 2) == 0:
                t.color('snow')  # 白
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branch / 3)
        elif branch < 8:
            if random.randint(0, 1) == 0:
                t.color('snow')
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branch / 2)
        else:
            t.color('sienna')  # 赭(zhě)色
            t.pensize(branch / 10)  # 6
        t.forward(branch)
        a = 1.5 * random.random()
        t.right(20 * a)
        b = 1.5 * random.random()
        Tree(branch - 10 * b, t)
        t.left(40 * a)
        Tree(branch - 10 * b, t)
        t.right(20 * a)
        t.up()
        t.backward(branch)
        t.down()

# 掉落的花瓣
def Petal(m, t):
    for i in range(m):
        a = 200 - 400 * random.random()
        b = 10 - 20 * random.random()
        t.up()
        t.forward(b)
        t.left(90)
        t.forward(a)
        t.down()
        t.color('lightcoral')  # 淡珊瑚色
        t.circle(1)
        t.up()
        t.backward(a)
        t.right(90)
        t.backward(b)

# 繪圖區域
t = T.Turtle()
# 畫布大小
w = T.Screen()
t.hideturtle()  # 隱藏畫筆
t.getscreen().tracer(5, 0)
w.screensize(bg='wheat')  # wheat小麥
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')

# 畫櫻花的軀干
Tree(60, t)
# 掉落的花瓣
Petal(200, t)
w.exitonclick()
T.done()

效果

在這里插入圖片描述



圓舞曲

from turtle import *

def stop():
    global running
    running = False

def main():
    global running
    clearscreen()
    bgcolor("gray10")
    tracer(False)
    shape("triangle")
    f =   0.793402
    phi = 9.064678
    s = 5
    c = 1
    # create compound shape
    sh = Shape("compound")
    for i in range(10):
        shapesize(s)
        p =get_shapepoly()
        s *= f
        c *= f
        tilt(-phi)
        sh.addcomponent(p, (c, 0.25, 1-c), "black")
    register_shape("multitri", sh)
    # create dancers
    shapesize(1)
    shape("multitri")
    pu()
    setpos(0, -200)
    dancers = []
    for i in range(180):
        fd(7)
        tilt(-4)
        lt(2)
        update()
        if i % 12 == 0:
            dancers.append(clone())
    home()
    # dance
    running = True
    onkeypress(stop)
    listen()
    cs = 1
    while running:
        ta = -4
        for dancer in dancers:
            dancer.fd(7)
            dancer.lt(2)
            dancer.tilt(ta)
            ta = -4 if ta > 0 else 2
        if cs < 180:
            right(4)
            shapesize(cs)
            cs *= 1.005
        update()
    return "DONE!"

if __name__=='__main__':
    print(main())
    mainloop()

效果

在這里插入圖片描述



哆啦A夢

import turtle


def flyTo(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
def drawEye():
    turtle.tracer(False)
    a = 2.5
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a -= 0.05
        else:
            a += 0.05
        turtle.left(3)
        turtle.fd(a)
    turtle.tracer(True)
def beard():
    """ 畫胡子, 一共六根
    """
    # 左邊第一根胡子
    flyTo(-37, 135)
    turtle.seth(165)
    turtle.fd(60)
    # 左邊第二根胡子
    flyTo(-37, 125)
    turtle.seth(180)
    turtle.fd(60)
    # 左邊第三根胡子
    flyTo(-37, 115)
    turtle.seth(193)
    turtle.fd(60)
    # 右邊第一根胡子
    flyTo(37, 135)
    turtle.seth(15)
    turtle.fd(60)
    # 右邊第二根胡子
    flyTo(37, 125)
    turtle.seth(0)
    turtle.fd(60)
    # 右邊第三根胡子
    flyTo(37, 115)
    turtle.seth(-13)
    turtle.fd(60)
def drawRedScarf():
    """ 畫圍巾
    """
    turtle.fillcolor("red")  # 填充顏色
    turtle.begin_fill()
    turtle.seth(0)  # 朝向右
    turtle.fd(200)  # 前進10個單位
    turtle.circle(-5, 90)
    turtle.fd(10)
    turtle.circle(-5, 90)
    turtle.fd(207)
    turtle.circle(-5, 90)
    turtle.fd(10)
    turtle.circle(-5, 90)
    turtle.end_fill()
def drawMouse():
    flyTo(5, 148)
    turtle.seth(270)
    turtle.fd(100)
    turtle.seth(0)
    turtle.circle(120, 50)
    turtle.seth(230)
    turtle.circle(-120, 100)
def drawRedNose():
    flyTo(-10, 158)
    turtle.fillcolor("red")  # 填充顏色
    turtle.begin_fill()
    turtle.circle(20)
    turtle.end_fill()
def drawBlackdrawEye():
    turtle.seth(0)
    flyTo(-20, 195)
    turtle.fillcolor("#000000")  # 填充顏色
    turtle.begin_fill()
    turtle.circle(13)
    turtle.end_fill()
    turtle.pensize(6)
    flyTo(20, 205)
    turtle.seth(75)
    turtle.circle(-10, 150)
    turtle.pensize(3)
    flyTo(-17, 200)
    turtle.seth(0)
    turtle.fillcolor("#ffffff")
    turtle.begin_fill()
    turtle.circle(5)
    turtle.end_fill()
    flyTo(0, 0)
def drawFace():
    turtle.forward(183)  # 前行183個單位
    turtle.fillcolor("white")  # 填充顏色為白色
    turtle.begin_fill()  # 開始填充
    turtle.left(45)  # 左轉45度
    turtle.circle(120, 100)  # 右邊那半邊臉
    turtle.seth(90)  # 朝向向上
    drawEye()  # 畫右眼睛
    turtle.seth(180)  # 朝向左
    turtle.penup()  # 抬筆
    turtle.fd(60)  # 前行60
    turtle.pendown()  # 落筆
    turtle.seth(90)  # 朝向上
    drawEye()  # 畫左眼睛
    turtle.penup()  # 抬筆
    turtle.seth(180)  # 朝向左
    turtle.fd(64)  # 前進64
    turtle.pendown()  # 落筆
    turtle.seth(215)  # 修改朝向
    turtle.circle(120, 100)  # 左邊那半邊臉
    turtle.end_fill()  #
def drawHead():
    """ 畫了一個被切掉下半部分的圓
    """
    turtle.penup()  # 抬筆
    turtle.circle(150, 40)  # 畫圓, 半徑150,圓周角40
    turtle.pendown()  # 落筆
    turtle.fillcolor("#00a0de")  # 填充色
    turtle.begin_fill()  # 開始填充
    turtle.circle(150, 280)  # 畫圓,半徑150, 圓周角280
    turtle.end_fill()
def drawAll():
    drawHead()
    drawRedScarf()
    drawFace()
    drawRedNose()
    drawMouse()
    beard()
    flyTo(0, 0)
    turtle.seth(0)
    turtle.penup()
    turtle.circle(150, 50)
    turtle.pendown()
    turtle.seth(30)
    turtle.fd(40)
    turtle.seth(70)
    turtle.circle(-30, 270)
    turtle.fillcolor("#00a0de")
    turtle.begin_fill()
    turtle.seth(230)
    turtle.fd(80)
    turtle.seth(90)
    turtle.circle(1000, 1)
    turtle.seth(-89)
    turtle.circle(-1000, 10)
    turtle.seth(180)
    turtle.fd(70)
    turtle.seth(90)
    turtle.circle(30, 180)
    turtle.seth(180)
    turtle.fd(70)
    turtle.seth(100)
    turtle.circle(-1000, 9)
    turtle.seth(-86)
    turtle.circle(1000, 2)
    turtle.seth(230)
    turtle.fd(40)
    turtle.circle(-30, 230)
    turtle.seth(45)
    turtle.fd(81)
    turtle.seth(0)
    turtle.fd(203)
    turtle.circle(5, 90)
    turtle.fd(10)
    turtle.circle(5, 90)
    turtle.fd(7)
    turtle.seth(40)
    turtle.circle(150, 10)
    turtle.seth(30)
    turtle.fd(40)
    turtle.end_fill()
    # 左手
    turtle.seth(70)
    turtle.fillcolor("#FFFFFF")
    turtle.begin_fill()
    turtle.circle(-30)
    turtle.end_fill()
    # 腳
    flyTo(103.74, -182.59)
    turtle.seth(0)
    turtle.fillcolor("#FFFFFF")
    turtle.begin_fill()
    turtle.fd(15)
    turtle.circle(-15, 180)
    turtle.fd(90)
    turtle.circle(-15, 180)
    turtle.fd(10)
    turtle.end_fill()
    flyTo(-96.26, -182.59)
    turtle.seth(180)
    turtle.fillcolor("#FFFFFF")
    turtle.begin_fill()
    turtle.fd(15)
    turtle.circle(15, 180)
    turtle.fd(90)
    turtle.circle(15, 180)
    turtle.fd(10)
    turtle.end_fill()
    # 右手
    flyTo(-133.97, -91.81)
    turtle.seth(50)
    turtle.fillcolor("#FFFFFF")
    turtle.begin_fill()
    turtle.circle(30)
    turtle.end_fill()
    # 口袋
    flyTo(-103.42, 15.09)
    turtle.seth(0)
    turtle.fd(38)
    turtle.seth(230)
    turtle.begin_fill()
    turtle.circle(90, 260)
    turtle.end_fill()
    flyTo(5, -40)
    turtle.seth(0)
    turtle.fd(70)
    turtle.seth(-90)
    turtle.circle(-70, 180)
    turtle.seth(0)
    turtle.fd(70)
    # 鈴鐺
    flyTo(-103.42, 15.09)
    turtle.fd(90)
    turtle.seth(70)
    turtle.fillcolor("#ffd200")
    turtle.begin_fill()
    turtle.circle(-20)
    turtle.end_fill()
    turtle.seth(170)
    turtle.fillcolor("#ffd200")
    turtle.begin_fill()
    turtle.circle(-2, 180)
    turtle.seth(10)
    turtle.circle(-100, 22)
    turtle.circle(-2, 180)
    turtle.seth(180 - 10)
    turtle.circle(100, 22)
    turtle.end_fill()
    flyTo(-13.42, 15.09)
    turtle.seth(250)
    turtle.circle(20, 110)
    turtle.seth(90)
    turtle.fd(15)
    turtle.dot(10)
    flyTo(0, -150)
    drawBlackdrawEye()
def main():
    turtle.screensize(800, 6000, "#F0F0F0")
    turtle.pensize(3)
    turtle.speed(9)
    drawAll()
if __name__ == "__main__":
    main()
    turtle.mainloop()



效果

在這里插入圖片描述



時鐘


import turtle
from datetime import *

# 抬起畫筆,向前運動一段距離放下
def Skip(step):
    turtle.penup()
    turtle.forward(step)
    turtle.pendown()


def mkHand(name, length):
    # 注冊Turtle形狀,建立表針Turtle
    turtle.reset()
    Skip(-length * 0.1)
    # 開始記錄多邊形的頂點,當前的烏龜位置是多邊形的第一個頂點,
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    # 停止記錄多邊形的頂點,當前的烏龜位置是多邊形的最后一個頂點,將與第一個頂點相連,
    turtle.end_poly()
    # 回傳最后記錄的多邊形,
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)


def Init():
    global secHand, minHand, hurHand, printer
    # 重置Turtle指向北
    turtle.mode("logo")
    # 建立三個表針Turtle并初始化
    mkHand("secHand", 135)
    mkHand("minHand", 125)
    mkHand("hurHand", 90)
    secHand = turtle.Turtle()
    secHand.shape("secHand")
    minHand = turtle.Turtle()
    minHand.shape("minHand")
    hurHand = turtle.Turtle()
    hurHand.shape("hurHand")

    for hand in secHand, minHand, hurHand:
        hand.shapesize(1, 1, 3)
        hand.speed(0)

    # 建立輸出文字Turtle
    printer = turtle.Turtle()
    # 隱藏畫筆的turtle形狀
    printer.hideturtle()
    printer.penup()


def SetupClock(radius):
    # 建立表的外框
    turtle.reset()
    turtle.pensize(7)
    for i in range(60):
        Skip(radius)
        if i % 5 == 0:
            turtle.forward(20)
            Skip(-radius - 20)

            Skip(radius + 20)
            if i == 0:
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))
            elif i == 30:
                Skip(25)
                turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
                Skip(-25)
            elif (i == 25 or i == 35):
                Skip(20)
                turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
                Skip(-20)
            else:
                turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
            Skip(-radius - 20)
        else:
            turtle.dot(5)
            Skip(-radius)
        turtle.right(6)


def Week(t):
    week = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
    return week[t.weekday()]


def Date(t):
    y = t.year
    m = t.month
    d = t.day
    return "%s-%d-%d" % (y, m, d)


def Tick():
    # 繪制表針的動態顯示
    t = datetime.today()
    second = t.second + t.microsecond * 0.000001
    minute = t.minute + second / 60.0
    hour = t.hour + minute / 60.0
    secHand.setheading(6 * second)
    minHand.setheading(6 * minute)
    hurHand.setheading(30 * hour)

    turtle.tracer(False)
    printer.forward(65)
    printer.write(Week(t), align="center", font=("Courier", 14, "bold"))
    printer.back(130)
    printer.write(Date(t), align="center", font=("Courier", 14, "bold"))
    printer.home()
    turtle.tracer(True)

    # 100ms后繼續呼叫tick
    turtle.ontimer(Tick, 100)


def main():
    # 打開/關閉龜影片,并為更新圖紙設定延遲,
    turtle.tracer(False)
    Init()
    SetupClock(160)
    turtle.tracer(True)
    Tick()
    turtle.done()


if __name__ == "__main__":
    main()


效果

在這里插入圖片描述

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/257116.html

標籤:python

上一篇:大眾點評封ip,還字體加密?我直呼,就這啊!

下一篇:演算法小課堂——最小生成樹Kruskal

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more