Pippy sliderule
Sliderule for Pippy on Sugar
Use arrow keys to move upper scale
Challenges:
Create more markings at useful intervals
Create alternate scales, CI, A, K, S, T, LL, Ln
Add a cursor
Mouse input
Circular sliderule
Replicate all the features at http://wiki.sugarlabs.org/go/Activities/Sliderule
source
Note blog messes up indenting
# sliderule
import pippy, pygame, sys
from pygame.locals import *
import math
# always need to init first thing
pygame.init()
# create the window and keep track of the surface
# for drawing into
screen = pygame.display.set_mode()
# turn off the cursor
pygame.mouse.set_visible(False)
color = (0, 0, 0)
bgcolor = (250,250,250)
rdisp = 0
def drawnum(posx, posy, num):
fsize = 25
msg = str(num)
font = pygame.font.Font(None, fsize)
text = font.render(msg, True, color)
textRect = text.get_rect()
textRect.centerx = posx
textRect.centery = posy
screen.blit(text, textRect)
def drawbox(rightdisp,downdisp,markdisp):
pygame.draw.line(screen, color, (rightdisp+100, downdisp), (rightdisp+800, downdisp))
pygame.draw.line(screen, color, (rightdisp+800, downdisp), (rightdisp+800, downdisp+100))
pygame.draw.line(screen, color, (rightdisp+800, downdisp+100), (rightdisp+100, downdisp+100))
pygame.draw.line(screen, color, (rightdisp+100, downdisp+100), (rightdisp+100, downdisp))
for i in range (1,10):
pygame.draw.line(screen, color, (rightdisp+700*math.log10(i)+100, downdisp+markdisp), (rightdisp+700*math.log10(i)+100, downdisp+markdisp+20))
drawnum(rightdisp+700*math.log10(i)+100,downdisp+50,i)
pygame.display.flip()
def draw2box():
screen.fill(bgcolor)
drawbox(rdisp,100,80)
drawbox(0,200,0)
draw2box()
# events
while pippy.pygame.next_frame():
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
elif event.key == 275:
rdisp += 10
draw2box()
elif event.key == 276:
rdisp -= 10
draw2box()
Use arrow keys to move upper scale
Challenges:
Create more markings at useful intervals
Create alternate scales, CI, A, K, S, T, LL, Ln
Add a cursor
Mouse input
Circular sliderule
Replicate all the features at http://wiki.sugarlabs.org/go/Activities/Sliderule
source
Note blog messes up indenting
# sliderule
import pippy, pygame, sys
from pygame.locals import *
import math
# always need to init first thing
pygame.init()
# create the window and keep track of the surface
# for drawing into
screen = pygame.display.set_mode()
# turn off the cursor
pygame.mouse.set_visible(False)
color = (0, 0, 0)
bgcolor = (250,250,250)
rdisp = 0
def drawnum(posx, posy, num):
fsize = 25
msg = str(num)
font = pygame.font.Font(None, fsize)
text = font.render(msg, True, color)
textRect = text.get_rect()
textRect.centerx = posx
textRect.centery = posy
screen.blit(text, textRect)
def drawbox(rightdisp,downdisp,markdisp):
pygame.draw.line(screen, color, (rightdisp+100, downdisp), (rightdisp+800, downdisp))
pygame.draw.line(screen, color, (rightdisp+800, downdisp), (rightdisp+800, downdisp+100))
pygame.draw.line(screen, color, (rightdisp+800, downdisp+100), (rightdisp+100, downdisp+100))
pygame.draw.line(screen, color, (rightdisp+100, downdisp+100), (rightdisp+100, downdisp))
for i in range (1,10):
pygame.draw.line(screen, color, (rightdisp+700*math.log10(i)+100, downdisp+markdisp), (rightdisp+700*math.log10(i)+100, downdisp+markdisp+20))
drawnum(rightdisp+700*math.log10(i)+100,downdisp+50,i)
pygame.display.flip()
def draw2box():
screen.fill(bgcolor)
drawbox(rdisp,100,80)
drawbox(0,200,0)
draw2box()
# events
while pippy.pygame.next_frame():
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
elif event.key == 275:
rdisp += 10
draw2box()
elif event.key == 276:
rdisp -= 10
draw2box()
0 Comments:
Post a Comment
<< Home