2016-07-01 12 views
1

私はPygameを使ってPythonで単純サークルタイマーをコーディングしようとしています。 現時点では、次のようになります。 TimerアンチエイリアスアークPygame

ご覧のとおり、青い線は波打ちがあり、白い点が入っています。 pygame.draw.arc()関数を使用してこの青い線を達成していますが、アンチエイリアス処理されておらず、悪く見えます。私はそれをアンチエイリアスしたいと思いますが、これを実現するgfxdrawモジュールは、アーク幅の選択をサポートしていません。 「、私はこの問題を解決するだろう任意のpygameの機能を認識していないです

pygame.draw.arc(screen, blue, [center[0] - 120, center[1] - 120, 240, 240], pi/2, pi/2+pi*i*koef, 15) 
pygame.gfxdraw.aacircle(screen, center[0], center[1], 105, black) 
pygame.gfxdraw.aacircle(screen, center[0], center[1], 120, black) 

答えて

0

drawがあなたのように壊れているので、あなたは基本的に、解決策を自分でプログラム(またはpygameの以外のものを使用)する必要が意味:ここではコードスニペットですあなたが厚さを与えることはありませんgfxdrawと述べた。

一つ非常に醜いしかし、簡単な解決策は、弧のセグメントに複数回描画することです。欠落しているギャップを常に「埋め」ます。これはまだタイマーアークの非常に前面にいくつかのエイリアシングを残しますが、残りは入力されます。私は、一般的にこれをお勧めしません、私はhttps://www.cs.ucsb.edu/~pconrad/cs5nm/08F/ex/ex09/drawCircleArcExample.py

からdegreesToRadiansdrawCircleArcをコピーした

import pygame 
from pygame.locals import * 
import pygame.gfxdraw 
import math 

# Screen size 
SCREEN_HEIGHT = 350 
SCREEN_WIDTH = 500 

# Colors 
BLACK = (0, 0, 0) 
WHITE = (255, 255, 255) 
GREY = (150, 150, 150) 
RED = (255,0,0) 


# initialisation 
pygame.init() 
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) 
done = False 
clock = pygame.time.Clock() 

# We need this if we want to be able to specify our 
# arc in degrees instead of radians 
def degreesToRadians(deg): 
    return deg/180.0 * math.pi 

# Draw an arc that is a portion of a circle. 
# We pass in screen and color, 
# followed by a tuple (x,y) that is the center of the circle, and the radius. 
# Next comes the start and ending angle on the "unit circle" (0 to 360) 
# of the circle we want to draw, and finally the thickness in pixels 
def drawCircleArc(screen,color,center,radius,startDeg,endDeg,thickness): 
    (x,y) = center 
    rect = (x-radius,y-radius,radius*2,radius*2) 
    startRad = degreesToRadians(startDeg) 
    endRad = degreesToRadians(endDeg) 

    pygame.draw.arc(screen,color,rect,startRad,endRad,thickness) 


# fill screen with background 
screen.fill(WHITE) 
center = [150, 200] 
pygame.gfxdraw.aacircle(screen, center[0], center[1], 105, BLACK) 
pygame.gfxdraw.aacircle(screen, center[0], center[1], 120, BLACK) 

pygame.display.update() 

step = 10 
maxdeg = 0 

while not done: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      done = True 

    maxdeg = maxdeg + step 
    for i in range(min(0,maxdeg-30),maxdeg): 
     drawCircleArc(screen,RED,(150,200),119,i+90,max(i+10,maxdeg)+90,14) 
     #+90 will shift it from starting at the right to starting (roughly) at the top 
    pygame.display.flip() 

    clock.tick(2) # ensures a maximum of 60 frames per second 

pygame.quit() 

注意を解決策はありますが、ピンチで行う可能性があります。私はPythonで書かれている森林火災アルゴリズムの

+0

それは良く見えますが、まだ完全ではありません。私はグーグルにしようとするか、他の可能な解決策を考えようとする –

+1

あなたがpygameを使う必要があれば簡単な方法は、グラフィックスプログラムでそれを行い、スプライトシートからカウンタステップをblitすることです。あなたがその中にほんの一握りの場所しか必要としないなら、手書きのハックはおそらくその努力に値するものではありません。 – Isa

+1

なぜ次のセグメントを描画してからフラッドフィルを適用しないのですか? –

0

小アスキーアートスタイルのデモ:

import sys 

class Canvas: 
    def __init__(self): 
     self.rows=10 
     self.columns=10 
     self.cells = {(r,c):None for r in range(1,self.rows+1) for c in range(1,self.columns+1)} 
     for i in range(3,6): 
      self.cells[(i,5)] = 1 
      self.cells[(i,8)] = 1 
     for i in range(5,8): 
      self.cells[(3,i)] = 1 
      self.cells[(6,i)] = 1 

    def display(self): 
     for i in range(1,self.rows): 
      for j in range(1,self.columns): 
       sys.stdout.write("*" if self.cells[(i,j)] else " ") 
      sys.stdout.write("\n") 


    def fill(self, x, y, t): 
     if not self.cells[(x,y)]: 
      to_fill = [(x,y)] 
      while to_fill: 
       # pick a point from the queue 
       x,y = to_fill.pop() 
       # change color if possible 
       self.cells[(x,y)] = t 

       # now the neighbours x,y +- 1 
       for delta_x in range(-1,2): 
        xdx = x+delta_x 
        if xdx > 0 and xdx < self.columns+1: 
         for delta_y in range(-1,2): 
          ydy = y+delta_y 
          # avoid diagonals 
          if (delta_x == 0)^(delta_y == 0): 
           if ydy > 0 and ydy < self.rows+1: 
            # valid x+delta_x,y+delta_y 
            # push in queue if no color 
            if not self.cells[(xdx,ydy)]: 
             to_fill.append((xdx,ydy)) 

c = Canvas() 
c.display() 
c.fill(4,6,2) 
c.display() 

だから基本的には空のキャンバスを作成し、その中に醜い中空の長方形(最初の図)のようなものを描きます、塗りつぶしを実行し、再度、塗りつぶされた矩形を描画します:開始時

**** 
    * * 
    * * 
    *** 





    **** 
    **** 
    **** 
    *** 

、あなただけのゾーンを区切るために2線を描画し、X、ゾーン内の一点のy座標を渡すこの塗りつぶしメソッドを呼び出すことができます。

次に、次の塗りつぶしのために次の線を描き直します。