wxPythonでタイマーを使ってアニメーションを描画した.
Processingで同じプログラムを作る5倍はめんどくさいw
うまく動けば自由落下のアニメーションが動くはず.
厳密には自由落下ではないけど...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import wx class myWindow(wx.Frame): def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id, title) self.panel = wx.Panel(self, size=(300, 600)) self.panel.SetBackgroundColour('WHITE') self.Fit() self.createTimer() self.counter = 0 self.ball = Ball(10) def InitBuffer(self): size = self.GetClientSize() self.buffer = wx.EmptyBitmap(max(1,size.width), max(1,size.height)) dc = wx.BufferedDC(None, self.buffer) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) def createTimer(self): self.timer=wx.Timer(self) self.timer.Start(20) self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) def onTimer(self, event): self.InitBuffer() dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) dc.Clear() dc.BeginDrawing() dc.SetPen(wx.Pen("black", 3, wx.SOLID)) dc.DrawText("Free fall",20,20) self.ball.Fall(dc) dc.EndDrawing() class Ball: def __init__(self,R): self.r = R self.v = 0 self.x = 300/2 self.y = 0 def Fall(self,dc): self.v += 0.5 self.y += self.v/2 if self.y > 600: self.y = 0 self.v = 0 dc.SetPen(wx.Pen(wx.Colour(255,165,0))) dc.SetBrush(wx.Brush(wx.Colour(255,0,0))) dc.DrawCircle(150,self.y,self.r) if __name__ == "__main__": app = wx.PySimpleApp() w = myWindow(title="Free Fall") w.Show() app.MainLoop() |