Thursday, November 30, 2023

Pie Time

 I'm in pie land!!



                                                                    *     *     *

Thinking that I should get with it, and finally look at Evariste Galois and - eventually -

Lie groups. The underlying problem being the difficulty of solving higher order equations,

and working with groups and transformations instead. Very important for physics...


But then, Bard really impressed me this morning:

                                                                   


                                                                          




Asked for the expansion of (x + 1)^5. Then asked for the root of the long equation.

No problem!!
                                                            *     *     *

Just updated Feed Aspen to make it more challenging (Pygame10). The speed of the oncoming bowl

increases every time the player scores. As well, one can play again from the Game Over

screen.

                                                                    

It's a playable game...


import pygame
import random

# Pygame Setup Stuff
pygame.init()
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 500
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Codemy.com - Feed Aspen')
clock = pygame.time.Clock()
running = True
# Create Variables to keep track of score and lives
score = 0
lives = 5
speed = 5
playsound = True

dt = 0
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)

# Define the fonts
title_font = pygame.font.SysFont('impact', 40)
score_font = pygame.font.SysFont('impact', 25)
lives_font = pygame.font.SysFont('impact', 25)
game_over_font = pygame.font.SysFont('impact', 75)
restart_game_font = pygame.font.SysFont('impact', 40)

# Render the text (as surface) Text, boolean for antialiasing, text color, bg color
title_text = title_font.render("Feed Aspen!", True, "#3d5f9f", "silver")
score_text = score_font.render(f"Score: {score}", True, "#3d5f9f", "silver")
lives_text = lives_font.render(f"Lives: {lives}", True, "#3d5f9f", "silver")
game_over_text = game_over_font.render("Game Over!", True, "#3d5f9f", "silver")
restart_game_text = restart_game_font.render("Press 'p' to Play Again...", True, "#3d5f9f", "silver")

# Get Text Rect
title_text_rect = title_text.get_rect()
score_text_rect = score_text.get_rect()
lives_text_rect = lives_text.get_rect()
game_over_text_rect = game_over_text.get_rect()
restart_game_text_rect = restart_game_text.get_rect()

# Position the text
title_text_rect.center = (WINDOW_WIDTH / 2, 30)
score_text_rect.topleft = (10, 5)
lives_text_rect.topleft = ((WINDOW_WIDTH - lives_text.get_width() - 10), 5)
game_over_text_rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)
restart_game_text_rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + 90)
# load our images
aspen = pygame.image.load('images/aspen.png')
food = pygame.image.load('images/food.png')

# get rect surrounding our images
aspen_rect = aspen.get_rect()
food_rect = food.get_rect()

# Position our images
aspen_rect.center = (60, WINDOW_HEIGHT / 2)
food_rect.x = WINDOW_WIDTH + 100
food_rect.y = random.randint(65, (WINDOW_HEIGHT - food.get_height()))

while running:
# poll for events
# pygame.QUIT event means that the user clicked the X to close the window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# Pick the screen color
screen.fill("silver")

# Blit text onto screen
screen.blit(title_text, title_text_rect)
screen.blit(score_text, score_text_rect)
screen.blit(lives_text, lives_text_rect)

# Check if we're out of lives
if lives == 0:
# Game over text
screen.blit(game_over_text, game_over_text_rect)
screen.blit(restart_game_text, restart_game_text_rect)
# Stop The Food From Moving again
food_rect.x = 0
food_rect.y = 10000

# Check for p
keys = pygame.key.get_pressed()
if keys[pygame.K_p]:
# Update game start variables
score = 0
lives = 6
speed = 5

# Blit images onto screen
screen.blit(aspen, aspen_rect)
screen.blit(food, food_rect)

# Blit score unto screen
score_text = score_font.render(f"Score: {score}", True, "#3d5f9f", "silver")
lives_text = lives_font.render(f"Lives: {lives}", True, "#3d5f9f", "silver")

# Draw Line at top of the screen
pygame.draw.line(screen, "#3d5f9f", (0, 60), (WINDOW_WIDTH, 60), 2)

# Move Our Images
keys = pygame.key.get_pressed()

# Move Aspen
if keys[pygame.K_UP] and aspen_rect.y > 70:
aspen_rect.y -= 300 * dt
if keys[pygame.K_DOWN] and aspen_rect.y < WINDOW_HEIGHT - aspen.get_height() - 5:
aspen_rect.y += 300 * dt

# Move Food
if food_rect.x < 0:
# Aspen Missed the Food!
# Lose a life
lives -= 1
# Update Lives On Screen
lives_text = lives_font.render(f"Lives: {lives}", True, "#3d5f9f", "silver")
food_rect.x = WINDOW_WIDTH + 100
food_rect.y = random.randint(65, (WINDOW_HEIGHT - food.get_height()))
else:
# Move The food to the left
food_rect.x -= speed

# Check for collisions
if aspen_rect.colliderect(food_rect):
# Increase the score
score += 1
speed += 2
# Update Score Text
score_text = score_font.render(f"Score: {score}", True, "#3d5f9f", "silver")
food_rect.x = WINDOW_WIDTH + 100
food_rect.y = random.randint(65, (WINDOW_HEIGHT - food.get_height()))

# flip the display to output our work to the screen
pygame.display.flip()

# Set the clock stuff / delta time in seconds since the last frame
# used for framerate independent physics
dt = clock.tick(60) / 1000

pygame.quit()

Wednesday, November 29, 2023

Advanced

 Every once in a while, a little game is just the ticket. While St-Jean

is suffering from a water mains break, a little plumbing game from Mat is Fun:


                                                                



                                                               *     *     *

                                                                    

*     *     *

Went through another tutorial on styling Matplotlib, and researched a few things.

This should allow mw to improve yesterday's cross product grapher, something I haven't

seen a good version of on the web. The central problem, though, is that the third vector

can get quite long, and may be negative...

                                                                         


                                                                                  




                                                                                      

                                                                               *     *     *

                                                                             





                                                                         

Tuesday, November 28, 2023

Products

 Vectors, it will be recalled, have both length and direction. One can multiply one with the other

to find magnitude with the dot product. 



The result is a scalar. We are still in a 2D space and need the cos value to correct the

outcome as a function of orientation.





The cross product is something else: we are still multiplying the absolute length values,

but correcting with the sine function, and + or - orientation. The result here is a new

vector, but in a 3D space.

                                                                       


                                                                  








                                                                                 




import numpy as np

# Define the two vectors
vector1 = np.array([2, 3])
vector2 = np.array([-4, 5])

# Calculate the cross product
cross_product = np.cross(vector1, vector2)

# Print the result
print(cross_product)

import matplotlib.pyplot as plt
import numpy as np

# Define the vector
#vector = np.array([1, 2, 3])
vector = ([2, 3, 0])
vector1 = ([-4, 5, 0])
vector2 = ([0, 0, cross_product])


# Create a figure and axis object
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Draw the vector using quiver()
ax.quiver(0, 0, 0, vector[0], vector[1], vector[2], color='orange')
ax.quiver(0, 0, 0, vector1[0], vector1[1], vector1[2], color='red')
ax.quiver(0, 0, 0, vector2[0], vector2[1], vector2[2], color='black')

# Set the x, y, and z limits of the plot
ax.set_xlim([-5, 5])
ax.set_ylim([-5, 5])
ax.set_zlim([-5, 5])

# Add a grid to the plot
ax.grid(True)

# Show the plot
plt.show()

                                                                                  

*     *     *


                                                                                                


                                                                       

Monday, November 27, 2023

Silly_Q

 Monday morning, and time to get clear about electromotive force, which is energy

produced by electrons in a circuit and electromagnetic waves, which are field forces

travelling in space.


Me, asking a silly question...




Anatomy of an Electromagnetic Wave - NASA Science

In electromagnetic radiation, how do electrons actually "move"? - Physics Stack Exchange

                                                                *     *     *

How did I ever survive without AI:

                                                                      


                                                                                  



                                                                                  

                                                                                 




                                                                                    

Sunday, November 26, 2023

Silly!

 Microsoft is offering a new MSN experience, starting this morning. One gets to

customize which feeds one gets (I got rid of sports) as well as the look of the page.

I'm 'silly pink'😊

                                                                    

                                                                      *     *     *


Site has a nice video on transformers:



                                                                      *     *     *

Numpy for machine Learning 9, the very last one, is done. It is about how to filter

an array with Boolean lists, or conditions...

                                                                        





Saturday, November 25, 2023

Aspen_Game

 Pygame 9 is out for the week: there is a little game where one tries

to have the dog Aspen collide with the food bowl before it goes off-screen.

Pretty much used the code as given, although I chose the prettier pic of

Aspen, and the more colorful bowl. Also chose not to have the lives number

totally to the right. I find things more restful like this.

                                                          


Did wonder, though, about the writing text to screen code. What is that True

flag about. It turns out, it activates anti-aliasing and makes for a smoother image.

Also wondered why we are rendering text from Font(). Turns out this is a shortcut.

One could also do it from graphics, but it might be more work...

                                                                       



                                                                                 




Friday, November 24, 2023

Clarification_impedance

 A lady asked me about impedance; said it was not clear in her mind. In short,

resistance is what we find in a direct current DC, and impedance in alternating

current AC. And the formula for Ohm's Law is different in each case. In direct

current DC, current is equal to voltage divided by resistance. In alternating current

AC, current is the product of voltage multiplied by impedance!



                                                                              

                  

                                                                       *     *     *

So, in the case of a typical household the impedance of the circuit is not an issue,

but the performance rating of the wires is...

                                                                            

 
                                                                                    

                                                    

Huge

 A lot of drama in AI last week, as Sam Altman was ousted, joined Microsoft,

and now has returned to Open AI. According to The Economist, there were disagreenments

about 'safety' among board members. It is, undoubtedly, a HUGE issue...










Thursday, November 23, 2023

A_Cake

 A really easy recipe for AppleCake just appeared on my Facebook page. Might

make it this evening, and enjoy it warm:




One cuts up two small apples, and cooks them in butter in a pan. One then adds

the other ingredients, well-mixed. Cook 10 minutes on low heat. Flip (on a plate) and

cook the other side 5 minutes. Enjoy warm or cold...

Did a quick calorie count; makes 6,  200 calorie servings:

                                                                            




TG23

 It's American Thanksgiving, Make it Great 😺

                                                                  


*     *     *
In my wind down phase last night, decided to read through Ducksters" electricity for

kids. I've got the math down on the following problem:


                                                                                     


To check your answer:
                                                                                https://www.ducksters.com/science/physics/resistors_in_series_and_parallel.php


All Good! But one little section from the text was bothering me...

'Note that the total resistance is less than any of the resistors in parallel. This will always be the case. The equivalent resistance will always be less than the smallest resistor in parallel.'