Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello ā I'm @olemoritz on Twitter.
[SOLVED!] Help with text colour (scene)
-
It's completely finished!!!
However, in the last scene (restart scene) the text if for some reason black. Could you please help me make it white?Thanks in advance!
Here's the code:
<pre><code>
#coding: utf-8
from scene import *
from random import *
import time
import sys
class Particle(object):
def init(self, wh):
self.w = wh.w
self.h = wh.h
self.x = randint(0, self.w)
self.y = randint(0, self.h)
self.vx = randint(-10, 20)
self.vy = randint(-10, 20)
self.colour = Color(random(), random(), random())def update(self): self.x += self.vx self.y += self.vy self.vx *= 0.98 self.vy *= 0.98 if self.x > self.w: self.x = self.w self.vx *= -1 if self.x < 0: self.x = 0 self.vx *= -1 if self.y > self.h: self.y = self.h self.vy *= -1 if self.y < 0: self.y = 0 self.vy *= -1 def draw(self): fill(*self.colour) rect(self.x, self.y, 8, 8)
class Intro(Scene):
def setup(self):
self.particles = []
for p in xrange(200):
self.particles.append(Particle(self.size))
def draw(self):
background(0.00, 0.05, 0.20)
for p in self.particles:
p.update()
p.draw()
for t in self.touches.values():
for p in self.particles:
tx, ty = t.location.x, t.location.y
d = (p.x - tx)(p.x - tx)+(p.y - ty)(p.y - ty)
d = sqrt(d)
p.vx = p.vx - 5/d*(p.x-tx)
p.vy = p.vy - 5/d*(p.y-ty)
p.colour = Color(random(), random(), random())s = 47 if self.size.w > 100 else 7 text('Welcome to\n Jitter Tap\n\n\n', 'Futura', s, *self.bounds.center().as_tuple()) t = 100 if self.size.w > 100 else 7 text('\nš“', 'Futura', t, *self.bounds.center().as_tuple()) s = 27 if self.size.w > 100 else 7 text('\n\n\n\n\n\n\n\n\n\n\n\nBy: Adedayo Ogunnoiki', 'Futura', s, *self.bounds.center().as_tuple()) def touch_ended(self, touch): run(Help1())
import motion, scene
use_motion = Trueclass Help1(Scene):
def setup(self):
self.particles = []
for p in xrange(200):
self.particles.append(Particle(self.size))def draw(self): background(0.00, 0.05, 0.20) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random()) s = 35 if self.size.w > 100 else 7 text('You will have to\nclick the button\na 100 times as\nquickly as possible.\nThen your time\nand the speed\nat which you\nwere clicking will\nbe displayed.', 'Futura', s, *self.bounds.center().as_tuple()) def touch_ended(self, touch): run(Help2())
class Help2(Scene):
def setup(self):
self.particles = []
for p in xrange(200):
self.particles.append(Particle(self.size))def draw(self): background(0.00, 0.05, 0.20) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random()) s = 45 if self.size.w > 100 else 7 text('Also, you can\nclick the ā\nat the top\nright of the\nscreen to exit.', 'Futura', s, *self.bounds.center().as_tuple()) def touch_ended(self, touch): run(JitterClick())
import time
from scene import *
from PIL import Image
class JitterClick(Scene):
def init(self):
self.start_time = 0
self.finish_time = 0
self.clicks = 0def setup(self): self.button = Button(Rect(self.size.w/2-100, self.size.h/2-140, 200, 200)) self.button.background = Color(0,0.05,0.2) self.button.stroke = Color(0,0.05,0.2) self.button.image = 'Red_Circle' self.button.action = self.add_clicks self.add_layer(self.button) self.particles = [] for p in xrange(200): self.particles.append(Particle(self.size)) def add_clicks( self): self.clicks += 1 if self.clicks == 1: self.start_time = time.time() def draw(self): background(0,0.05,0.2) self.button.background = Color(0,0.05,0.2) self.button.draw() text('Taps: %i' % self.clicks, x=self.size.w/2, y=self.size.h/3.8*3, font_size=57) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random()) if self.clicks == 100: self.finish_time = time.time() run(desp(self.clicks, self.finish_time - self.start_time))
class desp(Scene):
def init(self, xclicks, duration):
self.xclicks = xclicks
self.duration = duration
self.duration = "%.3f" % self.duration
self.speed = duration/xclicks
self.speed = "%.3f" % self.speeddef setup(self): self.show_instructions = True self.p_size = 64 if self.size.w > 700 else 32 self.particles = [] for p in xrange(200): self.particles.append(Particle(self.size)) def draw(self): background(0, 0.05, 0.2) text('\n\n\n\n\n\nIt took you \n{} seconds \nto tap {} \ntimes. You were\ntapping at \n{} taps a\nsecond.'.format(self.duration, self.xclicks, self.speed), x=self.size.w/2, y=self.size.h/3.8*3, font_size=42) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random()) def touch_ended(self, touch): run(restart())
class restart(Scene):
def setup(self):
self.button = Button(Rect(self.size.w/2-80, self.size.h/2--45, 150, 150), 'Restart')
self.button.background = Color(0,0.05,0.2)
self.button.stroke = Color(0,0.05,0.2)
self.button.image = 'Blue_Circle'
self.button.action = self.add_clicks
self.add_layer(self.button)
self.particles = []
for p in xrange(200):
self.particles.append(Particle(self.size))def add_clicks( sender): run(JitterClick()) def draw(self): background(0,0.05,0.2) self.button.background = Color(0,0.05,0.2) self.button.draw() s = 45 if self.size.w > 100 else 7 text('\n\n\nOr you can\nclick the ā\nat the top\nright of the\nscreen to exit.', 'Futura', s, *self.bounds.center().as_tuple()) for p in self.particles: p.update() p.draw() for t in self.touches.values(): for p in self.particles: tx, ty = t.location.x, t.location.y d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty) d = sqrt(d) p.vx = p.vx - 5/d*(p.x-tx) p.vy = p.vy - 5/d*(p.y-ty) p.colour = Color(random(), random(), random())
run(Intro())
</code></pre> -
http://omz-software.com/pythonista/docs/ios/scene.html#scene.text spells it out pretty clearly
-
Yes, was also just about to post. tint(255,255,255) just before you draw the text()
-
I love the particle effects. Really nice. I tried to modify omz example once. With no luck :). It's way beyond me.
But I was thinking of using a Scene to run before my ui app run. As a splash screen. I was trying to go for an effect similar to the apple watch start up. Have the name of my app zoom into the Center and then a line of text on the bottom, maybe my name, email address etc. I don't want the scene to take over the whole screen if possible. Also would like to be able to specify how long the scene stayed on the screen or if it is dismissed with a button click.With your skills, it would appear it wouldn't be that hard for you to write something like that. If you used some constants for the strings etc... Up the top of the file, could be a great community tool. Also, if you could wrap up particle animation part of the code so you or others could write different animations to plug into the class.
Just a thought. Could be a good learning exercise :)
BTW, I am just guessing you can run a scene(), exit it, then run a ui app. If you do decide to do something like this, I will help anyway I can, but my skills are very limited.
-
At first I had no idea what you were saying. However, I read through it a couple times and I would have no problem helping.
I just got an idea as I'm typing this right now.
(Tell me if it's not explicit enough)
So, using the same (add_layer) etc. in the jitter click scene, you could do so after each 0.1 seconds it will re-run your scene with your text a bit larger and with the if function you could make it stop when you think it's a reasonable size. Then run whatever app you would. Lastly you add:
<pre><code>
def touch_ended(self, touch):
</code></pre>
And it could run your app when the screen is clicked.Tell me if my concept is what you're looking for :)
And btw I'm not really that skilled, it took me like 2.5 days to make this, where someone could make it in half a day. Not to mention I got help from you @OMZ @CCC and other people I might have forgotten to mention :P
-
self.particles = [] for p in xrange(200): self.particles.append(Particle(self.size)) # ...could be rewritten as a one liner... self.particles = [Particle(self.size) for i in xrange(200)]
-
I am just guessing you can run a scene(), exit it, then run a ui app.
See
SceneViewer.py
which leveragesscene.SceneView
to run a scene.Scene inside a ui.View. Best of both worlds. -
Thanks guys. 777, I will look a little further at the documentation and write back
-
Ok, Goodluck!
-
Thanks 777. Ccc, I downloaded the SceneViewer.py. It's great. It answered one simple question for me straight away, being that you can run a scene without taking over the screen. In the init, it does a present, I just passed 'sheet' to it and worked, also tried 'popover' also worked.
But, it's almost there I think. But maybe miles also. So that a splash screen like this could be called once at the bringing of the program and forgotten about thereafter, I don't want to mix my code in with it. Would like to have a my_splash_screen.py with a single call, then it stays on the screen modally until,dismissed or a duration. The below code works :) YEAH!
Well, it doesn't because I am blocking the main thread I think. I am using wait_modal. But, I can screw around as much as I like, I just don't understand it enough. Maybe what I want is not possible. It seems to me it should be, but just takes someone who understands it. Anyway, I think if this could be overcome, could add some very interesting possibilities to add some pizazz to the ui apps. Anyone, help from anywhere would be great......# See; https://omz-forums.appspot.com/pythonista/post/5290516186923008 import scene, ui class MyScene(scene.Scene): def draw(self): scene.background(0, 0, 0) scene.fill(1, 0, 0) for touch in self.touches.values(): x, y = touch.location scene.ellipse(x - 50, y - 50, 100, 100) class SceneViewer(ui.View): def __init__(self, in_scene): self.present('sheet', hide_title_bar = True) scene_view = scene.SceneView(frame=self.frame) scene_view.scene = in_scene() self.add_subview(scene_view) self.add_subview(self.close_button()) def close_action(self, sender): print('Closing...') self.close() def close_button(self): the_button = ui.Button(title='X') the_button.x = self.width - the_button.width the_button.y = the_button.height / 2 the_button.action = self.close_action the_button.font=('<system-bold>', 20) return the_button #scene.run(MyScene) sv = SceneViewer(MyScene) sv.wait_modal() v = ui.View() v.present('sheet')