Skip to content

Commit

Permalink
Add shadow Font and FixedString demos (tests really) to Shapes and Fi…
Browse files Browse the repository at this point in the history
…xedString
  • Loading branch information
paddywwoof committed Feb 9, 2017
1 parent d576026 commit 4a0b125
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
18 changes: 13 additions & 5 deletions FixedString.py
Expand Up @@ -24,10 +24,17 @@
It enables both 3D and 2D
rendering and aims to provide
a host of exciting commands.'''

str1 = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext, font_size=32, background_color=(200,140,20,235),
camera=CAMERA2D, shader=flatsh, f_type='SMOOTH')
str1.sprite.positionX(-300) #NB note Shape methods act on FixedString.sprite
# 'normal' FixedString on a (fairly) solid background
str1 = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext, font_size=32,
background_color=(200,140,20,235),
camera=CAMERA2D, shader=flatsh, f_type='SMOOTH')
str1.sprite.position(-300, 0, 2) #NB note Shape methods act on FixedString.sprite
# shadow outline FixedString to show up against light or dark backgrounds
# try setting shadow_radius to 0 to see what the issue is
str1a = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext[:53], font_size=48,
color=(70, 70, 180, 255), background_color=None, shadow_radius=1,
camera=CAMERA2D, shader=flatsh, f_type='SMOOTH')
str1a.sprite.position(50, -150, 1) #NB note Shape methods act on FixedString.sprite

str2 = pi3d.FixedString('fonts/NotoSerif-Regular.ttf', mytext, font_size=24, f_type='BUMP')
mycuboid = pi3d.Cuboid(camera=CAMERA, z=2, x=0.5)
Expand All @@ -41,7 +48,8 @@
while DISPLAY.loop_running():
str1.draw()
mycuboid.draw()
mycuboid.rotateIncZ(0.05)
str1a.draw()
mycuboid.rotateIncX(0.091)
mycuboid.rotateIncY(0.13)
if mykeys.read() == 27:
mykeys.close()
Expand Down
34 changes: 28 additions & 6 deletions Shapes.py
Expand Up @@ -62,14 +62,30 @@
myhemisphere = pi3d.Sphere(radius=1, sides=24, slices=24, hemi=0.5, name="hsphere",
x=4, y=-1, z=10)
myPlane = pi3d.Plane(w=4, h=4, name="plane", z=12)
# Load ttf font and set the font colour to 'raspberry'
arialFont = pi3d.Font("fonts/NotoSerif-Regular.ttf", (221,0,170,255))
mystring = pi3d.String(font=arialFont, string="Now the Raspberry Pi really does rock", z=4)
mystring.set_shader(flatsh)

# Use three ttfs fonts one with the colour 'raspberry', one with background
# colour and one using a contrasting shadow
txt = "Now the Raspberry Pi really does rock"
strings = [pi3d.String(
font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (221, 0, 170, 255)),
string=txt, z=4),
pi3d.String(
font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (0, 0, 26, 255)),
string=txt, z=4),
pi3d.String(
font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (0, 0, 26, 255),
shadow=(200, 255, 0, 255), shadow_radius=1),
string=txt, z=4)]

for s in strings:
s.set_shader(flatsh)

# Fetch key presses
mykeys = pi3d.Keyboard()

angl = 0.0
i_f = 0
i_s = 0
# Display scene
while DISPLAY.loop_running():

Expand Down Expand Up @@ -118,8 +134,14 @@
mylathe.rotateIncZ(0.4)
mylathe.rotateIncX(0.11)

mystring.draw()
mystring.rotateIncZ(0.5)
strings[i_s].draw()
for s in strings:
s.rotateIncZ(0.5)

i_f += 1
if i_f > 150:
i_f = 0
i_s = (i_s + 1) % 3

k = mykeys.read()
if k >-1:
Expand Down

0 comments on commit 4a0b125

Please sign in to comment.