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:
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:
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...
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,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],
[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,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 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()
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...
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
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...
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...
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):
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:
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...
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...
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()
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:
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.