سؤال

وأود أن رسم خطوط (الموقف التعسفي وطول) على سطح في pygame، والتي هي نفسها صورة محملة من ملف على القرص.

ويمكن لأي شخص أن يشير لي إلى بعض الأمثلة التعليمات البرمجية التي يقوم بذلك؟

هل كانت مفيدة؟

المحلول

وهذا يجب أن تفعل ما كنت طالبا:

# load the image
image = pygame.image.load("some_image.png")

# draw a yellow line on the image
pygame.draw.line(image, (255, 255, 0), (0, 0), (100, 100))

وعادة ما لا يوجه إلى الصورة الأصلية، حيث سيكون لديك لإعادة تحميل صورة للحصول على الأصل الظهر (أو إنشاء نسخة منه قبل بدء الرسم على ذلك). ولعل ما تحتاجه فعلا هو شيء أكثر من هذا القبيل:

# initialize pygame and screen
import pygame
pygame.init()
screen = pygame.display.set_mode((720, 576))

# Draw the image to the screen
screen.blit(image, (0, 0))

# Draw a line on top of the image on the screen
pygame.draw.line(screen, (255, 255, 255), (0, 0), (50, 50))

نصائح أخرى

والمساعدة على حدة pygame.draw في pygame:

واسم     pygame.draw - وحدة pygame لرسم الأشكال

وFILE     د: ملفات \ برنامج \ python25 \ ليب \ حزم الموقع \ pygame \ draw.pyd

وظائف     aaline (...)         pygame.draw.aaline (السطحية أو اللون أو startpos، endpos، مزيج = 1): عودة مصحح         رسم خطوط الحواف المحسنة الجميلة

aalines(...)
    pygame.draw.aalines(Surface, color, closed, pointlist, blend=1): return Rect

arc(...)
    pygame.draw.arc(Surface, color, Rect, start_angle, stop_angle, width=1): return Rect
    draw a partial section of an ellipse

circle(...)
    pygame.draw.circle(Surface, color, pos, radius, width=0): return Rect
    draw a circle around a point

ellipse(...)
    pygame.draw.ellipse(Surface, color, Rect, width=0): return Rect
    draw a round shape inside a rectangle

line(...)
    pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
    draw a straight line segment

lines(...)
    pygame.draw.lines(Surface, color, closed, pointlist, width=1): return Rect
    draw multiple contiguous line segments

polygon(...)
    pygame.draw.polygon(Surface, color, pointlist, width=0): return Rect
    draw a shape with any number of sides

rect(...)
    pygame.draw.rect(Surface, color, Rect, width=0): return Rect
    draw a rectangle shape
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top