Files
  • main.py
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
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
import pygame, sys
from pygame.locals import *
##############################################################
#Zoila and Olivia


import random

#print('Level 0: Basic one-expression derivatives and intregation.\nLevel 1: Multiple-expression derivatives and intregation with one connection.\nLevel 2: Multiple-expression dervatives and integration with two connection.\nLevel 3: Multiple-expression dervatives and integration with three connections.\nConnections are addition, subtraction, multiplication, and division.\nLevel 4: Extreme.')
#print('\nWhat level do you want to work in? Type a number from 0 to 4?')
level = 2#int(input())
probsol=[]
for i in range(3):
    #cm is constant multiple
    cm = random.randint(1,9)
    #e is exponent
    e = random.randint(1,9)
    if cm == 1:
      st_cm = ''
    else:
      st_cm = str(cm)
    if e == 1:
      st_e = ''
    else:
      st_e = str(e)

    #sE = simpleExpression
    sE = ['', '(sin', '(cos', '(ln']
    rsE = list(random.choice(sE))
    der=''
    if rsE != []:
      rsE.append('(x)')
      rsE.append(')')
    else:
      rsE.append('(x)')

    #fun is function
    fun = ['(sin', '(cos', '(ln']
    rfun = random.choice(fun)

    if level == 0:
      rsE = ''.join(rsE)
      probsol.append(rsE)


    if level > 0:
      #locx is for location of (x)
      locx = rsE.index('(x)')
      
      #loop replaces x with a new random function
      for i in range(random.randint(1,4)):
        hold = rsE[locx]
        rsE[locx] = rfun
        rsE.insert(locx+1,'(x)')
        rsE.append(')')
        rfun = random.choice(fun)
        locx = rsE.index('(x)')
      rsE = ''.join(rsE)
      rsE = list(rsE)
      
      #ep is "list of end parenthesis" and is the list that the location number of the end parenthesis in rsE will be appended to
      ep = []
      #finds location of end parenthesis
      for i in range(len(rsE)):
        if rsE[i] == ')':
          ep.insert(0,i)
      
      #lep is length of ep, so number of end parenthesis
      lep = len(ep)
      rep = random.randint(0,lep)
      
      #adds random exponents to expressions
      for i in range(0,rep):
        rsE = list(rsE)
        if st_e != '1':
          rsE.insert(ep[i]+1,'^')
          rsE.insert(ep[i]+2,st_e)
        else:
          rsE = rsE
        e = random.randint(1,9)
        st_e = str(e)
      
      if rsE == list(rsE):
        rsE = ''.join(rsE)
      #if rsE == list(rsE):
      rsE = list(rsE)
      #sp is "list is start parenthesis" and is list where location number of start parenthesis is appended to
      sp = []

      #finds the locations of start parenthesis and appends them to sp
      for i in range(len(rsE)):
        if rsE[i] == '(':
          sp.insert(0,i)
      
      lsp = len(sp)
      rsp = random.randint(0,lsp)
      
      #adds random constant multiples to expressions
      for i in range(0,rsp):
        rsE = list(rsE)
        if st_cm != '1':
          rsE.insert(sp[i]+1,st_cm)
        cm = random.randint(1,9)
        st_cm = str(cm)
      rsE = ''.join(rsE)
      
      
      rsE = ('(2sin(3x))^7')
      #print(rsE,'rsE1')
      rsE = list(rsE)
      if rsE[0] == '(':
        rsE.insert(0,'1')
      #print(rsE)
        
    #  for i in range()
      #Working on finding the derivative
      ep = []

      #finding the close )
      for i in range(len(rsE)):
        if rsE[i] == ')':
          ep.insert(0,i)
      #print(ep,'ep')
      
    #  for i in range(len(rsE)):
    #    if rsE[i] == '(':
    #      rsE.insert(i,'1')
    #      break
    #  rsE = ''.join(rsE)

    #  print(rsE , "this is rsE")

    #  for i in range(len(rsE)):
    #    if rsE[i] == '(':
    #      sp.insert(i,'1')
    #  print(sp,'sp')
    #  print(rsE)

      sp = []
      for i in range(len(rsE)):
        if rsE[i] == '(':
          sp.append(i)
      #print(sp,'sp')

      for i in range(len(ep)-1):
        #print(i,'i')
        #v is variable
        #v1 location of ep
        v1 = int(ep[i]) + 1
        #print(v1,'v1')
        
        if rsE[v1] == '^':
          rsE[v1+1] = int(rsE[v1+1])

          if rsE[v1+1] == int(rsE[v1+1]):
            #v3 location of sp minus one
            v3 = sp[i] - 1
            #print(v3,'v3')
            rsE[v3] = int(rsE[v3])

            if rsE[v3] == int(rsE[v3]):
              v4 = rsE[v1+1] * rsE[v3]
              #print(v4,'v4')

      #print(rsE)

              

        


      
      if rsE == sE[0]:
        der = 1
        #print("zero")
        #print("this is the derivitive")
        #print(der)
      if rsE == sE[1]:
        if st_e == '':
          p = e * cm
          cm = str(cm)
          m = e - 1
          e = str(e)
          p = str
          m = str(m)
          st_e = str(st_e)
          der =  p + "x^" + m 
          #print("one")
          #print("This is the derivitive")
          #print(der)

        else:
          p = cm * e
          p = str(p)
          cm = str(cm)
          w = e - 1
          e = str(e)
          st_e = str(st_e)
          w = str(w)
          der = p + "(x)" + w
          #print("two")
          #print("This is the derivitive")
          #print(der)


      if rsE == sE[2]:
        if st_e == '':
          p = cm * e
          p = str(p)
          cm = str(cm)
          w = e - 1
          e = str(e)
          st_e = str(st_e)
          w = str(w)
          der = p + "(sin(x))^" + w
          #print("three")
          #print("This is the derivitive")
          #print(der)
        else:
          st_e + ')'
          p = e * cm
          p = str(p)
          cm = str(cm)
          w = e - 1
          e = str(e)
          st_e = str(st_e)
          w = str(w)
          der = p + "sin(x)^" + w + "cos(x)"
          #print("four")
          #print("This is the derivitive")
          #print(der)
      if rsE == sE[3]:
        if st_e == '':
          cm = str(cm)
          w = e - 1
          e = str(e)
          st_e = str(st_e)
          w = str(w)
          der = "-" + st_cm + "sin(x)" 
        else:
          st_e + ')'
          p = e * cm
          cm = str(cm)
          w = e - 1
          e = str(e)
          st_e = str(st_e)
          w = str(w)
          p = str(p)
          der = p + "cos(x)" + w + "-sin(x)"

    final1 = ''
    final2 = ''
    for i in range(len(rsE)):
        final1 = final1 + str(rsE[i])
    probsol.append(final1)
    for i in range(len(der)):
        final2 = final2 + str(der[i])
    probsol.append(final1)
    probsol.append(final2)
print(probsol)

#End Zoila and Olivia
#############################################################



# set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (144, 238, 144)
BLUE = (149, 200, 216)
GREY = (128,128,128)

# set up pygame
pygame.init()

# set up the window
windowSurface = pygame.display.set_mode((1200, 800), 0, 32)

pygame.display.set_caption('Calculus App')


# set up fonts
basicFont = pygame.font.SysFont(None, 48)

# set up the text
text = basicFont.render('READY TO IMPROVE YOUR DERIVATIVES?', True, WHITE, BLACK)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery

# draw the text onto the surface
windowSurface.blit(text, textRect)

# draw the white background onto the surface
windowSurface.fill(GREY)


# draw the flashcard's background rectangle onto the surface
pygame.draw.rect(windowSurface, BLACK, (textRect.left - 200, textRect.top - 200, textRect.width + 400, textRect.height + 400))
pygame.draw.rect(windowSurface, BLUE, (textRect.left - 190, textRect.top - 190, textRect.width + 380, textRect.height + 380))
pygame.draw.rect(windowSurface, BLACK, (textRect.left - 180, textRect.top - 180, textRect.width + 360, textRect.height + 360))

#let's go button
#pygame.draw.rect(windowSurface, GREEN, (textRect.centerx-50, textRect.top + 100,  200,  150))
text2 = basicFont.render('(click anywhere to proceed.)', True, WHITE, BLACK)
textRect2 = text2.get_rect()
textRect2.centerx = windowSurface.get_rect().centerx
textRect2.centery = windowSurface.get_rect().centery+100


# draw the text onto the surface
windowSurface.blit(text, textRect)
windowSurface.blit(text2, textRect2)

# draw the window onto the screen
pygame.display.update()

# run the game loop
i=0
tx = 'READY TO IMPROVE YOUR DERIVATIVES?'
tx3 = probsol[0]
tx4 = probsol[1]
tx5 = probsol[2]


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

        elif event.type == MOUSEBUTTONUP:
            mousex,mousey = event.pos
            mouseclicked = True
            
            if i == 0:
                #disappear previous text
                text = basicFont.render(tx, True, BLACK, BLACK)
                windowSurface.blit(text, textRect)

                text3 = basicFont.render(tx3, True, WHITE, BLACK)
                textRect3 = text3.get_rect()
                textRect3.centerx = windowSurface.get_rect().centerx
                textRect3.centery = windowSurface.get_rect().centery
                windowSurface.blit(text3, textRect3)
                pygame.display.update()
                
            elif i == 1:
                #disappear previous text
                text3 = basicFont.render(tx3, True, BLACK, BLACK)
                windowSurface.blit(text3, textRect3)

                text4 = basicFont.render(tx4, True, WHITE, BLACK)
                textRect4 = text3.get_rect()
                textRect4.centerx = windowSurface.get_rect().centerx
                textRect4.centery = windowSurface.get_rect().centery
                windowSurface.blit(text4, textRect4)
                pygame.display.update()

            elif i == 2:
                #disappear previous text
                text4 = basicFont.render(tx4, True, BLACK, BLACK)
                windowSurface.blit(text4, textRect4)

                text5 = basicFont.render(tx5, True, WHITE, BLACK)
                textRect5 = text5.get_rect()
                textRect5.centerx = windowSurface.get_rect().centerx
                textRect5.centery = windowSurface.get_rect().centery
                windowSurface.blit(text5, textRect5)
                pygame.display.update()
            else:
                #disappear previous text
                text5 = basicFont.render(tx5, True, BLACK, BLACK)
                windowSurface.blit(text5, textRect5)

                text2 = basicFont.render('(click anywhere to proceed.)', True, BLACK, BLACK)
                windowSurface.blit(text2, textRect2)

                text6 = basicFont.render('Good Job', True, WHITE, BLACK)
                textRect6 = text5.get_rect()
                textRect6.centerx = windowSurface.get_rect().centerx
                textRect6.centery = windowSurface.get_rect().centery
                windowSurface.blit(text6, textRect6)
                pygame.display.update()

            i=i+1

        elif event.type == MOUSEMOTION:
            mousex,mousey = event.pos