sajjads programming blog

publish my programming stuffs on web

Tuesday, August 08, 2006

refractive index


# this program is developed under space (www.space_kerala.org) project # developed by sajjad( csajjad@gmail.com) , vibeesh(pvibeesh@gmail.com) George john #

import pygame
import math
import pygame.font
from pygame.locals import *
u=0
r_index=1.33
emitter_y=20
value=200
color=(255,255,255)
deviation=0
screen=pygame.display.set_mode((700,610))

river=pygame.image.load("river.jpeg")
def colorchooser():
pygame.draw.rect(screen,(255,255,255),(20,20,20,20),0)
pygame.draw.rect(screen,(255,0,0),(20,60,20,20),0)
pygame.draw.rect(screen,(0,255,0),(20,100,20,20),0)
pygame.draw.rect(screen,(0,0,255),(20,140,20,20),0)
def prntrindex():
string='n2='+str(r_index)
text_d1 = font.render(string,1, (255,255,255))
textpos_d1 = ((600,80,48,24))
screen.blit(text_d1,textpos_d1)
def pgbar():
pygame.draw.line(screen,(255,255,0),(650,200),(650,300),5)
pygame.draw.polygon(screen,(255,255,0),((640,175),(660,175),(650,190)) ,0)
pygame.draw.polygon(screen,(255,255,0),((640,325),(660,325),(650,310)) ,0)

i=200
while i<=300: if value==i: pygame.draw.line(screen,(255,255,0),(640,i),(660,i),5) else: pygame.draw.line(screen,(255,255,0),(640,i),(660,i),2) i+=20 def inc_angle(): opposite_side=250 dx=250 dy=400-emitter_y #hypt=sqrt(pow(dx,2)+pow(dy,2)) hypt=pow((pow(dx,2)+pow(dy,2)),.5) angle=math.asin(opposite_side/hypt) degr=math.degrees(angle) string='i='+str(int(degr)) text_d1 = font.render(string,1, (255,255,255)) textpos_d1 = ((600,20,48,24)) screen.blit(text_d1,textpos_d1) return degr def emitter(): inci=inc_angle() refr=inci/r_index string2='r='+str(int(refr)) text_r = font.render(string2,1, (255,255,255)) textpos_r = ((600,50,48,24)) screen.blit(text_r,textpos_r) angle=90-refr rad_angle=math.radians(angle) hyp=210/math.sin(rad_angle) val=pow(hyp,2)-pow(210,2) if color==(255,0,0): deviation=40 elif color==(0,255,0): deviation=20 elif color==(0,0,255): deviation=0 refracted_x=math.sqrt(val) #+350 refracted_x=refracted_x+350 if color==(255,255,255): pygame.draw.line(screen,(255,0,0),(350,400),(refracted_x+40,610),1) pygame.draw.line(screen,(0,255,0),(350,400),(refracted_x+20,610),1) pygame.draw.line(screen,(0,0,255),(350,400),(refracted_x,610),1) else: pygame.draw.line(screen,color,(350,400),(refracted_x+deviation,610),1) def refra(): #x=450-u x=450 if x<380: x="350" font="pygame.font.Font(None,25)" event="pygame.event.wait()" y="pygame.mouse.get_pos()" x="'," y="',y"> 95 and x<105>20 and y<205: emitter_y="y">20 and x<40:>20 and y<40: color="(255,255,255)">60 and y<80: color="(255,0,0)">100 and y<120: color="(0,255,0)">140 and y<160: color="(0,0,255)">640 and x<660>175 and y<190:>2:
r_index=2
if value>300:
value=300
elif x>640 and x<660>310 and y<325:
value-=20
r_index-=.2
if r_index<1:
r_index=1
if value<200:
value=200
#if event.type is KEYDOWN :
#if event.key==K_k:
#u+=20
#elif event.key==K_f:
#u-=20

refra()
prntrindex()
colorchooser()
pygame.display.update()


##################################################

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home