ãæªå®æãã¸ã§ã¹ãã£å ¥å - Kivy Advent Calendar 2013
(â»ç·¨éä¸ã§ã...)
Kivyã¯ã¸ã§ã¹ãã£èªèã®ã©ã¤ãã©ãªãæã£ã¦ãã¾ãã
ãµã³ãã«ã³ã¼ã (https://github.com/kivy/kivy/tree/master/examples/gestures) ãããç°¡åãªãã¹ããã§ãã¾ãããããã¯4種é¡ã®ä¸çæ¸ãã·ã³ãã«ï¼checkãcircleãsquareãcrossï¼ãåºå®ã§æã£ã¦èå¥ããã ãã§ããããã§
- èªåã§ãã¿ã¼ã³ãç»é²ãã¦èå¥ã§ããã
- Palmã®ä¸çæ¸ãå ¥å (Grafiti) 並ã«æ°ååã®ãã¿ã¼ã³ãå ¥ãã¦ãå®ç¨çãªæéã§èå¥ã§ããã
ã¨ããç¹ãå®é¨ãã¦ã¿ããã¨æãã¾ãã
ã
2013-12-26 追è¨
ããããªããããã®è¨äºãã®ãã¢ããã§ããä¼ã¿ä¸ã«ãã£ããããã¾ãã
(kivy.storageã使ããã¨æã£ãããKivy Launcher 1.7.2ã§å®è£
ããã¦ãªãã£ã...)
ã
ä¸æ¦ã¯ãã¼ãºããã¦ãã ãããã²ã¨ã¾ãKivy Launcherã¨æ¯ãã¦ã¿ã¦æã£ããã¨ãã
Kivy 1.8ã¯ããã¡ãã
ãã©ããã³ã°è¿½ã£ã¦ã¾ããã大éã«éç¥ã¡ã¼ã«ãæ¥ã¦ãã¦Kivyãã¼ã ããã°ãã·ã¡ã·ã¡ç´ãã¦ããã¨ããã¿ããã§ãããªããä»é±ä¸ã«ã¨ãè¨ã£ã¦ããããªæ°ããã¾ãããä»å¹´ä¸ãç¡çãããªãã®ã£ã¦å¢ã...orz
(ã¾ããã°ããã¯Python3対å¿ã®æ¹ã«åãå
¥ãã¦ããã¿ããã§ãã...)
pyjnius使ããªããªããã
Advent Calendarã§pyjniusãã¿ãããããã£ãã®ã§ãããå
¨é¨ç¡é§ã«ãªãããããã¾ããã
ã¨ããã®ãåçãå é度ã»ã³ãµãGPSãªã©ãæ©ç¨®ä¾åãªãã®ã¯ãplyerãã¨ããã¢ã¸ã¥ã¼ã«ã§ã¾ã¨ãã¦ã¾ãã¦ãããã使ãã°å°ã楽ã«æ¸ããããã«ãªãããã§ãã
https://plyer.readthedocs.org/en/latest/
ãã ãä»ã®ã¨ããiOS (pyobjc) ã®å¯¾å¿ãå«ã¾ãã¦ãªãã®ã§ãKivy-iOSã®äººã«é å¼µã£ã¦ããããã¨ã«ãªããã...
ä»å¾tryãããã¨ãã
èªåãååç解ãã¦ããªãã®ã§ããããã¨æã£ã¦ãã¦ãåºæ¥ãªãã£ããã¿ãå¤ãã£ãä¸æ¹ãããã¥ã¡ã³ãã§åãã¨ãã£ã¦ãããªããåããªããã®ãå¤ã ãã£ã¦çµæ§ãããã¾ããã
- kivy.garden
- æ¡å¼µã¦ã£ã¸ã§ãããéãã¦GitHubããç´æ¥ã¤ã³ã¹ãã¼ã«ã§ããããã«ããKivyå°ç¨ã®ã¤ã³ã¹ãã¼ã©ãã¹ããã風ã®ã»ã¬ã¯ã¿ï¼æ¥ä»é¸æï¼ãç»é¢è»¢æã®æ¡å¼µçãç»åããµã ãã¤ã«ã§è¡¨ç¤ºãããã¡ã¤ã«ã»ã¬ã¯ã¿ãªã©ãé¢ç½ããã®ãããããããã®ã§ãããããããã¤ã³ã¹ãã¼ã©ãAndroidã§ã¯åããªãã®ã§ã2013-12-03 QRã³ã¼ãã¿ããã«ãã¢ã¸ã¥ã¼ã«ãåããã©ã«ãå ã«ç½®ãã¦importãããªã©ã®ç´°å·¥ãå¿ è¦ã«ãªãã¾ã...
- kivy.uix.camera
- ã«ã¡ã©ããã®åç»ããªã¢ã«ã¿ã¤ã ã§ç»é¢ä¸ã«åããã®ã§ãããå°ãªãã¨ãNexus7-2013ã§ã¯åãã¾ããï¼ä½è èªèº«ãgstreamer使ããªãã¨ç¡çã¨ãè¨ã£ã¦ã¾ããï¼ã
- kivy.storage
- key-valueã¹ãã¢ã1.7.0ã§å ¥ã£ãã¨æ¸ãã¦ããã2013-12-25 ã¸ã§ã¹ãã£ã®è¨é²ã«ä½¿ããã¨æã£ãããå½±ãå½¢ãããã¾ããã§ãã...
SL4Aã¯ï¼
è¨åã¯ãã¾ããããªãªã¼ã¹ãåæ»ãã¦ããã®ã§ä½¿ãã®ã¯ã©ããªãã ããã£ã¦æãã
å®å
¨åæ¢ãã¦ããããã§ã¯ãªããã°ç´ãã¯å¼ãç¶ãè¡ããã¦ãã¾ããããªãªã¼ã¹ã¯é£ããã®ããªã£ã¦ç¶æ³ã§ãã
ã¾ã¨ã
ããããåé¡ã¯ããã¾ããã©ãKivyã«ã¤ãã¦ã¯ããå°ã追ã£ããã¦ã¿ãããã¨æãã¾ãã
ã¾ãèªåã¯ä»äºçã«ã¯Webæ¹é¢ã®äººã ããHTML/CSS/MetaJSãªããã§ãæè¿ã¯ãã«ãã¿ããããã¬ã¼ã ãããã¡ã使ãã¦ããããåºæ¥ããã¨ã¯åãã£ã¦ã¯ããã®ã§ãããæ馴ããPythonã§æ¸ããã®ããã¯ãå¬ãããã§ãããã
cymunkã使ã£ã¦éªãéããã - Kivy Advent Calendar 2013
cymunkã¯2次å
ç©çã¨ã³ã¸ã³ChipMunk (http://chipmunk-physics.net/) ã®Cythonå®è£
ã§ãKivyLauncerã«ãããã©ã«ãã§å
¥ã£ã¦ãã¾ãã
https://cymunk.readthedocs.org/en/latest/
ãªãã¸ã§ã¯ãã®éåãè¡çªãå¼¾æ§ã®è¨ç®å¦çããã£ã¦ããããã®ã§ãcymunkã®ãµã³ãã«ã³ã¼ãã§ã¯ã«ã©ãã«ãªãã¼ã«ãå¼¾ã¾ãã¦ãã¾ãã
ãã®ãµã³ãã«ã³ã¼ãã
- ã«ã©ã¼ãã¼ã«ã§ã¯ãªãå°ããç½ãçµæ¶ã«ãã
- ã¿ããããªãã¦ãã©ã³ãã ã§çºçããã
- éåãå¼±ããã¦ãå·¦å³ã«æºããããã«ãã
- å¼¾æ§ã¯ã»ã¼ã¼ãã«ãã
- å°é¢çã«çãããè·¡ã¯æ®ãã¤ã¤è¨ç®å¯¾è±¡ããå¤ã
ã¨ããã°ãéªãéãç©ãã£ã¦ãããã«ã¿ããªãããªãâ¦ã¨æã£ãã®ã§å®é¨ãã¦ã¿ã¾ããã
çµæã¯â¦
ãªãããå°é¢çã«çããããã®å¦çããã¡ãã¨ãã£ã¦ããªãã®ã§ãå°é¢ãéªçã転ãã£ã¦ãããã¦ã
ãã¾ãéªã£ã½ããªãããªã
(/sdcard/kivy/letitsnow/)
android.txt | ãç´æ |
flake.png | éªã®çµæ¶ã¿ãããªç»å (ãªããã°circle.pngããªãã¼ã ãã¦) |
main.py | ã¹ã¯ãªããæ¬ä½ |
(android.txt)
title=letitsnow author=cheeseshop orientation=landscape
(main.py)
from kivy.clock import Clock from kivy.app import App from kivy.graphics import Color, Rectangle from kivy.uix.widget import Widget from kivy.properties import DictProperty, ListProperty from kivy.core.image import Image from cymunk import Space, Segment, Vec2d, Body, Circle from random import random from kivy.lang import Builder from os.path import dirname, join class Snow(Widget): cbounds = ListProperty() cmap = DictProperty({}) flist = ListProperty() def __init__(self, **kwargs): super(Snow, self).__init__(**kwargs) self.init_space() self.bind(size=self.update_bounds, pos=self.update_bounds) self.texture = Image(join(dirname(__file__), 'flake.png')).texture Clock.schedule_interval(self.step, 1 / 30.) def init_space(self): self.space = space = Space() space.iterations = 30 space.gravity = (0, -300) space.sleep_time_threshold = 0.5 space.collision_slop = 0.5 for x in xrange(4): seg = Segment(space.static_body, Vec2d(0, 0), Vec2d(0, 0), 0) seg.elasticity = 0.0 self.cbounds.append(seg) space.add_static(seg) self.update_bounds() def update_bounds(self, *largs): a, b, c, d = self.cbounds x0, y0 = self.pos x1 = self.right y1 = self.top self.space.remove_static(a) self.space.remove_static(b) self.space.remove_static(c) self.space.remove_static(d) a.a = (x0, y0); a.b = (x1, y0) b.a = (x1, y0); b.b = (x1, y1) c.a = (x1, y1); c.b = (x0, y1) d.a = (x0, y1); d.b = (x0, y0) self.space.add_static(a) self.space.add_static(b) self.space.add_static(c) self.space.add_static(d) def step(self, dt): if random() < 0.4: self.add_flake(random() * self.right, self.top - 20, 5) if random() < 0.2: self.space.gravity = (100-random()*200, -50*random()-50) self.space.step(1 / 30.) self.update_objects() def update_objects(self): for body, obj in self.cmap.iteritems(): p = body.position radius, color, rect = obj rect.pos = p.x - radius, p.y - radius rect.size = radius * 2, radius * 2 def add_flake(self, x, y, radius): body = Body(100, 1e9) body.position = x, y circle = Circle(body, radius) circle.elasticity = 0.1 self.space.add(body, circle) with self.canvas.before: color = Color(1, 1, 1) rect = Rectangle( texture=self.texture, pos=(self.x - radius, self.y - radius), size=(radius * 2, radius * 2)) self.cmap[body] = (radius, color, rect) self.flist.append((body, circle) ) if len(self.flist) > 300: body, circle = self.flist.pop(0) self.space.remove(body) self.space.remove(circle) class SnowApp(App): def build(self): return Snow() if __name__ == '__main__': SnowApp().run()
ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ã/ã¿ã¤ãã¼ã使ã
端æ«ã®ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ãæ©è½ãNexus7-2013ã§ã¯[é»æº]ï¼[é³éå°]ãåæã«0.3ç§ãããæ¼ãã¨æ®ãã¾ãããã¾ããããããã«ããã失æãã¦ããªã¥ã¼ã 表示ã¾ã§æ®ãã¦ãã¾ã£ããâ¦
Kivyèªä½ã«ãã¹ã¯ãªã¼ã³ã·ã§ãããåãæ©è½ããã£ã¦ããfrom kivy.modules import keybindingãã¨ã¤ã³ãã¼ãããã¨ãF12ããã¼ãæ¼ãã¦æ®ãã¾ããã§ããã¤ããã¼å
¥åã§ããã¨ã¯éããªãããããã¿ã³ãæ¼ãããæ®ããã ã¨ãã¿ã³ãã®ãã®ãåã£ã¦ãã¾ãã¾ãã
ããã§ã¯ã2013-12-09 ç»é¢è»¢æãã§ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ããããã¢ããªèªä½ã«ã»ã«ãã¿ã¤ãã¼ã¤ãã®ã¹ã¯ãªã¼ã³ã·ã§ããæ©è½ã追å ãã¦ã¿ã¾ãã
解説
ã¿ã¤ãã¼ã«ã¤ãã¦
ã¯ã³ã·ã§ããã¿ã¤ãã¼ (schedule_once) ãkvè¨èªå´ã§ä½¿ã£ã¦ã¿ã¾ãããClockã¯ã©ã¹ã¯kvè¨èªã®çµã¿è¾¼ã¿ã§ã¯ãªãã®ã§importãå¿
è¦ã§ãããã¡ã½ãããå¢ããããã¯ããããªã¨â¦
注æç¹ã¨ãã¦ã¯ã¿ã¤ãã¼ã®ã³ã¼ã«ããã¯ã¯1ã¤å¼æ°ãåãã£ã¦ã¨ããã§ãããããdtã¯ã·ã¹ãã æéã£ã½ãã§ããã¾ãå
¨ç¶ä½¿ããªããã©å¼æ°ã®æ°ãåãããªãã¨ãããªãã®ã§â¦
ã¹ã¯ãªã¼ã³ã·ã§ãã
ç¹ã«ãã¡ã¤ã«åãæå®ããªããã°ãscheenshot0001.pngãã¨ããå½¢å¼ã§ãmain.pyã¨åããã©ã«ãã«ä¿åãã¦ããã¾ãããã ä¿åã«æéããããã®ã§ãç»é¢ãä¸ç¬åºã¾ãã®ãåããã¨æãã¾ãã
Homeç»é¢ã¨Settingç»é¢ãSettingã®ä¸ãã2çªç®ãã5ç§å¾ã«ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ãããã¿ã³ã
ã¹ã©ã¤ãï¼åç´æ¹åã¨æ°´å¹³æ¹åï¼ã
(/sdcard/kivy/capture/)
android.txt | ãç´æ |
main.py | 5è¡è¿½å ããã ã ã»ã¨ãã©ä½¿ãåã |
(android.txt)
title=capture author=cheeseshop orientation=portrait
(main.py)
from kivy.app import App from kivy.properties import StringProperty from kivy.uix.screenmanager import ScreenManager, Screen from kivy.uix.screenmanager import ShaderTransition, SlideTransition, FadeTransition, WipeTransition from kivy.core.window import Window FADEINOUT_TRANSITION_FS = '''$HEADER$ uniform float t; uniform sampler2D tex_in; uniform sampler2D tex_out; void main(void) { float t1 = 0.45; float t2 = 0.55; vec4 cin = vec4(texture2D(tex_in, tex_coord0.st)); vec4 cout = vec4(texture2D(tex_out, tex_coord0.st)); vec4 frag_col = t < t1 ? vec4*1 on_text: app.settr(self.text) Button: pos_hint: {'center_x':0.5, 'top':0.4} size_hint: (None, None) size: (200, 50) text: 'Capture after 5sec' on_press: Clock.schedule_once(app.capture, 5) Button: pos_hint: {'center_x':0.5, 'top':0.2} size_hint: (None, None) size: (200, 50) text: 'Back to home' on_press: root.manager.transition = app.tr1; root.manager.current = 'home' ''') class FadeInOutTransition(ShaderTransition): fs = StringProperty(FADEINOUT_TRANSITION_FS) class HomeScreen(Screen): pass class SettingScreen(Screen): pass class ScreenApp(App): trs = { 'Slide_H': (SlideTransition(direction='right'), SlideTransition(direction='left')), 'Slide_V': (SlideTransition(direction='up'), SlideTransition(direction='down')), 'Fade': FadeTransition(), 'Wipe': WipeTransition(), 'FadeIO': FadeInOutTransition(), } def settr(self, tr): trs = self.trs[tr] if isinstance(trs, tuple): self.tr0 = trs[0] self.tr1 = trs[1] else: self.tr0 = trs self.tr1 = trs def capture(self, dt): Window.screenshot() def build(self): self.sm = ScreenManager() self.sm.add_widget(HomeScreen(name='home')) self.sm.add_widget(SettingScreen(name='setting')) self.settr('Fade') return self.sm if __name__ == '__main__': ScreenApp().run()
*1:1.0 - t / t1) * cout) :
t > t2 ? vec4((t - t2) / (1.0 - t2) * cin) : vec4(0.0);
gl_FragColor = frag_col;
}
'''
from kivy.lang import Builder
Builder.load_string('''
#:import Clock kivy.clock.Clock
ãæªå®æãRPG風ã«ãã£ã©ã¯ã¿ãåãã (2) - Kivy Advent Calendar 2013
ä»åº¦ã¯ãèæ¯ãã¹ã¯ãã¼ã«ï¼ãã£ã©ã¯ã¿ã足è¸ã¿ãã§ç§»åãã¦ããããã«è¦ãã¾ããèæ¯ãScrollViewã«ãã¦ããããAnimationã§ã³ã³ããã¼ã«ã§ãããã©ãããã¨ããå®é¨ã§ãã
FloatLayout (èæ¯) Image (ãã£ã©ã¯ã¿) ... ä½ç½®ï¼ç»åãå¤æ´ â FloatLayout ScrollView (èæ¯) ... ä½ç½®ãå¤æ´ Image (ãã£ã©ã¯ã¿) ... ç»åãå¤æ´
(22:30)
ç³ã訳ããã¾ããããä»åã¯ã®ãã¢ããããã¦ãã ããã
ã
ä»ã®ã¨ãããã¾ããã£ã¦ããã®ã¯æ¬¡ã®ã¨ããã
- åå (2013-12-19) ããå¼ç¶ãã UI
- FloatLayoutä¸ã§èæ¯ãã¬ã¼ã (ScrollView) ã¨ãã£ã©ã¯ã¿ (Image) ãéãåããã
- ScrollViewã®å é¨ã«ããã (GridLayoutã§é ç½®ããImage群) ãæããã
次ã®ç¹ããã¾ããã£ã¦ãã¾ããã
- ScrollViewã®å·¦ä¸é ã«ããããåºå®ããã¦ãã¾ãã(scroll_x,scroll_y)ããããã£ãå¤æ´ãã¦ãåãããã¨ãã§ããªã
(ã¹ã¯ãªã¼ã³ã·ã§ããã§ãåããã¥ããã¨ã¯æãã¾ãã) ãã£ã©ã¯ã¿ã®åæä½ç½®ã¯ãããã®ä¸å¤®ã§ãèæ¯ã®è¦ç´ (ãããããã)ã¨ãã£ã©ã¯ã¿ãæãã¯ããªã®ã§ãããããããGameé åã®å·¦ä¸è©°ãã¨ãªã£ã¦åããªãç¶æ³ãªã®ã§ãå½ç¶ãã£ã©ã¯ã¿ã¨æã£ã¦ãã¾ããã
ããããsize_hintãªã©ã®æå®ãééã£ã¦ãããã ã¨æãã¾ããããããã試è¡é¯èª¤ãã¦ãåãæ°é
ãããªãç¶æ³ã§ãâ¦å¹´æ«å¹´å§ã®å®¿é¡ã¨ããã¦ãã ããã
ã¤ãã³ãå¦ç - Kivy Advent Calendar 2013
ç¸å¤ããããã¿åã/æéåãã§ç³ã訳ãªãã§ããã¤ãã³ãå¦çã®åé¡ã§å°ãå ç (http://d.hatena.ne.jp/cheeseshop/20131205) ããã®ã§ããã®ä»¶ã§å°ãæ¸ããã¨ã«ãã¾ãã
Kivyã®ã¤ãã³ãå¦çã¯ãåã¦ã£ã¸ã§ããã¯ã©ã¹ããããã¿ã¤ãã³ã°ãã§ãã¤ãã³ãã«çµã³ã¤ããé¢æ°ç¾¤ãå®è¡ãããã¨ãããã®ã§ããä»åã®Advent Calendarã§ä½¿ã£ã¦ãããã®ãæããã¨
è¨äº | ã¯ã©ã¹ | ã¤ãã³ã | åä½ |
---|---|---|---|
2013-12-01 ãã¡ã¤ã«é¸æ | Button | on_release | Load/Cancelãã¿ã³ãæ¼ãããå®è¡(ããã¼) |
2013-12-03 QRã³ã¼ã | TextInput | on_text_validate | Enterãã¼ãæ¼ãããQRã³ã¼ãçæ |
2013-12-05 ã¹ã©ã¤ã | RstDocument | on_touch_up | ã¿ããããããããã¢ãããéã |
2013-12-08 ãããã¢ãã | FloatLayout | on_touch_up | ã¿ãããããããã«ãéã |
2013-12-09 ç»é¢è»¢æ | Spinner | on_text | é¸æè¢ãå¤æ´ãããç»é¢å¹æå·®æ¿ |
2013-12-09 ç»é¢è»¢æ | Button | on_press | ãã¿ã³ãæ¼ãããå¥ã¹ã¯ãªã¼ã³ã«è»¢æ |
2013-12-10 ã¢ããªå¾©å¸° | App | on_pause | å¥ã®ã¢ããªã¸ã®åæ¿æ |
2013-12-10 ã¢ããªå¾©å¸° | App | on_resume | å¥ã®ã¢ããªããã®å¾©å¸°æ |
2013-12-11 ã«ã¼ã | Scatter | on_touch_up | ã¿ãããããã²ã£ããè¿ã |
2013-12-13 æµè¡èª | Button | on_press | ãã¿ã³ãæ¼ãããåã |
2013-12-14 åç | StackLayout | on_touch_up | ã¿ãããããã«ã¡ã©èµ·å |
2013-12-14 åç | PythonActivity | on_activity_result | ã«ã¡ã©çµäºã®ã¿ã¤ãã³ã° |
2013-12-15 ããã¹ãå ±æ | Button | on_press | ãã¿ã³ãæ¼ãããã¡ã¼ã©èµ·å |
2013-12-16 Webãã©ã¦ã¶ | Button | on_press | ãã¿ã³ãæ¼ããããã©ã¦ã¶èµ·å |
2013-12-16 Webãã©ã¦ã¶ | Button | on_press | ãã¿ã³ãæ¼ããããã©ã¦ã¶èµ·å |
2013-12-18 Launcher | Button | on_press | ãã¿ã³ãæ¼ãããKivyLauncherèµ·å |
2013-12-19 ãã£ã©ç§»å | Button | on_press | ãã¿ã³ãæ¼ããããã£ã©ã¯ã¿ç§»å |
2013-12-19 ãã£ã©ç§»å | Animation | on_progress | ç»åãé 次å¤ãã¦ã¢ãã¡ |
2013-12-19 ãã£ã©ç§»å | Animation | on_complete | æä»å¶å¾¡ãè§£é¤ |
ã¾ãããã¿ã³ãæ¼ãã¦ââãããã®ãå¤ãã§ããã§ãä¸ã«ã¯ã¢ãã¡ãã¢ããªãã¢ã¯ãã£ããã£ã®ããã«Kivyã«ãããã¦ã¼ã¶æä½ã¨ã¯é¢ä¿ãªãã¤ãã³ããçºçãããã®ãããã¾ãã
on_touch_up / on_touch_downã«ã¤ãã¦
ãã¦ãåé¡ã ã£ãã®ã¯ã2013-12-05 ã¹ã©ã¤ããã®on_touch_upã§ããããã§ã¯ç»é¢ãããã«ã¿ãããããreStructureTextã½ã¼ã¹ããããã¢ãããè¦ãã¦ãã¾ããããããã§ã¯on_touch_upã®æ»ãå¤ã§åé¡ã解決ãããã®ããã«æ¸ãã¦ãã¾ãããå®éã«ã¯ããã§ã¯ããã¾ããã§ãããä¸è¦ãä»éããã¹ã©ã¤ããã®ã½ã¼ã¹ãè¦ãã¦ãã¾ããããå®ã¯
- å ¨é¨ã®ã¹ã©ã¤ã (page01ãpage03) ã®ã½ã¼ã¹ãä¸æã«éã (ã©ããä¸çªä¸ã«ãªããã¯ä¸å®)
- å¤é¨ãã¿ããããã¨ãã«ã¯3ã¤ã¨ãéãã
ã¨ãããã®ã§ãããå¿
ããã表示ãã¦ããã¹ã©ã¤ãã®ã½ã¼ã¹ãè¦ããªãã£ãã¨ãããã¨ã§ãã
ä½æ
ãããªãã®ãã¨ããã°ãon_touch_upã¨ããã®ã¯ã¿ããããå ´æã«ããã¦ã£ã¸ã§ããã¸éãããã¤ãã³ãã§ã¯ãªããåã«ãã¿ããããã«ããæãé¢ãããã¨ããã¤ãã³ãã ããã§ãã
ã¤ã¾ãããã¿ããããå ´æ以å¤ã«ç½®ãããã¦ã£ã¸ã§ãããã«å¯¾ãã¦ãon_touch_upã¯çºçãããããããScreenManagerãCarouselã®ããã«ç»é¢è»¢æã«ãã£ã¦ãé表示ã«ãªã£ã¦ããã¦ã£ã¸ã§ãããã«ãon_touch_upã¯çºçãã¦ãã¾ãã®ã§ããã
: orientation: 'vertical' Label: text: 'LABEL1' on_touch_down: self.text = 'LABEL1: DOWN' on_touch_up: self.text = 'LABEL1: UP' Label: text: 'LABEL2' on_touch_down: self.text = 'LABEL2: DOWN' on_touch_up: self.text = 'LABEL2: UP' Label: text: 'LABEL3' on_touch_down: self.text = 'LABEL3: DOWN' on_touch_up: self.text = 'LABEL3: UP'
: orientation: 'vertical' Label: text: 'LABEL1' on_touch_down: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL1: DOWN') on_touch_up: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL1: UP') Label: text: 'LABEL2' on_touch_down: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL2: DOWN') on_touch_up: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL2: UP') Label: text: 'LABEL3' on_touch_down: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL3: DOWN') on_touch_up: self.collide_point(*args[1].pos) and setattr(self, 'text', 'LABEL3: UP')
(ã¾ãä¸è¬çã«ã¤ãã³ããã³ãã©ã¯ãkvè¨èªãããã¡ã½ããã§æ¸ãæ¹ã楽ã ã¨æãã¾ãâ¦)
ScreenManagerãCarouselã®é表示ã¦ã£ã¸ã§ããã«ã¤ãã¦ã¯ããããç¾å¨è¡¨ç¤ºããã¦ãããã®ã調ã¹ããã¨ãã§ãã¾ãããããããæ¡ä»¶ã«ãã¦ã¤ãã³ããåãä»ãããåãä»ããªãããåãæ¿ãããã¨ã«ãªãã¾ãã
self.collide_point(*touch.pos) | èªèº«ã«ã¿ããããã |
self.manager.current_screen is self | ScreenManagerãèªèº«ã表示ãã¦ããã |
self.parent.current_slide is self | Carouselãèªèº«ã表示ãã¦ããã (2013-12-05 ã¹ã©ã¤ãã¯ããã使ç¨) |
on_touch_up/on_touch_downã¯ãå ¨ç»é¢ã§ä½¿ãåã«ã¯ãããã£ãåé¡ã¯ãªã (2013-12-08 ãããã¢ãããªã©) ã®ã§ãããè¤æ°ãã£ããé表示è¦ç´ ãããå ´åã¯æ³¨æãå¿ è¦ã§ãã
KivyLauncherã¨SL4A+Py4Aã®æ¯è¼ - Kivy Advent Calendar 2013
ãã¦ä»åKivyLauncherãããããã¨ããã£ã¦ãã¾ãããã2å¹´åã¯SL4A+Py4Aãããããã¨è©¦ãã¦ãã¾ããã
- http://d.hatena.ne.jp/cheeseshop/20110326
- http://d.hatena.ne.jp/cheeseshop/20110226
- http://d.hatena.ne.jp/cheeseshop/20110225
ã¨ãªãã¨ããã®2ã¤ã¯ã©ãéãã®ãæ°ã«ãªãã¨ããããããã¾ããã
KivyLauncherã¯ãã¾ãSDLãOpenGLãçµã¿åããã¦ãã«ãã¡ãã£ã¢ç°å¢ãä½ã£ã¦ããPythonãèµ·åãã¾ããã¾ããã«ãã¡ãã£ã¢ç°å¢ã¨ãã£ã¦ããAndroidã®SurfaceViewã¨SDLé¢é£ã®ã¯ã©ã¹ããã£ã¤ãã¦ãAndroidã®ãµã¼ãã¹ããã°ã©ã ã¨ãã¦åãããã«ãããã®ã§ããUnityã¿ãããªã²ã¼ã ã¨ã³ã¸ã³ã«æ¯ã¹ãã°è²§å¼±ã§ããã§ããæä½éãã¬ã¼ã (ç»é¢)ã¨ãµã¦ã³ãã¨ã¿ããããã«å
¥åã«ã¢ã¯ã»ã¹ã§ããã°ããã¨ããçºæ³ã§ãã®ã§ãã©ã¤ãã©ãªæ¬¡ç¬¬ã§ã©ã®ãããªUIã§ãçµã¿ç«ã¦ããã¾ãã
èµ·åãããPythonããã¯Androidã®APIã§ã¯ãªãããã®ãã«ãã¡ãã£ã¢ç°å¢ã«ã¢ã¯ã»ã¹ãã¾ããKivyã®ã©ã¤ãã©ãªã¯ãã®ä¸ã§ã¦ã£ã¸ã§ããã®æç»ãã¯ããã¯ãã¿ããã¤ãã³ãã®ç®¡çãè¡ããã¨ã§ã¢ãã¡ã¼ã·ã§ã³ãã¤ã³ã¿ã©ã¯ã·ã§ã³ãå®ç¾ããã¦ãã¾ãã
Windowsã»MacOSXã»iOSä¸ã®Kivyã®å ´åã (å®è£
ã¯DirectXã ã£ããããããéãã®ã§ãã) åããã«ãã¡ãã£ã¢ç°å¢ãä½ãããã®ä¸ã§ã¦ã£ã¸ã§ããæç»ãã¤ãã³ã管çãè¡ãã®ã§ããã¼ãã¦ã§ã¢ã®éãï¼ã«ã¡ã©ãGPSãå é度ã»ã³ãµï¼ãé¿ããã¨ããæ¡ä»¶ã§ããã°ããã«ããã©ãããã©ã¼ã ã®ã¢ããªã±ã¼ã·ã§ã³ãä½ããã¨ãå¯è½ãªããã§ãã
SL4Aã§ã®ããã°ã©ãã³ã°ã®ã¢ããã¼ãã¯ãããã¨ã¯å¯¾ç
§çãªãã®ã«ãªãã¾ãã
SL4Aããèµ·åãããPythonã¯ãSL4Aãçµç±ãã¦Android APIã«ã¢ã¯ã»ã¹ãã¦æç»ããã¼ãã¦ã§ã¢æä½ãå©ç¨ã§ããå½¢ã«ãªã£ã¦ãã¾ããSL4Aã¯Androidã¨å¯æ¥ã«é£æºãã¦ãã¦ãæç»ãAndroidæ¬æ¥ã®ã¬ã¤ã¢ã¦ãã¨ã³ã¸ã³ã使ããã¨ã«ãªãã¾ããSL4Aã¯ããã°ã©ãã³ã°è¨èªã¨ãã¦PythonãJrubyãPHPãªã©ã使ãã¾ãããåãååã®APIãå¼ã³åºãã®ã§ãè¦ãç®ã¯Javaã§Androidããã°ã©ãã³ã°ããã®ã«è¿ãå½¢ã«ãªãã¾ãã
ãã«ããã©ãããã©ã¼ã ãæèããã®ã§ããã°Kivyããé¸æè¢ã¯ããã¾ãããããããAndroidã ãã§åãã°ãããããã°ã©ã ã§ããã°Kivyã§æ¸ããSL4Aã§æ¸ããè¿·ãã¨ããããããã¾ããã
SL4Aã¯ãããããAndroidã¢ããªãJavaã§éçºããçµé¨ãããã°æ©ã馴æãã¨æãã¾ããã¾ãWebViewãã¼ã¹ã®ã¢ããªã±ã¼ã·ã§ã³ãä½ãå ´åã¯SL4Aãé¸æãããã¨ã«ãªãã¾ãã
ä¸æ¹Kivyã¯ããã¾ã§ã®Androidããã°ã©ãã³ã°ã¨ã¯ç°ãªãå½¢æ
ãªã®ã§ãJavaã«ããéçºçµé¨ããªãæ¹ãåãã¦ããã¨æãã¾ããã²ã¼ã ããã°ã©ãã³ã°ãçµã¿è¾¼ã¿ã®Linux端æ«ãçµé¨ãã人ã¯ãKivyã®æ¹ã馴æãããããã¾ããã
ãã¨ãKivyLauncherã¨SL4A+Py4Aã®ããã«åããéãã¨ãã¦ãAndroidã¢ããªã®ãã¼ããã·ã§ã³ãããã¾ããKivyLauncherã¯USBã¹ãã¬ã¼ã¸ããããã¯ã¼ã¯ãBluetoothç¨åº¦ããè¦æ±ãã¦ãã¾ããããSL4Aã¯Android APIã®å¤§åã網ç¾
ãã¦ãããããé£çµ¡å¸³ã ã®SMSã ã®é話ã ã®ãããã¨ãããããã¼ããã·ã§ã³ãè¦æ±ãã¦ãã¾ãã
ãããã«ãããªSL4Aããã¤ã³ã¹ãã¼ã«ãã¦ãã ãããã¨ã客ããã«ãé¡ãããã®ã¯é£ããã®ã§ãæä½éã®ãã¼ããã·ã§ã³ã§APKããã±ã¼ã¸ãä½ã£ã¦æ¸¡ããããªãã§ããããããSL4AãGoogle Playã§å
¬éã§ããªãã®ãããã®ãã¼ããã·ã§ã³ãå½±é¿ãã¦ããã¨æãã¾ãã
ä¸æ¹ã®KivyLauncherã¯Google Playããã¤ã³ã¹ãã¼ã«å¯è½ã«ãªã£ã¦ãã¾ããã¾ã 試ãã¦ã¯ãã¾ããããKivyLauncherã§pyjniusã使ã£ã¦GPSæ
å ±ãåå¾ããã¢ããªãä½ã£ãããGPSé¢é£ã®ãã¼ããã·ã§ã³ãã¤ããããã«ãã«ããç´ãå¿
è¦ãããã§ãããã
RPG風ã«ãã£ã©ã¯ã¿ãåãã - Kivy Advent Calendar 2013
Animationãªãã¸ã§ã¯ãã®å®é¨ã§ãããç¡é§ã«ã²ã¼ã æ©ã£ã½ãã¤ã³ã¿ãã§ã¼ã¹ã«ãã¦ã¿ã¾ããã
ã§ãA/B/X/Yãã¼ã¯ããã¼ã§ããåãã®ã¯ä¸ä¸å·¦å³ãã¼ã ãã
ã¨ã©ã¼ãã§ãã¯ä½ããã¦ã¾ããã®ã§ãå¹³æ°ã§ç»é¢å¤ã¸åºã¦è¡ã£ã¡ããã¾ã...
ã
â»spellyonããã®ãµã¤ããç¹çéç©ãããç´ æããåããã¦ãã¾ã (http://dispell.net/)
(/sdcard/kivy/thrpg/)
android.txt | ãç´æ |
main.py | ã¹ã¯ãªããæ¬ä½ |
th7_remari.png | é夢ã¨éçæ²ã®24x32ãããã£ã©ãã¡ã¤ã«(èæ¯ãééå) |
chara.atlas | ä¸ã®ç»åã«ç´ä»ããatlasãã¡ã¤ã« é夢ã®ãã¼ã¿ãã使ã£ã¦ã¾ãã... |
(android.txt)
title=thrpg author=cheeseshop orientation=landscape
(chara.atlas)
{ "th7_remari.png": { "N0": [ 24, 224, 24, 32], "N1": [ 0, 224, 24, 32], "N2": [ 24, 224, 24, 32], "N3": [ 48, 224, 24, 32], "E0": [ 24, 192, 24, 32], "E1": [ 0, 192, 24, 32], "E2": [ 24, 192, 24, 32], "E3": [ 48, 192, 24, 32], "S0": [ 24, 160, 24, 32], "S1": [ 0, 160, 24, 32], "S2": [ 24, 160, 24, 32], "S3": [ 48, 160, 24, 32], "W0": [ 24, 128, 24, 32], "W1": [ 0, 128, 24, 32], "W2": [ 24, 128, 24, 32], "W3": [ 48, 128, 24, 32] } }
(main.py)
from kivy.app import App from kivy.animation import Animation from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.image import Image from kivy.uix.boxlayout import BoxLayout from kivy.uix.relativelayout import RelativeLayout from itertools import cycle from kivy.lang import Builder Builder.load_string('''\: orientation: 'vertical' Label: size_hint_y: 3./8. GridLayout: size_hint_y: 2./8. rows: 3 Label: Button: id: btn_N text: '^' on_press: app.move('N') Label: Button: id: btn_W text: '<' on_press: app.move('W') Label: Button: id: btn_E text: '>' on_press: app.move('E') Label: Button: id: btn_S text: 'v' on_press: app.move('S') Label: Label: size_hint_y: 3./8. : orientation: 'vertical' Label: size_hint_y: 3./8. GridLayout: size_hint_y: 2./8. rows: 3 Label: Button: text: 'X' Label: Button: text: 'Y' Label: Button: text: 'A' Label: Button: text: 'B' Label: Label: size_hint_y: 3./8. : game: _game orientation: 'horizontal' ControlPad: size_hint_x: 1./8. Game: id: _game size_hint_x: 6./8. ActionPad: size_hint_x: 1./8. : canvas: Color: rgb: (.25, .50, .25) Rectangle: size: self.size pos: (0, 0) : drct: 'E' source: 'atlas://chara/E0' allow_stretch: True size: (192, 256) size_hint: (None, None) ''') class Root(BoxLayout): pass class ControlPad(BoxLayout): pass class ActionPad(BoxLayout): pass class Game(RelativeLayout): pass class Character(Image): pass class GameApp(App): def cycle(self, iter=cycle(list('0123'))): return iter.next() def reload(self, anim, ch, progress): ch.source = 'atlas://chara/%s%s' % (ch.drct,self.cycle()) ch.reload() def clear(self, anim, ch): self.moving = False def move(self, drct, *args): if self.moving: return False self.moving = True self.anim = Animation( d=1./1., s=1./8., t='linear', x=self.ch.x+(drct=='E')*192-(drct=='W')*192, y=self.ch.y+(drct=='N')*256-(drct=='S')*256) self.ch.drct = drct self.anim.bind(on_progress=self.reload) self.anim.bind(on_complete=self.clear) self.anim.start(self.ch) return False def build(self): root = Root() self.moving = False self.ch = Character() self.ch.pos = (0, 0) self.ch.drct = 'S' root.game.add_widget(self.ch) return root if __name__ == '__main__': GameApp().run()
解説
Kivyã®ã¢ãã¡ã¼ã·ã§ã³æ©è½
Animationãªãã¸ã§ã¯ãã¯ãæç»ã¿ã¤ãã³ã°ã«ãããã¦ã¦ã£ã¸ã§ããã®ãµã¤ãºãä½ç½®ã¨ãã£ãããããã£ãé次å¤æ´ãã¦ããã¨ãããã®ã§ãã
å¼æ°ã«ã¯æ¬¡ã®ãããªãã®ãæå®ãã¦ã¤ã³ã¹ã¿ã³ã¹ãçæãã¾ãã
- ãµã¤ãºãä½ç½®ã®æçµå¤ (x, y, pos, size)
- æç»ã¿ã¤ãã³ã° (d:ã¢ãã¡ã¼ã·ã§ã³ã®æéãs:æç»éé)
- ãã©ã³ã¸ã·ã§ã³é¢æ° (t:æååã¾ãã¯3ã¤ã®å¼æ°[åæå¤,æçµå¤,0ã1ã®å¤]ãåãé¢æ°)
ãã®å¾ start(widget) ã¡ã½ããã§ãå¼æ°ã«æå®ããã¦ã£ã¸ã§ããã®ç§»åãéå§ãã¾ãã
æ©è¡ã¢ãã¡ã¼ã·ã§ã³
Animationãªãã¸ã§ã¯ãã¯ãããã¾ã§ã¦ã£ã¸ã§ããã®ãæ°å¤ã®ãããããã£ãé 次å¤æ´ãããã®ã§ãã
é¢æ°ããã¾ã使ãã°ç»åãå¤æ´ããã®ãå¯è½ããããã¾ããããã¡ãã£ã¨é¢åãªã®ã§å¥ã®æ¹æ³ãåããã¨ã«ãã¾ããã
ãã®ãµã³ãã«ã§ã¯ãæç»ã¿ã¤ãã³ã°ã§ãon_progressã¤ãã³ããçºçããããã¨ãå©ç¨ãã¦ãã¾ããon_progressã§å¼ã³åºããã³ãã©ã®ç¬¬2å¼æ°ã«ã¯ç§»åä¸ã®ã¦ã£ã¸ã§ãããå
¥ãã®ã§ãããã§åãåãã®ãã£ã©ã¯ã¿ç»å (3ãã¿ã¼ã³) ãé 次å
¥ãæ¿ãã¦æ©è¡ã®ã¢ãã¡ã¼ã·ã§ã³ãå®ç¾ãã¦ãã¾ãã
æä»å¦ç
ã¢ãã¡ã¼ã·ã§ã³ã¯ããã°ã©ã ããããã¯ãã並è¡ã«èµ°ãã®ã§ãåä½ä¸ã«å¥ã®ç§»åãã¿ã³ãåãä»ãã¦ãã¾ãå¯è½æ§ãããã¾ãããã®ãµã³ãã«ã§ã¯ãã²ã¨ã¤ã®ç§»åãçµãã£ã¦ãã次ã®ãã¼ãåãä»ããããã«ããããã®ã§ã移åãçµãã£ãã¨ãã®on_completeã¤ãã³ãã¨ãã©ã° (moving) ã使ã£ã¦æä»å¶å¾¡ããã¦ãã¾ãã
ãã¼æä½ããªãã¼ãããªã
ã²ã¼ã ãã¼ããããã©ãã¯on_pressã使ã£ã¦ããã®ã§ããã®é½åº¦é¢ãã¦æ¼ãã¦ãç¹°ãè¿ããªãã¨ãããªãã§ãããã®ä»¶ã«ã¤ãã¦ã¯å¾ã§è§£æ±ºçãæ¢ãã¦ã¿ã¾ã...
ï¼ãã¶ãon_touch_downã使ãã°ãããã§ãããããæ¬å½ã«ãã®ãã¿ã³ãæ¼ããããcollide_pointã§ãã§ãã¯ããå¿
è¦ãããã¾ãï¼