-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
1090 lines (826 loc) · 49.6 KB
/
gui.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pygame
import pygame.gfxdraw
import math
import random
import wfca
import json
import threading
#=- Alphabetically ordered helper functions -=#
def add_vec(vec1,vec2):
return [ai + vec2[i] for i,ai in enumerate(vec1)]
def int_vec(vec):
return [int(v) for v in vec]
def generate_elipsoid(position,angle,radius,harmonics,tick):
excentricity = 1+ generate_excentricity(angle,harmonics,tick)
x = position[0]+math.cos(angle)*radius*excentricity
y = position[1]+math.sin(angle)*radius*excentricity
return [x,y]
def generate_excentricity(angle,harmonics,tick):
return sum([harmonic[1]*math.cos(harmonic[3]+tick/harmonic[2] + harmonic[0]*angle) for harmonic in harmonics])
def get_mouse_angle(position):
return math.atan2(-(position[1]-pygame.mouse.get_pos()[1]),-(position[0]-pygame.mouse.get_pos()[0]))
def get_mouse_distance(position):
mouse_pos = pygame.mouse.get_pos()
return math.sqrt((position[0]-mouse_pos[0])**2 + (position[1]-mouse_pos[1])**2)
def process_letter(text,letter,searching):
allowed_letters = "abcdefghijklmnopqrstuvwxyzéèê’ç"
if searching == "gapped": allowed_letters+= "_"
if letter == "backspace":
return text[:-1]
if letter == "space" and text.replace(" ",""):
return text + " "
letter = letter.replace("2","é").replace("7","è").replace("^","ê").replace("8","_").replace("4","’").replace("9","ç")
if letter not in allowed_letters:
return text
return text + letter
def to_rect(x,y,w,h,inted=True):
if inted:
return [int_vec([x+w/2,y+h/2]),int_vec([x+w/2,y-h/2]),int_vec([x-w/2,y-h/2]),int_vec([x-w/2,y+h/2])]
return [[x+w/2,y+h/2],[x+w/2,y-h/2],[x-w/2,y-h/2],[x-w/2,y+h/2]]
#=- GUI and Slide -=#
class GUI():
def __init__(self):
#=- Pygame set up -=#
#===================#
self.screen_width = 1300
self.screen_heigth = int(self.screen_width*9/16)
self.screen = pygame.display.set_mode(( self.screen_width, self.screen_heigth),pygame.RESIZABLE)
pygame.display.set_caption("A collapsed dictionary")
self.running = True
self.clock = pygame.time.Clock()
self.tick = 0
self.floated_tick = 0
pygame.init()
#=- WFCA set up -=#
#=================#
self.corpora = ["Texts/FrenchCorpus.txt","Texts/EnglishCorpus.txt","Texts/LatinCorpus.txt","Texts/SpanishCorpus.txt","Texts/PoemCorpus.txt"]
self.corpora_names = ["French","English","Latin","Spanish","Poem"]
self.word_ends = ["er","ed","us","ar","t"]
self.word_end_index = 0
self.text_index = 0
self.collapsed_text = wfca.CollapsedText()
#=- UX set up -=#
#===============#
self.main_color = (18,22,25)
self.background_color = (234,222,218)
self.fonts = [pygame.font.Font("mirage.otf",int(self.screen_width/12)),pygame.font.Font("mirage.otf",int(self.screen_width/30)),pygame.font.Font("mirage.otf",int(self.screen_width/10))]
self.addons = [self.background_color,self.main_color,self.fonts,self.screen_width]
self.requests = {"change slide":[],"change language":[],"change_words":[],"applying_changes":False}
self.submits = {"key_pressed":[]}
# Create the slides
self.slides = {"main":Slide("main",*self.addons),
"dictionary":Slide("dictionary",*self.addons),
"completion":Slide("completion",*self.addons),
"parameters":Slide("parameters",*self.addons)}
self.current_slide = self.slides["main"]
def run(self):
while self.running:
self.event()
self.update()
self.draw()
def event(self):
self.submits = {"key_pressed":[]}
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
if event.type == pygame.KEYDOWN:
self.submits["key_pressed"].append(pygame.key.name(event.key))
def draw(self):
self.current_slide.draw(self.screen,self.tick)
pygame.display.flip()
def process_requests(self):
if self.requests["change slide"]:
if self.requests["change slide"][0] not in list(self.slides.keys()): return
self.current_slide = self.slides[self.requests["change slide"][0]]
if self.requests["change spaced"]:
x = threading.Thread(target=self.generate_threaded_spaced_words,group=None,daemon=True)
x.start()
if self.requests["change gapped"]:
x = threading.Thread(target=self.generate_threaded_gapped_words,group=None,daemon=True)
x.start()
if self.requests["change language"]:
self.text_index = (self.text_index+1)%len(self.corpora)
self.slides["parameters"].elements["button texts"][0].base_text = self.corpora_names[self.text_index]
self.slides["parameters"].elements["button texts"][0].render_text()
if self.requests["change word end"]:
self.word_end_index = (self.word_end_index+1)%len(self.word_ends)
self.slides["parameters"].elements["button texts"][1].base_text = "End in -"+self.word_ends[self.word_end_index]
self.slides["parameters"].elements["button texts"][1].render_text()
def generate_threaded_spaced_words(self):
generated_words = self.words_call(self.requests["change spaced"][0],self.corpora[self.text_index],False)
for i in range(min(16,len(generated_words))):
self.current_slide.elements["button texts"][i].base_text = generated_words[i]
self.current_slide.elements["button texts"][i].current_text = self.current_slide.elements["button texts"][i].base_text
self.current_slide.elements["button texts"][i].current_color = self.current_slide.elements["button texts"][i].main_color
self.current_slide.elements["button texts"][i].base_text_rendered = self.current_slide.elements["button texts"][i].update_rendered_text()
def generate_threaded_gapped_words(self):
generated_words = self.words_call(self.requests["change gapped"][0],self.corpora[self.text_index],True)
for i in range(min(10,len(generated_words))):
self.current_slide.elements["button texts"][i].base_text = generated_words[i]
self.current_slide.elements["button texts"][i].current_text = self.current_slide.elements["button texts"][i].base_text
self.current_slide.elements["button texts"][i].current_color = self.current_slide.elements["button texts"][i].main_color
self.current_slide.elements["button texts"][i].base_text_rendered = self.current_slide.elements["button texts"][i].update_rendered_text()
def words_call(self,seed,text,gapped):
generated_words = []
current_word_end = self.word_ends[self.word_end_index]
if gapped:
generated_words += self.collapsed_text.generate_gapped_text(200,text,seed)
generated_words = list(set(generated_words))
generated_words.sort()
return generated_words
if len(seed) == 0:
length = 4
else:
length = 2
generated_words += self.collapsed_text.generate_spaced_text(200,text,seed,current_word_end+"!",length)
generated_words = list(set(generated_words))
generated_words.sort()
return generated_words
def update(self):
self.clock.tick(90)
self.requests = {"change slide":[],"change language":[],"change word end":[],"change spaced":[],"change gapped":[],"applying_changes":False}
self.current_slide.update(self.requests,self.submits)
self.process_requests()
self.floated_tick +=0.666
self.tick = int(self.floated_tick)
class Slide():
def __init__(self,identifiant,background_color,main_color,fonts,screen_width):
# Get data from API
self.background_color = background_color
self.main_color = main_color
self.altered_color = (120,100,82)
self.fonts = fonts
self.identifiant = identifiant
self.screen_width = screen_width
self.addons = {"fonts":fonts,
"colors":{"main color":self.main_color,"background color":self.background_color,"altered color":self.altered_color,"desaltered color":(134,98,110)},
"screen width":self.screen_width}
# Create and set up the structure
self.classes = {"button texts":ButtonText,
"eyes":Eye,
"closing eyes":ClosingEye,
"text fields":TextField,
"texts":DisplayedText,
"laceworks":Lacework,
"gears":Gear,
"strings":OscillatingString,
"clouds":Cloud,
"fingers":Finger,
"clocks":Clock,
"cheeses":Cheese,
"arrows":Arrow}
self.elements ={"button texts":[],
"text fields":[],
"texts":[],
"eyes":[],
"closing eyes":[],
"laceworks":[],
"gears":[],
"strings":[],
"clouds":[],
"fingers":[],
"clocks":[],
"cheeses":[],
"arrows":[]}
# Load the elements of the slide
with open(f"Structure/{identifiant}.json") as f:
data = json.load(f)['main']
f.close()
# Create the objects corresponding in the json file
for category,element_list in data.items():
for element in element_list:
self.elements[category].append(self.classes[category](*element.values(),self.addons))
if identifiant == "dictionary": self.create_spaced_texts()
elif identifiant == "completion": self.create_gapped_texts()
def create_spaced_texts(self):
# Create the displayed examples of generated words
temp_collapsed_text = wfca.CollapsedText()
generated_words = temp_collapsed_text.generate_spaced_text(200,"Texts/FrenchCorpus.txt","A","er!",2)
generated_words = list(set(generated_words))
generated_words.sort()
# Create the associated elements
rows = [5,6,5]
for j in range(3):
for i in range(rows[j]):
x = 1/(1/3.15+(j/4.6))
y = 1/(1/5.2+(i/15)-(j%2)/24)
self.elements["button texts"].append(ButtonText(x,y,generated_words[i+j*5],[None,None],3,True,0,self.addons))
def create_gapped_texts(self):
# Create the displayed examples of generated words
temp_collapsed_text = wfca.CollapsedText()
generated_words = temp_collapsed_text.generate_gapped_text(50,"Texts/FrenchCorpus.txt","P____ine")
generated_words = list(set(generated_words))
generated_words.sort()
# Create the associated elements
rows = [3,4,3]
word_index = 0
for j in range(3):
for i in range(rows[j]):
word_index += 14
x = 1/(1/4.5+(j/5))
y = 1/(1/5+(i/10)-(j%2)/24+((j+1)%2)/80)
if (word_index)>= len(generated_words):
self.elements["button texts"].append(ButtonText(x,y,generated_words[i+j*5],[None,None],3,True,0,self.addons))
continue
self.elements["button texts"].append(ButtonText(x,y,generated_words[i+j*5],[None,None],3,True,0,self.addons))
def draw(self,screen,tick):
screen.fill(self.background_color)
all_elements = [el for category in self.elements.values() for el in category]
for obj in all_elements:
obj.draw(screen,tick)
def update(self,requests,submits):
for button_text in self.elements["button texts"]:
button_text.update(requests)
for text_field in self.elements["text fields"]:
text_field.update(submits,requests)
for cloud in self.elements["clouds"]:
cloud.update(requests)
for clock in self.elements["clocks"]:
clock.update(requests)
for gear in self.elements["gears"]:
gear.update(requests)
for finger in self.elements["fingers"]:
finger.update()
for text in self.elements["texts"]:
text.update()
#=- Alphabetically ordered decoration elements -=#
class Arrow():
def __init__(self,x,y,radius,inversed,addons):
# Arrow attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = int(addons["screen width"]/radius)
self.inversed = inversed
# Global attributes
self.main_color = addons["colors"]["main color"]
self.background_color = addons["colors"]["background color"]
def draw(self,screen,tick):
x,y = self.position
# Draw the arrow body -> four segments
for i in range(4):
# Get the circle Ys
self.circle_positions = [int(y-self.radius/2),int(y+self.radius/2)] if (i+self.inversed)%2 else [int(y+self.radius/2),int(y-self.radius/2)]
# And the rect between the blank and colored circles
self.rect_positions = to_rect(x,y,self.radius*2,self.radius)
# Draw the colored one
pygame.gfxdraw.filled_circle(screen,x,self.circle_positions[0],self.radius,self.main_color)
pygame.gfxdraw.aacircle(screen,x,self.circle_positions[0],self.radius,self.main_color)
# Draw the rect in between
pygame.gfxdraw.filled_polygon(screen,self.rect_positions,self.main_color)
pygame.gfxdraw.aapolygon(screen,self.rect_positions,self.main_color)
# Draw the blank one
pygame.gfxdraw.filled_circle(screen,x,self.circle_positions[1],self.radius,self.background_color)
pygame.gfxdraw.aacircle(screen,x,self.circle_positions[1],self.radius,self.background_color)
# Move X to the next segment
x += self.radius*2
# Draw the arrow tip -> moving triangle
x -= self.radius
# Set the angle of the tip
theta = -math.pi/4 + math.cos(tick/20+self.inversed*math.pi)*math.pi/5 - (self.inversed)*math.pi/2
# Get the coordinates of the triangle of the tip
trigon_position = [ int_vec((x+self.radius*math.cos(theta),y+self.radius*(math.sin(theta)+0.3))),
int_vec((x+self.radius*math.cos(theta+1.57),y+self.radius*(math.sin(theta+1.57)+0.3))),
int_vec((x+self.radius*math.cos(theta+3.141),y+self.radius*(math.sin(theta+3.141)+0.3)))]
# Eventually draw the tip
pygame.gfxdraw.filled_polygon(screen,trigon_position,self.main_color)
pygame.gfxdraw.aapolygon(screen,trigon_position,self.main_color)
class ButtonText():
def __init__(self,x,y,text,action,changing_type,underlined,cooldown,addons):
# Button text attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.base_text = text # Initially displayed text
self.action = action # Which action is done when the button is pressed
self.changing_type = changing_type # Hover aspect
self.underlined = underlined # Determine if the text is underlined
self.cooldown_delay = cooldown # Set the cooldown between two presses
self.cooldown = 0
# Global attributes
self.font = addons["fonts"][0] if action[0] else addons["fonts"][1]
self.main_color = addons["colors"]["main color"]
# Modifiers
self.current_color = addons["colors"]["main color"] # Drawn color
self.current_text = text # Displayed text
self.altered = False # == True if the button is hovered
self.increment = 0 # Animation variabme
self.render_text()
def render_text(self):
# Renders the text and associate it its ux elements
self.base_text_rendered = self.font.render(self.base_text,True,self.main_color)
self.base_rect = pygame.rect.Rect(*self.position,*self.font.size(self.base_text))
# Reset the data
self.current_text = self.base_text
self.current_render = self.base_text_rendered
self.current_rect = pygame.rect.Rect(*self.position,*self.font.size(self.current_text))
self.current_underline = pygame.rect.Rect(self.current_rect.x,self.current_rect.y+self.current_rect.height-3,self.current_rect.width,2)
def reset(self):
# Reset the data
self.cooldown = max(0,self.cooldown-1)
self.current_color = self.main_color
self.current_text = self.base_text
self.current_render = self.base_text_rendered
self.current_rect = pygame.rect.Rect(*self.position,*self.font.size(self.current_text))
self.current_underline = pygame.rect.Rect(self.current_rect.x,self.current_rect.y+self.current_rect.height-3,self.current_rect.width,2)
def update_rendered_text(self):
return self.font.render(self.current_text,True,self.current_color)
def update(self,requests):
self.reset()
# Get if the button is hovered
self.altered = self.current_rect.collidepoint(*pygame.mouse.get_pos())
if not self.altered: return # Not hovered -> quit
# If the button is clickable (coolodwn == 0) and there is a click process its action
if pygame.mouse.get_pressed()[0] and self.action[0] and not self.cooldown:
requests[self.action[0]].append(self.action[1])
self.cooldown = self.cooldown_delay
# Animation elements
self.increment += 1
if self.changing_type == 1:
self.current_color = (120,100,82)
self.current_text = self.base_text
self.current_render = pygame.transform.flip(self.update_rendered_text(),False,True)
elif self.changing_type == 2:
self.current_color = (120,100,82)
self.current_text = self.base_text[(self.increment//20)% (len(self.base_text)):]+ self.base_text[:((self.increment//20)% (len(self.base_text)))]
self.current_render = self.update_rendered_text()
elif self.changing_type == 3:
self.current_color = (120,100,82)
self.current_text = self.base_text
self.current_render = self.update_rendered_text()
def draw(self,screen,tick=0):
# Draw the text
screen.blit(self.current_render,self.position)
if not self.underlined: return
# Draw the line below if it is underlined
pygame.draw.rect(screen,self.main_color,self.current_underline)
class Cheese():
def __init__(self,x,y,start_angle,end_angle,radius,addons):
# Cheese attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.angle = int_vec([math.pi/start_angle,math.pi/end_angle]) # Range of angle between hole and abs
self.radius = int(addons["screen width"]/radius) # Max distance between the cheese pos and hole
# Global attributes
self.main_color = addons["colors"]["main color"]
# Determine amount and sizes of the holes, generate them
self.holes = []
self.hole_radius = [radius/13,radius/20,radius/20,radius/20,radius/8.5]
self.holes_count = 30
self.generate_holes()
def generate_holes(self):
# Generate all the holes
for i in range(self.holes_count):
# Hole attributes
drawn_angle = random.randint(self.angle[0]*100,self.angle[1]*100)/100
drawn_radius = random.randint(0,self.radius*100)/100
drawn_size = self.radius/random.randint(8,25)
# Create the hole
self.holes.append([int_vec(add_vec(self.position,[math.cos(drawn_angle)*drawn_radius,math.sin(drawn_angle)*drawn_radius])),drawn_size,random.random()*6.28])
def draw(self,screen,tick):
# Loop for each hole
for i in range(self.holes_count):
# Draw the aa-hole
pygame.gfxdraw.aacircle(screen,*self.holes[i][0],int(self.holes[i][1]),self.main_color)
pygame.gfxdraw.filled_circle(screen,*self.holes[i][0],int(self.holes[i][1]),self.main_color)
class Clock():
def __init__(self,x,y,radius,looking,addons):
# Clock attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = addons["screen width"]/radius
self.initial_radius = addons["screen width"]/radius
self.looking = looking
self.altered = False
# Global attributes
self.main_color = addons["colors"]["main color"]
self.altered_color = addons["colors"]["desaltered color"]
self.background_color = addons["colors"]["background color"]
self.font = pygame.font.Font("mirage.otf",int(self.radius/3))
# Set up the arrows and the "i"s
self.arrows = 3
self.arrows_infos = []
self.max_arrow_angle = int(628/self.arrows)
self.generate_arrows()
self.i_delay = 0
self.rendered_i = self.font.render("i",True,self.main_color)
def update(self,requests):
# Only update the looking clock
if self.looking:
return
self.altered = get_mouse_distance(self.position) < self.radius*0.75
# If the user clicks on, send the request
if not self.altered: return
if not pygame.mouse.get_pressed()[0]: return
requests["change slide"].append("main")
def generate_arrows(self):
# Get a random angle for the first arrow
arrow_angle = random.randint(20,int(628/self.arrows))/100
for i in range(self.arrows):
# Create an arrow and update the next one angle
self.arrows_infos.append([arrow_angle,random.randint(50,110)/100,random.randint(50,90),math.pi/12])
arrow_angle += math.pi*2/self.arrows * random.randint(90,110)/100
def draw_arrowing_clock(self,screen,tick):
self.i_delay += 0.01*(1+self.altered)
# Draw the bigger circle of the clock
pygame.gfxdraw.filled_circle(screen,*int_vec(self.position),int(self.radius*0.75), self.altered_color if not self.altered else self.main_color)
pygame.gfxdraw.aacircle(screen,*int_vec(self.position),int(self.radius*0.75), self.altered_color if not self.altered else self.main_color)
# Draw the mecanism center of the clock
pygame.gfxdraw.filled_circle(screen,*int_vec(self.position),int(self.radius*0.05),self.main_color if not self.altered else self.altered_color)
pygame.gfxdraw.aacircle(screen,*int_vec(self.position),int(self.radius*0.05),self.main_color if not self.altered else self.altered_color)
for i in range(self.arrows):
# Update and set the angle of the arrow
arrow_delay = 10*self.i_delay
arrow_dtheta = arrow_delay*self.arrows_infos[i][3]
angle = self.arrows_infos[i][0]+arrow_dtheta
# Get the arrow offset and get the position of the end of the arrow
arrow_lift = [self.radius*self.arrows_infos[i][1]*math.cos(angle),self.radius*self.arrows_infos[i][1]*math.sin(angle)]
end_line = add_vec(self.position,arrow_lift)
# Draw the end of the arrow
pygame.gfxdraw.filled_circle(screen,*int_vec(end_line),int(self.radius*self.arrows_infos[i][1]*0.2), self.main_color if not self.altered else self.altered_color)
pygame.gfxdraw.aacircle(screen,*int_vec(end_line),int(self.radius*self.arrows_infos[i][1]*0.2), self.main_color if not self.altered else self.altered_color)
# Draw the arrow itself
pygame.draw.line(screen,self.main_color if not self.altered else self.altered_color,self.position,end_line,3)
# All the "i" orbiting around the clock
for i in range(0,12):
# Get offset and raw position
spatched_i = [self.radius*1.5*math.cos(self.i_delay+2*math.pi*i/12),self.radius*1.5*math.sin(self.i_delay+2*math.pi*i/12)]
spatched_i = add_vec(spatched_i,[-self.font.size("i")[0]/2,-self.font.size("i")[1]/2])
screen.blit(self.rendered_i,add_vec(self.position,spatched_i))
def draw_looking_clock(self,screen,tick):
# Get some values
mouse_angle = get_mouse_angle(self.position)
circle_offset = [self.radius*0.35*math.cos(mouse_angle),self.radius*0.35*math.sin(mouse_angle)]
eye_ball_position = add_vec(self.position,circle_offset)
inner_circle_offset = [self.radius*0.35*math.cos(math.pi+mouse_angle),self.radius*0.35*math.sin(math.pi+mouse_angle)]
segment_first_end = [self.radius*0.35*math.cos(mouse_angle),self.radius*0.35*math.sin(mouse_angle)]
segment_second_end = [self.radius*math.cos(math.pi+mouse_angle),self.radius*math.sin(math.pi+mouse_angle)]
# Opposite direction inner circle
pygame.gfxdraw.aacircle(screen,*int_vec(add_vec(self.position,inner_circle_offset)),int(self.radius*0.5), self.altered_color)
pygame.gfxdraw.filled_circle(screen,*int_vec(add_vec(self.position,inner_circle_offset)),int(self.radius*0.5), self.altered_color)
pygame.gfxdraw.aacircle(screen,*int_vec(add_vec(self.position,inner_circle_offset)),int(self.radius*0.25), self.background_color)
pygame.gfxdraw.filled_circle(screen,*int_vec(add_vec(self.position,inner_circle_offset)),int(self.radius*0.25), self.background_color)
# Right direction inner circle
pygame.gfxdraw.aacircle(screen,*int_vec(eye_ball_position),int(self.radius*0.3), self.main_color)
pygame.gfxdraw.filled_circle(screen,*int_vec(eye_ball_position),int(self.radius*0.3), self.main_color)
pygame.gfxdraw.aacircle(screen,*int_vec(eye_ball_position),int(self.radius*0.1), self.background_color)
pygame.gfxdraw.filled_circle(screen,*int_vec(eye_ball_position),int(self.radius*0.1), self.background_color)
# Line between the two
pygame.draw.line(screen,self.background_color,add_vec(self.position,segment_first_end),add_vec(self.position,segment_second_end),5)
# Blank outer circle and colored outer circle
pygame.draw.circle(screen,self.background_color,self.position,int(self.radius),int(self.radius*0.45))
pygame.draw.circle(screen,self.altered_color,self.position,self.radius*1.01,int(self.radius*0.2))
pygame.gfxdraw.aacircle(screen,*int_vec(self.position),int(self.radius*1.01), self.altered_color)
pygame.gfxdraw.aacircle(screen,*int_vec(self.position),int(self.radius), self.background_color)
def draw(self,screen,tick):
return self.draw_looking_clock(screen,tick) if self.looking else self.draw_arrowing_clock(screen,tick)
class ClosingEye():
def __init__(self,x,y,radius,addons):
# Closing Eye attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = int(addons["screen width"]/radius)
# Global attributes
self.main_color = addons["colors"]["main color"]
self.background_color = addons["colors"]["background color"]
def draw(self,screen,tick):
decreasing = int(self.radius*(0.5+0.5*abs(math.cos(tick/80))))
# First inner circle
pygame.gfxdraw.aacircle(screen,*self.position,self.radius, self.main_color)
pygame.gfxdraw.filled_circle(screen,*self.position,self.radius, self.main_color)
# Breathing circle
pygame.gfxdraw.aacircle(screen,self.position[0],self.position[1]-self.radius,decreasing, self.background_color)
pygame.gfxdraw.filled_circle(screen,self.position[0],self.position[1]-self.radius,decreasing, self.background_color)
# Draw the irises
mouse_angle = get_mouse_angle(self.position)
# First iris, moving in direction to the mouse
iris_position = int_vec((self.position[0]+0.5*self.radius*math.cos(mouse_angle),self.position[1]+0.5*self.radius*math.sin(mouse_angle)))
pygame.gfxdraw.aacircle(screen,*iris_position,int(self.radius/3), self.background_color)
pygame.gfxdraw.filled_circle(screen,*iris_position,int(self.radius/3), self.background_color)
# Second iris
iris_position = int_vec((self.position[0]+0.6*self.radius*math.cos(mouse_angle),self.position[1]+0.6*self.radius*math.sin(mouse_angle)))
pygame.gfxdraw.aacircle(screen,*iris_position,int(self.radius/5), self.main_color)
pygame.gfxdraw.filled_circle(screen,*iris_position,int(self.radius/5), self.main_color)
class Cloud():
def __init__(self,x,y,radius,addons):
# Cloud attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = addons["screen width"]/radius
self.altered = False
# Global attributes
self.main_color = addons["colors"]["main color"]
self.background_color = addons["colors"]["background color"]
self.altered_color = addons["colors"]["altered color"]
# Create the waterflows
x = self.position[0]
y = self.position[1]
self.water_flows = [WaterFlow(x,y-self.radius,self.main_color,self.radius*2),WaterFlow(x+self.radius*1.1,y-self.radius*1.5,self.main_color,self.radius*3),WaterFlow(x-self.radius*1.3,y+self.radius*0.2,self.main_color,self.radius*3)]
# Set up the text in the center
self.font = pygame.font.Font("mirage.otf",int(self.radius))
self.text = "III"
self.base_render = self.font.render(self.text,True,self.background_color)
self.altered_render = self.font.render(self.text,True,self.altered_color)
self.current_render = self.base_render
# Set centered text properties
self.letter_dxy = [s/2 for s in self.font.size(self.text)]
self.letter_rect = self.base_render.get_rect()
self.letter_rect.x,self.letter_rect.y = self.position[0]-self.letter_dxy[0],self.position[1]-self.letter_dxy[1]
def update(self,requests):
self.current_render = self.base_render
self.altered = self.letter_rect.collidepoint(*pygame.mouse.get_pos())
if not self.altered: return
self.current_render = self.altered_render
if not pygame.mouse.get_pressed()[0]: return
requests["change slide"].append("main")
def draw(self,screen,tick):
#-- Draw the cloud itself --#
# The main circle of the cloud
pygame.gfxdraw.aacircle(screen,*self.position,int(self.radius), self.main_color)
pygame.gfxdraw.filled_circle(screen,*self.position,int(self.radius), self.main_color)
# The auxilaries circles #
iterated_circles = [[-self.radius,self.radius/10,int(self.radius/1.3)],
[-self.radius/1.5,-self.radius/2,int(self.radius/2.5)],
[self.radius/1.1,self.radius/9,int(self.radius/1.4)],
[self.radius/1.5,self.radius/2,int(self.radius/2.5)],]
for i in range(len(iterated_circles)):
iterated_circle_position = int_vec([self.position[0]+iterated_circles[i][0],
self.position[1]+iterated_circles[i][1],])
pygame.gfxdraw.aacircle(screen,*iterated_circle_position,iterated_circles[i][2], self.main_color)
pygame.gfxdraw.filled_circle(screen,*iterated_circle_position,iterated_circles[i][2], self.main_color)
# The water drops #
for water_flow in self.water_flows:
water_flow.draw(screen,tick)
screen.blit(self.current_render,[self.position[0]-self.letter_dxy[0],self.position[1]-self.letter_dxy[1]])
class DisplayedText():
def __init__(self,x,y,text,addons):
# Displayed text attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.base_text = text
# Global attributes
self.font = addons["fonts"][2]
self.main_color = addons["colors"]["main color"]
self.screen_width = addons["screen width"]
# Animation settings
self.animation_delay = 15 # time in tick between two changements
self.animation_counter = 0 # timer
self.animation_index = 0 # index of the letter capitalized (Workers of the world unite; you have nothing to lose but your chains.)
self.animated_texts = []
self.render_text()
self.render_animated_texts()
def render_animated_texts(self):
for i in range(len(self.base_text)):
# Get the text as a list
text = list(self.base_text.lower())
# Capitalize one
text[i] = text[i].upper()
# Turn back into text
self.base_text = "".join(text)
# Render and store
self.render_text()
self.animated_texts.append(self.rendered_text)
def render_text(self):
self.rendered_text = self.font.render(self.base_text,True,self.main_color)
def update(self):
# Update the counter
self.animation_counter = max(0,self.animation_counter-1)
if self.animation_counter: return
self.animation_index += 1 #update index
self.animation_counter = self.animation_delay #update counter
self.rendered_text = self.animated_texts[self.animation_index%(len(self.base_text))] # set the new rendered
def draw(self,screen,tick):
screen.blit(self.rendered_text,self.position)
class Eye():
def __init__(self,x,y,radius,harmonics,addons):
# Eye attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = addons["screen width"]/radius
self.harmonics = harmonics
self.precision = 20
# Global attributes
self.main_color = addons["colors"]["main color"]
self.background_color = addons["colors"]["background color"]
# Render and specify letters drawn inside the eyeballs
self.delay = random.randint(0,10)
self.letters = "dictionary "
self.rendered_letters = {}
self.initialize_letters(addons["fonts"][1])
def initialize_letters(self,font):
# Get all the unique letters in my text
unique_letters = "".join(set(self.letters))
for i in range(len(unique_letters)):
# Render each letter
self.rendered_letters[unique_letters[i]] = [font.render(unique_letters[i],True,self.background_color),font.size(unique_letters[i])]
def draw(self,screen,tick):
# Get the mouse position to make the iris follow the cursor
mouse_angle = get_mouse_angle(self.position)
# Get the stretched iris position
iris_position = int_vec(generate_elipsoid(self.position,mouse_angle,self.radius/3,self.harmonics,tick))
# Draw the iris
pygame.gfxdraw.aacircle(screen,*iris_position,int(self.radius/2.5), self.main_color)
pygame.gfxdraw.filled_circle(screen,*iris_position,int(self.radius/2.5), self.main_color)
# Get wich letter has to be drawn inside the iris
letter = self.letters[(self.delay + tick // 50) % len(self.letters)]
# Draw the letter
iris_position[0] -= self.rendered_letters[letter][1][0]/2
iris_position[1] -= self.rendered_letters[letter][1][1]/2
screen.blit(self.rendered_letters[letter][0],iris_position)
# Draw the outline of the eyeball
for i in range(int(6.31*self.precision)):
outline_position = int_vec(generate_elipsoid(self.position,i/self.precision,self.radius,self.harmonics,tick))
pygame.gfxdraw.filled_circle(screen,*outline_position,1, self.main_color)
class Finger():
def __init__(self,x,y,length,angle,inverted,addons):
# Finger attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.base_length = addons["screen width"]/length
self.ultimate_base_length = addons["screen width"]/length
self.base_angle = math.pi/angle
self.ultimate_base_angle = math.pi/angle
self.cooldown = 0 # Cooldown between two phalanx-cut
self.phalanx_count = 4 # Number of phalanx
self.inverted = (-1)**inverted
# Global attributes
self.main_color = addons["colors"]["desaltered color"]
self.background_color = addons["colors"]["background color"]
self.altered_color = addons["colors"]["main color"]
self.used_colors = [self.altered_color,self.main_color]
# Determination of more specifics finger's caracteristics
self.angle_speed = random.randint(120,150)
self.angle_delay = random.randint(0,62)/10
self.length_speed = random.randint(90,110) # How fast the phalanx stretches
self.length_delay = random.randint(0,62)/10
self.angle_amplitude = random.randint(10,20)/100
self.length_amplitude = random.randint(10,20)/100 # How much the phalanx stretches
self.dtheta_delay = random.randint(0,62)/10
self.dtheta_amplitude= random.randint(8,20)/100
self.dtheta = 0
def update(self):
# Phalanx cutting
self.cooldown = max(0,self.cooldown-1)
if get_mouse_distance(self.position)>100 or not pygame.mouse.get_pressed()[0]:
return
if self.cooldown > 0 or self.phalanx_count<3:
return
# If the phalanx is cutable, cut it and modify its properties
self.cooldown = 20
self.phalanx_count -= 1
self.dtheta_amplitude *= 3
def draw(self,screen,tick):
# Angle, length and angle offset used for all the finger, that depends of time
self.base_angle = self.ultimate_base_angle * (1+self.angle_amplitude*math.cos(self.angle_delay+tick/self.angle_speed))
self.base_length = self.ultimate_base_length* (1+self.length_amplitude*math.cos(self.length_delay+tick/self.length_speed))/1.3
self.dtheta = self.dtheta_amplitude*math.cos(self.dtheta_delay+tick/10)
# Get the width of the finger in function the length of a single segment
self.width = self.base_length / 5
# Draw the finger and its shadow
for j in range(2):
last_joint_pos = add_vec(self.position,[5,5]) if not self.inverted + 1 else add_vec(self.position,[5,-5])
# Draw the very beginning of the finger
pygame.draw.circle(screen,self.used_colors[j],last_joint_pos,self.width/2)
for i in range(self.phalanx_count):
# Phalanx properties
curbature = self.inverted*math.pi/(self.phalanx_count-i) if i else i
current_angle = self.base_angle-curbature-self.inverted*self.dtheta*i
current_length = self.base_length/(i+1) if i else 0.7*self.base_length
# Position of the end of the phalanx
joint = add_vec(last_joint_pos,[current_length*math.cos(-current_angle),current_length*math.sin(-current_angle)])
phax_joint = [[0.5*self.width*math.cos(-current_angle-math.pi/2),0.5*self.width*math.sin(-current_angle-math.pi/2)],[0.5*self.width*math.cos(-current_angle+math.pi/2),0.5*self.width*math.sin(-current_angle+math.pi/2)]]
phalanx = [add_vec(last_joint_pos,phax_joint[0]),add_vec(last_joint_pos,phax_joint[1]),add_vec(joint,phax_joint[1]),add_vec(joint,phax_joint[0])]
# Draw the rectangular part of the phalanx
pygame.draw.polygon(screen,self.used_colors[j],phalanx)
pygame.draw.aaline(screen,self.used_colors[j],int_vec(phalanx[0]),int_vec(phalanx[1]),3)
pygame.draw.aaline(screen,self.used_colors[j],int_vec(phalanx[1]),int_vec(phalanx[2]),3)
pygame.draw.aaline(screen,self.used_colors[j],int_vec(phalanx[2]),int_vec(phalanx[3]),3)
pygame.draw.aaline(screen,self.used_colors[j],int_vec(phalanx[3]),int_vec(phalanx[0]),3)
# Draw the end of the phalanx : nail / junction
pygame.gfxdraw.aacircle(screen,*int_vec(joint),int(1.06*self.width/2), self.used_colors[j])
pygame.gfxdraw.filled_circle(screen,*int_vec(joint),int(1.06*self.width/2), self.used_colors[j])
last_joint_pos = joint
last_joint_pos = self.position
self.base_length *= 1.3
self.width = self.base_length / 5
class Gear():
def __init__(self,x,y,radius,text,addons):
# Gear attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.radius = addons["screen width"]/radius
self.text = text
self.tick = 0
self.altered = False
# Global attributes
self.main_color = addons["colors"]["main color"]
self.background_color = addons["colors"]["main color"]
self.screen_width = addons["screen width"]
self.font = pygame.font.Font("mirage.otf",int(self.screen_width/24))
self.font_small = pygame.font.Font("mirage.otf",int(self.screen_width/60))
self.text_rendered = [self.font.render(self.text,True,self.main_color),self.font_small.render("a",True,self.main_color),self.font_small.render("r"if text=="P" else "ck",True,self.main_color)]
def update(self,requests):
self.altered = get_mouse_distance(self.position)<50
if not pygame.mouse.get_pressed()[0] or not self.altered: return
# Send request if the user clicks on the center
requests["change slide"].append("parameters" if self.text == "P" else "dictionary")
def draw(self,screen,tick=0):
self.tick += 1*(1-2*self.altered)*(1+self.altered)
# Draw the center
screen.blit(self.text_rendered[0],self.position)
# Draw the orbital letters arround
dx = self.screen_width/240
orbital_pos = dx+self.position[0]+math.cos(self.tick/(dx*8))*dx*6,3*dx+self.position[1]+math.sin(self.tick/(dx*8))*dx*6
screen.blit(self.text_rendered[1],orbital_pos)
orbital_pos = dx+self.position[0]+math.cos(2*dx+self.tick/(dx*6))*dx*6,3*dx+self.position[1]+math.sin(2*dx+self.tick/(dx*6))*dx*10
screen.blit(self.text_rendered[2],orbital_pos)
class Lacework():
def __init__(self,x,y,radius,harmonics,linked,addons):
# Lacework attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.initial_radius = addons["screen width"]/radius
self.harmonics = harmonics
self.linked = linked
# Global attributes
self.main_color = addons["colors"]["main color"]
# Number of points per layer
self.precision = 5 if linked else 15
# Nummber of layers
self.iterations = 8
def draw(self,screen,tick):
# For each layer
for j in range(self.iterations):
# Get the layer distance
radius = self.initial_radius - self.initial_radius/18 * j
if self.linked:
# Draw a line between the two points
pygame.draw.aalines(screen,self.main_color,True,[int_vec(generate_elipsoid(self.position,i/self.precision,radius,self.harmonics,tick)) for i in range(int(6.31*self.precision))],1)
continue
for i in range(int(6.31*self.precision)):
# Draw the points
pygame.gfxdraw.filled_circle(screen,*int_vec(generate_elipsoid(self.position,i/self.precision,radius,self.harmonics,tick)),1,self.main_color)
class OscillatingString():
def __init__(self,x,y,length,addons):
# Oscillating String attributes
self.position = int_vec((addons["screen width"]/x,addons["screen width"]/y))
self.length = addons["screen width"]/length
self.precision = 80 # Number of vertical layers
# Global attributes