Sunday, March 31, 2024

EWeek-End

 Spending Easter sunday on my own. No coffee, no chocolate. 

Daughter Lyse is enjoying a week-end in NYC. Lyse and friend Cynthia

went to the Museum of Ice Cream . From Facrbook:


                                            


Planning to go out for a walk. Might work on coding problems later on... might not 😄

It's a beautifull week-end!

Saturday, March 30, 2024

Friday, March 29, 2024

The Bic C

  Something of a first world problem, I know. Now that I am in a 30-day

no coffee stretch, I am going to have to celebrate Easter without chocolate. 

Because the coca bean also contains caffeine, albeit much less than the

coffee one. 


Dr Berg really alerted me on the coffee problem. Caffeine is something plants

produce to ward off bugs, paralyses and kills them so that the fruit can survive.

I am no bug, but it makes me look at things in a different light. That really is anxiety

I was feeling with my daily dose...





A medical student recounts his experience with caffeine withdrawl, a lot like what I

went through. This is why folks are counselled to cut back gradually and avoid those

awfull crashes. 

He also explains how addiction develops. Powerful stuff:



                                                     *     *     *

Codemy Aspen Platform4, Gravity is now out. The player now falls when off

thre grass tiles, at an accelerating rate ( the ability to jump is coming next).

                                                   

If the player falls in the water, the game ends, currently indicated with a print\

function:




import pygame
import self as self

#Define a 2d vector
vector = pygame.math.Vector2

#Initialize the game
pygame.init()

# Set display surface (divisible by 32 tile size)
WINDOW_WIDTH = 960 # 30 columns
WINDOW_HEIGHT = 640 # 20 rows
display_surface = pygame.display.set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
pygame.display.set_caption("Aspen Platformer - Codemy.com")

# Set FPS and clock
FPS = 60
clock = pygame.time.Clock()

# Tile Class
class Tile(pygame.sprite.Sprite):
# Read and Create tiles and put em on the screen
def __init__(self, x, y, image_integer, main_group, sub_group=""):
super().__init__()
# Load image and add to the tile subgroups
if image_integer == 1:
self.image = pygame.image.load('images/Brown.png')
elif image_integer == 2:
self.image = pygame.image.load('images/Green.png')
sub_group.add(self)
elif image_integer == 3:
self.image = pygame.image.load('images/Blue.png')
sub_group.add(self)

# add every tile to main tile group
main_group.add(self)

# Get rect of images and position within the grid
self.rect = self.image.get_rect()
self.rect.topleft = (x,y)

# Apsen Player Class
class Aspen(pygame.sprite.Sprite):
def __init__(self, x, y, grass_tiles, water_tiles):
super().__init__()
# Define our aspen image
self.image = pygame.image.load("images/P.png")
# Get rect
self.rect = self.image.get_rect()
# Position aspen
self.rect.bottomleft = (x,y)

#Define our grass and water
self.grass_tiles = grass_tiles
self.water_tiles = water_tiles

# Kinematic Vectors (x,y)
self.position = vector(x,y)
self.velocity = vector(0,0)
self.acceleration = vector(0,0)

# Kinematic Constants
self.HORIZONTAL_ACCELERATION = 2
self.HORIZONTAL_FRICTION = 0.20
self.VERTICAL_ACCELERATION = 0.5 #Gravity


def update(self):
# set initial acceleration to 0,0 to start
self.acceleration = vector(0, self.VERTICAL_ACCELERATION)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.acceleration.x = -1 * self.HORIZONTAL_ACCELERATION
if keys[pygame.K_RIGHT]:
self.acceleration.x = self.HORIZONTAL_ACCELERATION

# Calculate new Kinematics
self.acceleration.x -= self.velocity.x * self.HORIZONTAL_FRICTION
self.velocity += self.acceleration
self.position += self.velocity + 0.5 * self.acceleration

# update rect
self.rect.bottomleft = self.position

# Check for collisions with Grass
touched_platforms = pygame.sprite.spritecollide(self, self.grass_tiles, False) # Return a python list of tiles we touched
if touched_platforms:
self.position.y = touched_platforms[0].rect.top + 1
self.velocity.y = 0

# Check for collisions with Water
if pygame.sprite.spritecollide(self, self.water_tiles, False):
print("You Died!")




# Define our sprite groups
main_tile_group = pygame.sprite.Group()
grass_tile_group = pygame.sprite.Group()
water_tile_group = pygame.sprite.Group()
aspen_group = pygame.sprite.Group()


# Create a tile map, nested python list: 0=no tile, 1=dirt, 2=grass, 3=water, 4=aspen
tile_map = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[2,2,2,2,2,2,2,2,0,0,0,0,0,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1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,1,1,1,1,1]
]

# Create Tile objects from the tile map
# 2 for loops because tile map is nested. 20 i down
for i in range(len(tile_map)):
# loop through the 30 elements in each list, j across
for j in range(len(tile_map[i])):
# Check for 0,1,2,3
if tile_map[i][j] == 1:
# dirt
Tile(j*32, i*32, 1, main_tile_group)
elif tile_map[i][j] == 2:
# grass
Tile(j*32, i*32, 2, main_tile_group, grass_tile_group)
elif tile_map[i][j] == 3:
# water
Tile(j*32, i*32, 3, main_tile_group, water_tile_group)
elif tile_map[i][j] == 4:
aspen = Aspen(j*32, i*32 + 32, grass_tile_group, water_tile_group)
aspen_group.add(aspen)


# Add a background
bg_image = pygame.image.load('images/bg.png')
bg_image_rect = bg_image.get_rect()
bg_image_rect.topleft = (0,0)



# Game Loop
running = True
while running:
# Check to quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# fill the display or blit an image
# display_surface.fill("black")
display_surface.blit(bg_image, bg_image_rect)

# Draw the Tiles
main_tile_group.draw(display_surface)

# Update and draw sprites
aspen_group.update()
aspen_group.draw(display_surface)


# Update Display
pygame.display.update()
clock.tick(FPS)

# End the game
pygame.quit()

Interestingly, we keep track of the player by checking for sprite.collide() with the grass...

Thursday, March 28, 2024

Stellar

 I'm almost there: just registered with Stelvision for a daily view of

the night sky from my chosen location, Montreal. I'll be looking for Jupiter

at 9pm. 


There is also a animation feature on this map which rotates things backwards or 

forwards.


Last hurdle, getting clear on why North at the top also gives me West on the right.

Something to do with if North is on top for my map, then I am facing South... 

                                                       



Wednesday, March 27, 2024

Converters

 Synfig Studio offers a range of converters, which are very powerful

tools one can use when animating. In effect, converter is a bit of a misnomer

because one is here given an opportunity to add functionality. It might

take a while to assess everything one might do, but one can have fun along the way.


Important to remember, the conversion is not on the object in the layers panel

but on one of its properties.


 Below, I ask for convert on color and can change the colors of the gradient

without fiddling with anything (at frame 96). I also changed the opacity of the

image at frame 48 down to .6. At 96, I put it back to 1.000. Smooth...


Just right-click on color and choose convert.

                                                                    


                                                                              


           https://wiki.synfig.org/Convert                        



Tuesday, March 26, 2024

Two Paths

 Had a bit of a learning day for myself, today. I got clear on how to do

two different path operations: moving a ball on a path; drawing a path so

that it appears grdually...

Ball on path: one draws a path with the spline tool set to outline. On draws a

ball and then links the center of the ball with the path - with both layers selected - 

on a right click anywhere on the path:link to spline. One is then free to animate 

between the ball at the beginning of the path, 

and at the end. The ball will move along the path...

                                                     




The second way makes the path appear. To do this, one creates a path with the spline tool

set to advanced outline. One then uses the width handles tool ( normally used for

widening or reducing the width of a stroke). Here the stroke is always the same but

one takes the end extra point which appears for this effect and, with a right click, asks
 
for cusp to flat. The point is then moved to the end of the path to redefine it, and then

to the beginning right next to the starting point. One just plays the timeline and the

path appears...

                                                                               


                                                                  

                                                                                 
*     *     *

So I am two weeks in, on my no coffee (read caffeine) reset.

I am grateful for the idea: if coffee helped me through some mind-numbing

mathematics by concentrating my attention, no-coffee is currently getting

me through anxiety-creating coding problems. i am super-chill, and taking things

in small steps. It all gets done. Heck, I've even gone back to German case

declinations and doing better with that. Chill!!!


Monday, March 25, 2024

Generic

 One thing I did learn yesterday, and which will prove very useful, is how

to shift the entry to certain parameters to the Libray. When I open the Library

Tab where the time elements usually are, I can see my values and change them

at will. Thus, my widget is modifiable and reusable.


On rick-clics , say Text, in the properties panel and ask for export. One then 

enters the name of the parameter, and it will show up in the Libray with its 

current value, from which it can be changed...



Sunday, March 24, 2024

Metabolism

 Another advance in health monitoring, recommended by Dr Berg,

the ever_helpful chyropractor. One gets to see how one's body processes

foods and thus, the particuliarities of one's metabolism. From a team in

Athens, Greece:

https://www.drtsoukalas.com/new_patient-lp-2.html

                                                         *     *     *

Been playing with split text, from a tutorial by Khemardi (116):

                                                                   


Saturday, March 23, 2024

Messier

 One thing one often comes across when reading about celestial objects

is an M and number designation. It is a reference to the Messier catalogue.

Messier did not catalogue asterisms (portions of the sky), but actual objects.

Below, from Bing/Chat:                             



From Wikipedia:

                                                                                    

                                                          *     *     *


The band, Picnic, meant to be playing in Moscow:

Friday, March 22, 2024

Day 12

 End of day 12, month without coffee. Can't say I really crave the

taste of coffee. It's actuqlly rather bitter, and I drink it black except on

special occasiosn when I might drop some chocolate pieces in it, or order

a specialty coffee. But I do have moments in early afternoon where I

just can't sit in front of the computer and slog on.


I have found an odd remedy for this: housework. I can do a few hours of work 

on kitchen cabinets, wash some floors, do laundry, It just happens. Really odd 

when before, I had to pull mysef away from the computer to do virtually anything.

I may well have a presentable appartment by Easter.


I'm not allowing myself to think about what happens after the month is over. Just

going to get there...


Horizontal

 Codemy Pygame has added horizontal movement to Aspen Platform.

It is all done with 2d vectors, and we have position, velocity and acceleration.

Because everything is initiated at 0, movement is smooth...


                                               



The code:

import pygame
import self as self

#Define a 2d vector
vector = pygame.math.Vector2

#Initialize the game
pygame.init()

# Set display surface (divisible by 32 tile size)
WINDOW_WIDTH = 960 # 30 columns
WINDOW_HEIGHT = 640 # 20 rows
display_surface = pygame.display.set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
pygame.display.set_caption("Aspen Platformer - Codemy.com")

# Set FPS and clock
FPS = 60
clock = pygame.time.Clock()

# Tile Class
class Tile(pygame.sprite.Sprite):
# Read and Create tiles and put em on the screen
def __init__(self, x, y, image_integer, main_group, sub_group=""):
super().__init__()
# Load image and add to the tile subgroups
if image_integer == 1:
self.image = pygame.image.load('images/Brown.png')
elif image_integer == 2:
self.image = pygame.image.load('images/GReen.png')
sub_group.add(self)
elif image_integer == 3:
self.image = pygame.image.load('images/Blue.png')
sub_group.add(self)

# add every tile to main tile group
main_group.add(self)

# Get rect of images and position within the grid
self.rect = self.image.get_rect()
self.rect.topleft = (x,y)

# Apsen Player Class
class Aspen(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
# Define our aspen image
self.image = pygame.image.load("images/P.png")
# Get rect
self.rect = self.image.get_rect()
# Position aspen
self.rect.bottomleft = (x,y)

# Kinematic Vectors (x,y)
self.position = vector(x,y)
self.velocity = vector(0,0)
self.acceleration = vector(0,0)

# Kinematic Constants
self.HORIZONTAL_ACCELERATION = 2
self.HORIZONTAL_FRICTION = 0.20



def update(self):
# set initial acceleration to 0,0 to start
self.acceleration = vector(0)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.acceleration.x = -1 * self.HORIZONTAL_ACCELERATION
if keys[pygame.K_RIGHT]:
self.acceleration.x = self.HORIZONTAL_ACCELERATION

# Calculate new Kinematics
self.acceleration.x -= self.velocity.x * self.HORIZONTAL_FRICTION
self.velocity += self.acceleration
self.position += self.velocity + 0.5 * self.acceleration

# update rect
self.rect.bottomleft = self.position




# Define our sprite groups
main_tile_group = pygame.sprite.Group()
grass_tile_group = pygame.sprite.Group()
water_tile_group = pygame.sprite.Group()
aspen_group = pygame.sprite.Group()


# Create a tile map, nested python list: 0=no tile, 1=dirt, 2=grass, 3=water, 4=aspen
tile_map = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2],
[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2],
[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,2,2,2,2,2],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,1,1,1,1,1]
]

# Create Tile objects from the tile map
# 2 for loops because tile map is nested. 20 i down
for i in range(len(tile_map)):
# loop thru the 30 elements in each list, j across
for j in range(len(tile_map[i])):
# Check for 0,1,2,3
if tile_map[i][j] == 1:
# dirt
Tile(j*32, i*32, 1, main_tile_group)
elif tile_map[i][j] == 2:
# grass
Tile(j*32, i*32, 2, main_tile_group, grass_tile_group)
elif tile_map[i][j] == 3:
# water
Tile(j*32, i*32, 3, main_tile_group, water_tile_group)
elif tile_map[i][j] == 4:
aspen = Aspen(j*32, i*32 + 32)
aspen_group.add(aspen)


# Add a background
bg_image = pygame.image.load('images/bg.png')
bg_image_rect = bg_image.get_rect()
bg_image_rect.topleft = (0,0)



# Game Loop
running = True
while running:
# Check to quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# fill the display or blit an image
# display_surface.fill("black")
display_surface.blit(bg_image, bg_image_rect)

# Draw the Tiles
main_tile_group.draw(display_surface)

# Update and draw sprites
aspen_group.update()
aspen_group.draw(display_surface)


# Update Display
pygame.display.update()
clock.tick(FPS)

# End the game
pygame.quit()



This was news to me. Kinematics has the same Greek root as Cinematic, just the 

movement... From Bing/Chat:

You
Explain Kinematics to me.

Copilot

Kinematics is the branch of physics that describes the motion of objects without considering the forces that cause them to move. It focuses on the geometrically possible motion of bodies or systems of particles, providing a description of their spatial positions and how they change over time. In other words, kinematics helps us understand how things move, using tools like words, diagrams, graphs, mathematical equations, and numerical data123.

Here are some key terms related to kinematics:

  1. Scalars and Vectors: Scalars are quantities with only magnitude (e.g., distance), while vectors have both magnitude and direction (e.g., velocity).
  2. Distance and Displacement: Distance is the total length traveled by an object, while displacement is the straight-line distance from the initial to the final position.
  3. Speed and Velocity: Speed is the rate of change of distance, while velocity includes both speed and direction.
  4. Acceleration: Acceleration describes how quickly an object’s velocity changes.

Remember, kinematics provides the language and tools we use to describe and explain the motion of real-world objects. So, let’s dive into this fascinating field and explore the dynamics of movement! 🚀🌟


                                                                  *     *     *

I think there might be a homework assignment with this tutorial. That is getting a grasp

of why the update function defines position as:


 self.position += self.velocity + 0.5 * self.acceleration

I'll be working on this, today.


                                                           *     *     *

Asking Bard/Gemini for help:


                                                     


The explanation:


I'll explain how the update function works, particularly the kinematic equations within the Aspen class:

1. Key Input and Acceleration:

The function starts by checking for left or right key presses using pygame.key.get_pressed().

If a left key is pressed, the acceleration is set to a negative value (-1 * HORIZONTAL_ACCELERATION), causing the player to move left.

If a right key is pressed, the acceleration is set to a positive value (HORIZONTAL_ACCELERATION), moving the player right.

If neither key is pressed, the acceleration is initially set to 0.

2. Kinematic Equations:

Friction: The acceleration is adjusted to account for friction using self.acceleration.x -= self.velocity.x * self.HORIZONTAL_FRICTION. This slows down the player based on their current speed.

Velocity Update: The velocity is updated by adding the acceleration: self.velocity += self.acceleration. This changes the player's speed based on the acceleration being applied.

Position Update: The position is updated using the formula self.position += self.velocity + 0.5 * self.acceleration. This formula is based on the concept of "average acceleration" over a time step, ensuring smoother motion.

3. Rect Update:

After updating the position vector, the self.rect.bottomleft attribute is set to the new position. This ensures the player's sprite rectangle stays aligned with its actual position on the screen, allowing for proper collision detection and visual representation.

Key Points:

The game uses a fixed time step (presumably 1/60th of a second, as the FPS is set to 60).

The kinematic equations are simplified versions of real-world physics, but they are effective for creating smooth, controllable 2D movement.

The HORIZONTAL_ACCELERATION and HORIZONTAL_FRICTION constants directly affect the player's movement feel and can be adjusted to fine-tune the gameplay experience.