-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (61 loc) · 2.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Import a library of functions called 'pygame'
import pygame
import math
import random
import tentacle
def vector_subtract(a,b):
return [a[0]-b[0],a[1]-b[1]]
def sign(x):
if x>0:
return 1
elif x<0:
return -1
else:
return 0
def vector_sign(a):
return [sign(a[0]),sign(a[1])]
# Initialize the game engine
pygame.init()
# Define the colors we will use in RGB format
BLACK = ( 0, 0, 0)
# Set the height and width of the screen
size = [1000,1000]
screen = pygame.display.set_mode(size)
#Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()
tentacles = []
roots = []
number_of_tentacles = 1
for tentaclee in range(number_of_tentacles):
color = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
tentacle_length = random.randint(1000,1000)
number_of_segments = 10
width_range = [int(tentacle_length/30),int(tentacle_length/20)]
tentacles.append(tentacle.tentacle(number_of_segments=number_of_segments,tentacle_length=tentacle_length,width_range=width_range,color=color))
roots.append([random.randint(0,size[0]),random.randint(0,size[1])])
# field_force = [0,20]
while not done:
clock.tick(60)
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
mouse = list(pygame.mouse.get_pos())
# Clear the screen and set the screen background
screen.fill(BLACK)
#update angle of segments
for index,tentaclee in enumerate(tentacles):
# tentaclee.update_angle(range_of_angle=1)
# tentaclee.wiggle(wiggle_range)
tentaclee.follow(mouse)
tentaclee.pin(roots[index])
# tentaclee.shift(field_force)
# tentaclee.gravity(field_force)
# Draw the screen elements
for tentaclee in tentacles:
if not tentaclee.is_straigth(intolerance=1):
tentaclee.draw(screen)
#update screen
pygame.display.flip()
# Be IDLE friendly
pygame.quit()