Skip to content

Commit

Permalink
animations
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkguy committed Jan 12, 2024
1 parent 81aa2c1 commit fe2c9ec
Show file tree
Hide file tree
Showing 31 changed files with 2,675 additions and 215 deletions.
92 changes: 92 additions & 0 deletions cg-lab/animation/boat_paddle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
import math
WINDOWSIZE=500
x=0
y=0
radius=70
angle=0
dir=0

def Init():
glClearColor(1.0,1.0,1.0,1.0)
gluOrtho2D(-WINDOWSIZE,WINDOWSIZE,-WINDOWSIZE,WINDOWSIZE)

def body():
glColor3f(1.0,0.0,0.0)
glBegin(GL_POLYGON)
glVertex2f(x-100,y)
glVertex2f(x+100,y)
glVertex2f(x+90,y-40)
glVertex2f(x-90,y-40)
glEnd()

glColor3f(0.0,0.0,0.0)
glBegin(GL_POLYGON)
glVertex(x+10,y+50)
glVertex(x-10,y+50)
glVertex(x-30,y)
glVertex(x+30,y)
glEnd()
glPointSize(10)
glBegin(GL_POINTS)
glVertex2f(x,y+80)
glEnd()

glColor3f(0.1,0.7,1.0)
glBegin(GL_POLYGON)
glVertex2f(-500,-40)
glVertex2f(-500,-500)
glVertex2f(500,-500)
glVertex2f(500,-40)
glEnd()

def hand():
glColor3f(0.0,1.0,0.0)
glLineWidth(5)
glBegin(GL_LINES)
glVertex2f(x,y)
x1=(-70)*math.cos(math.radians(angle))+(-70)*math.sin(math.radians(angle))+x
y1=-(-70)*math.sin(math.radians(angle))+(-70)*math.cos(math.radians(angle))+y
glVertex2f(x1,y1)
glEnd()

def drawBoat():
glClear(GL_COLOR_BUFFER_BIT)
body()
hand()
glutSwapBuffers()

def animate(temp):
global x,y,angle,dir
glutPostRedisplay()
glutTimerFunc(int(1000/60),animate,int(0))
if angle>30:
dir=1
if angle<-90:
dir=0

if(dir==1):
angle=angle-1
else:
angle=angle+1
x=x-1
if x==(-WINDOWSIZE+100):
x=400


def main():
glutInit(sys.argv)
glutInitWindowSize(WINDOWSIZE,WINDOWSIZE)
glutInitWindowPosition(0,0)
glutInitDisplayMode(GLUT_RGBA)
glutCreateWindow("Boat")
glutDisplayFunc(drawBoat)
glutTimerFunc(0,animate,0)
glutIdleFunc(drawBoat)
Init()
glutMainLoop()

main()
76 changes: 76 additions & 0 deletions cg-lab/animation/car-stop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
sys.setrecursionlimit(100000)
WS = 900
x,y=0,0
ps = 5
fillcolor = [1,0,0]

tx,ty=0,0

def getpixel(x,y):
return glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,None)[0][0]

def setpixel(x,y,fillcolor):
glColor3f(*fillcolor)
glPointSize(ps)
glBegin(GL_POINTS)
glVertex2f(x,y)
glEnd()
glFlush()



def flood(x,y,fillcolor,oldcolor):
if all (getpixel(x,y)==oldcolor):
setpixel(x,y,fillcolor)
flood(x+ps,y,fillcolor,oldcolor)
flood(x,y+ps,fillcolor,oldcolor)
flood(x-ps,y,fillcolor,oldcolor)
flood(x,y-ps,fillcolor,oldcolor)




def draw():
glClear(GL_COLOR_BUFFER_BIT)
print("draw func")
glColor3f(0,1,0)
glLineWidth(1)
glBegin(GL_POLYGON)
glVertex2f(100+tx,400+ty)
glVertex2f(300+tx,500+ty)
glVertex2f(550+tx,400+ty)
glVertex2f(550+tx,350+ty)
glVertex2f(150+tx,350+ty)
glEnd()
glFlush()



def animate(temp):
global tx,ty
print("animate func")
glutPostRedisplay()
glutTimerFunc(1000,animate,0)
tx+=10
ty+=0

def click(button,state,x,y):
if button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
flood(x,y,fillcolor,getpixel(x,y))

def main():
glutInit(sys.argv)
glutInitWindowSize(WS,WS)
glutCreateWindow("car stop")
gluOrtho2D(0,WS,0,WS)

glutDisplayFunc(draw)
glutMouseFunc(click)
glutTimerFunc(0,animate,0)
glutMainLoop()

main()
120 changes: 120 additions & 0 deletions cg-lab/animation/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
CAR PROGRAM
ABHINAND D MANOJ
"""
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import math
import sys
import random
from pygame import mixer

mixer.init()
plays=mixer.Sound('audio.mp3')

x=0
y=0
t=0
yr=100
tr=1

def init():
glClearColor(0,0,0,1)
gluOrtho2D(-500,500,-500,500)

def drawcir(q):
glColor3f(0,1,1)
glLineWidth(2)
glBegin(GL_TRIANGLE_FAN)
glVertex2f(q,0)
for i in range(0,361,1):
glVertex2f(q+20*math.cos(math.pi*i/180),20*math.sin(math.pi*i/180))
glEnd()
glColor3f(0,0,0)
glBegin(GL_LINES)
glVertex2f(q+20*math.cos(t)-(0)*math.sin(t),20*math.sin(t)+(0)*math.cos(t))
glVertex2f(q-20*math.cos(t)-(0)*math.sin(t),-20*math.sin(t)+(0)*math.cos(t))
glEnd()
glBegin(GL_LINES)
glVertex2f(q+0*math.cos(t)-(20)*math.sin(t),0+0*math.sin(t)+(20)*math.cos(t))
glVertex2f(q+0*math.cos(t)-(-20)*math.sin(t),0+0*math.sin(t)+(-20)*math.cos(t))
glEnd()

def draw():
global x,y
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1,0,0)
glBegin(GL_QUADS)
glVertex2f(x,y)
glVertex2f(x+200,y)
glVertex2f(x+160,y+40)
glVertex2f(x,y+40)
glEnd()
glBegin(GL_QUADS)
glVertex2f(x+10,y+40)
glVertex2f(x+10,y+80)
glVertex2f(x+155,y+80)
glVertex2f(x+155,y+40)
glEnd()
drawcir(x+25)
drawcir(x+155)
glutSwapBuffers()

def animate(value):
global x,y,t,tr,yr
if tr==1:
if x<500:
x=x+1
else:
x=-500
if t>-math.radians(360):
t-=0.01
else:
t=0.00
elif tr==0:
if x>-500:
x=x-1
else:
x=500
if t<math.radians(360):
t+=0.01
else:
t=0.00
elif tr==-1:
pass
glutPostRedisplay()
glutTimerFunc(yr,animate,yr)

def keyboard(key,x,y):
global tr,yr
key=key.decode()
if key=='f':
tr=1
elif key=='b':
tr=0
elif key=='w':
if yr!=0:
yr-=5
elif key=='s':
yr+=10
if yr==200:
tr=-1
elif key=='h':
plays.play()

def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500,500)
glutInitWindowPosition(600,0)
glutCreateWindow("CAR")
glutDisplayFunc(lambda : draw())
glutTimerFunc(0,animate,0)
glutKeyboardFunc(keyboard)
init()
glutMainLoop()
main()

Loading

0 comments on commit fe2c9ec

Please sign in to comment.