Tuesday, January 31, 2023

Card

                                                                  

So here we have linguistically gifted Turtle writing a greeting in a random

language. Pressing the up key moves him forward.


The program shows how class and super work together when one is passing

a class as an argument to another. super is the base class, ready to pass

on shape and color to the turtles class. Turtles will use these with self but

add a little something, here a message function, in a random language.


One could make some great cards using these tools.


from turtle import TurtleScreen, RawTurtle
from tkinter import*
import random
root = Tk()
c1 = Canvas(root, width= 300, height=400)
c1.pack()
screen = TurtleScreen(c1)
screen.bgcolor('sky blue')

def go():
t1.forward(130)

class turtle(RawTurtle):
def _init_(self, shape, color, message):
super().__init__(shape, color)
self.master = 'screen'
self.shape = 'turtle'
self.color = color
self.message = message

my_list = ['Hello!', 'Bonjour!', 'Guten Tag!', 'Hola!']
message = random.choice(my_list)

t1 = turtle(screen)
t1.shape('turtle')
t1.color('blue', 'red')
t1.pu()
t1.goto(-20, 30)
t1.pd()
t1.write(message, font=('Ink_Free', 20, 'bold'))
t1.pu()
t1.backward(50)

screen.onkey(fun=go, key="Up")
screen.listen()
root.mainloop()

screen.exitonclick()

Monday, January 30, 2023

Moles

 I've looked at this table of conversions, but was never

able to really make sense of what was going on. Until

today, that is. Had another 'middle of the night' session

on the computer and cracked it. ( I knew the molecular weight

of water was 18, but this table was off by a factor of ten!!)

Long story short, the molecular weight of glucose is - by coincidence, 

to me -180. So yes, the weight of sugar is ten times that of water, thus

on a table of solute weights, the difference between the two is a 

factor of 18. Sugar molecules weigh more on the dance floor.


To recap:

There are two measures of blood sugar concentration, one

uses moles and the other grams. The first is the scientific one,

used in the UK and Canada; the other the popular one, used in the US

and European countries. Molarity  is a convenience mesure meant

to link the work of chemists and a human-scale experience of weight.  

One mole represents  6.02214076×10^23 positive entities: molecules,

atoms or ions.


And this solved it for me; a proton is 1 dalton (an unofficial but widely used

measure). H2O comes in at 18 because O is good for 16(8 protons and 8 neutrons)

and the two H count for 1 each (Because it is water,  positive ions are

active...) A dalton is known as the universal unit.


                                                           


https://www.joslin.org/patient-care/diabetes-education/diabetes-learning-center/conversion-table-blood-glucose-monitoring

                                                              *     *     *

                                                                                 


                                                                                



How Was Avogadro's Number Determined? - Scientific American


Avogadro’s Number | Definition & Units | Britannica


                                                               *     *     *

Doing the math: an average person might have 5 liters of blood in circulation.

Given a reading of 100mg/DL (5.5 mmol/L), which is a reasonable fasting level,

a person would have 1000mg/L or one gram of 'sugar' per liter of blood in their body.

For 5 liters, this amounts to 5 grams, or approximately one teaspoon. Not that much, and 

the brains gets served first...

                                                               


                                                                      

                                   

                                                                              


Thus, a glucose injection is hypotonic.

                                                          *     *     *

Now mass producing turtles from a class:

                                                                        



Sunday, January 29, 2023

Piece O' Cake

 Still have to declutter the code, which was the whole oint to begin with...

                                                             


rom turtle import TurtleScreen, RawTurtle
from tkinter import*

root = Tk()
root.geometry('600x700')
c = Canvas(root, height=320, width=300)
c.grid(column=0, row=0, sticky=N)
my_screen = TurtleScreen(c)
my_screen.bgcolor('pink')
my_screen.bgpic("AngelC(1).gif")

c1 = Canvas(root, height=320, width=300)
c1.grid(column=0, row=0, sticky=S)
my_screen1 = TurtleScreen(c1)
my_screen1.bgcolor('orange')
my_screen1.bgpic("MadeIt.gif")

c2 = Canvas(root, height=600, width=300)
c2.grid(column=1, row=0, sticky = N)

my_screen2 = TurtleScreen(c2)
my_screen2.bgcolor('khaki')
my_screen2.bgpic("Arecette.gif")

c3 = Canvas(root, height=50, width=300)
c3.grid(column=1, row=0, sticky = S)
my_screen3 = TurtleScreen(c3)
my_screen3.bgcolor('sky blue')


class Squares(RawTurtle):
def _init_(self):
super().init(self)

t1 = Squares(my_screen, 'turtle')
t1.width(3)
t1.pu()
t1.goto(-140,120)
t1.pd()
t1.pencolor('red')
t1.fillcolor('green')
t1.write("ANGELFOOD CAKE", font=("Verdana",
15, "normal"))

t2 = Squares(my_screen, 'square')
t2.width(3)
t2.color('green')
t2.pencolor('red')
t2.pensize(2)
t2.pu()
t2.goto(-150,-100)
t2.pd()
t2.forward(290)

t3 = Squares(my_screen1, 'turtle')
t3.width(3)
t3.pu()
t3.goto(-140,130)
t3.pd()
t3.pencolor('brown')
t3.fillcolor('green')
t3.write("MADE IT", font=("Verdana",
15, "normal"))

t4 = Squares(my_screen1, 'triangle')
t4.width(3)
t4.color('teal')
t4.pencolor('brown')
t4.pensize(2)
t4.pu()
t4.goto(-150,-130)
t4.pd()
t4.forward(287)
t5 = Squares(my_screen3, 'turtle')
t5.width(3)
t5.color('coral')
t5.pencolor('brown')
t5.pensize(2)
t5.pu()
t5.goto(-150,-10)
t5.write('3/4 cups flour; .4 cups cornstarch; \n 5 eggs; 2/3 cups sugar, lemon peel', font=("Verdana",
8, "normal"))

t5.forward(287)
root.mainloop()


Saturday, January 28, 2023

Context

 Re yesterday's example. I have redone the screen to use cavas on tkinter. 

Here's the thing:

One would work from turtle classes in the context of a wider app. The version below

draws a canvas on a root window (with root on mainloop at the bottom). 

                                                                     


*     *     *

Hard at work on a recipe app: 
                                                                     
                                                                          
*     *     *



Recettes Simples Et Faciles | Le gateau des anges | Facebook


Had a go at making this. An Angelfood cake might be made

entirely with egg whites; this one keeps the egg yolks. Still, there are

no fats..

Friday, January 27, 2023

With_Class

 Learning to use turtle as an add-on to a tkinter project:

                                                     



from turtle import TurtleScreen, RawTurtle

import turtle

my_screen = turtle.Screen()
my_screen.bgcolor('pink')

class Squares(RawTurtle):
def _init_(self):
super()._init_(self)

t1 = Squares(my_screen, shape = 'circle')
t1.width(3)
t1.forward(50)

t2 = Squares(my_screen, shape='square')
t2.width(3)
t2.color('green')
t2.backward(75)

my_screen.mainloop()

Thursday, January 26, 2023

Procedural

 The current version of Python allowd for two ways to use turtle: procedural

and Object oriented. An example of procedural, below. Note, there is one turtle

and the heavy lifting is done by a function.


import turtle
import random
# setting the initial turtle
my_screen = turtle.Screen()
my_t = turtle.Turtle()
my_t.hideturtle()
my_t.pu()
my_t.goto(0, -100)
my_t.shape('circle')
my_t.showturtle()

# the function which creates dots of various sizes and colors
def dotty(x, y):

my_t.goto(x, y)
my_colors = ['slate grey', 'crimson', 'sky blue']
my_t.color(random.choice(my_colors))
my_r = random.randrange(1, 5)
print(my_r)
my_t.turtlesize(my_r)
my_t.stamp()
my_t.hideturtle()
return

#calling the function, and updating the screen
my_screen.onclick(dotty)
my_screen.update()

#keeping the window open
my_screen.mainloop()

Tomorrow, will show an OOP use of Turtle.

Wednesday, January 25, 2023

Worried

 This shapeshifter conflict in Ukraine has just gone up another notch

with the general decision to start sending the very latest tanks from

NATO countries into the arena. Everybody is smiling and brotherly in the news

now that we have a decision. Is there no one prepared to ask a few questions

about all this.


I actually googled this one. 'Is Ukraine about to run out of soldiers.' Just

asking, because if/when it does; what happens next. I am not the only concerned one.

As early as last summer, expert opinion had it that Ukraine had entered a zone of

being totally reliant on the West with respect to both the economy and military procurement.

And - for a dying man - President Putin seems to be making some pretty tight

proclamations. The one that impressed me, on the nuclear question:'We are not insane'.

Thank God! Send me the t-shirt.


One gets the impression that, even if the leadership in the US and elsewhere changes,

military decisions might not. Am I imagining this. Even in the face of a new Repubican House,

President Biden just allocated large sums to Ukrainian Defense. How is that giong to happen.


More incendiary rambling from the Russians: they now consider that they are primarily

fighting yes, NATO, but the US and Britain in particular. Interestinly, France has fought

Russia in the past (it didn['t end well for Napoleon) but the anglophone world has not.

Russia, for its part, has fought the West quite a few times, and made it through. The

West may be preparing its victory speech, but Russia has an agenda of it's own. This does

not make for general and unworried accord with current orientations.


Perso, I'd give Russia an exit ramp; each and every step of the way.

                                            *     *     *


Bank rate went up another .25 in this morning's annoucement by the Bank

of Canada, putting the 'taux diecteur' at 4.5%. They expect to hold at this level

for some time:

Bank of Canada says it can pause rate hikes as inflation set to ‘decline significantly’ - National | Globalnews.ca

Yeast

 I woke up in the middle of the night, and spent two hours going

back and forth and between languages in Wikipedia. I think

I have finally done it: given myself an overview of the terrain in 

biochemistry. I've wanted to do this for a long time but have

always been put off by all those terms, concepts and complicated

diagrams. 


I've found a way in: alcohol, the topic: fermentation. the

researcher: Pasteur in the mid 19th century who published "...About Beer". 

But first, one needs to go back to an earlier scientific mind, the German

Theodor Schwann(1810-1882), who developed very powerful microscopes.

He recognized that fermentation was the work of tiny organisms

'whose structures resembled those of plants'. He coined the term

metabolism.


Building on this, Pasteur found that fermentation needed to occur in the

abscence of oxygen. Today we recognize that it is a method to get energy

from molecules, and the oldest metabolic pathway on Earth, dating back

to a time when there was no oxygen. Eduard Buchner(1860-1917)

won a Nobel Prize in 1917 for showing it was a substance produced by yeast

that caused fermentation, in effect enzymes.


A yeast is a 'mushroom' that reproduces by budding.

                                                    




Tuesday, January 24, 2023

Vanity



 https://youtu.be/vEqRC3pnJvE


Let's take a moment to appreciate this wonder. It is

now possible to see, in close to real time, one's glucose reading.

Different from a medical test from actual blood by 10%

at most. The technology to do this is from Dexcom, based in San Diego

California. 


The test mechanism, on the person's arm, sends the data to an app

on the iphone. An app on the Applewatch receives, and shows it.

It is a trend line. A tap on the watch and there it is.


Apple has been promising direct reading of glucose from the watch itself,

without invasive procedures. It is a much awaited feature, and the company has

apparently taken a patent on a technology to do this, already. I do see, however,

how there might be some apprehension about moving ahead with this:

fitness is one thing, and medical treatment another. Could this feature lead to frivolous 

uses, or endanger some patients. I would hope not.


In fact, I would see this as a very useful development. Take the pizza problem, as it

confronts someone with diabetes1. Pizza is a carbohydrate food, and requires an insulin

injection before ingestion. All fine and good. But then, hours later glucose readings go up

again, and who knows what is going on. Pizza also contains fat from the cheese.

I would expect that with many 'vanity' users using this feature, we woud soon

find out.


It takes a few hours for fats to leave the stomach for the small intestine. What happens 

next will depend on whether your body is trying to find quick energy, seeking to restore 

glycogen in muscle for easy access, or willing to send it to long-term storage. As someone

who goes out in sub-zero tempratures for a quick shop, I have some ingtuitive grasp

on how my diet helps or hinders my activities. I just know I could get really good at

gauging what is going with me as a function of diet and activity.


Monday, January 23, 2023

FForest

 Back to Turtle, and the full code for the fractal forest.

Been playing with yhe color choices...

                                                                


from turtle import *
from random import *
screen = Screen()
screen.bgcolor('Misty Rose2')

t1 = Turtle()
t2 = Turtle()
t3 = Turtle()
t4 = Turtle()
t5 = Turtle()

x = -200
turtles = [t1,t2,t3,t4,t5]
for t in turtles:
t.speed(100)
t.left(90)
t.color('sienna1')
t.pu()
x += randint(80,160)
t.goto(x, randint(-100,10))
t.pd()


def branch(turt, branch_len):
angle = randint(22,30)
sf = uniform(0.6,0.8)
size = int(branch_len /10)
turt.pensize(size)
if branch_len < 20:
turt.color('spring green')
turt.stamp()
turt.color('sienna1')

if branch_len > 10:
turt.forward(branch_len)
turt.left(angle)
branch(turt, branch_len*sf)
turt.right(angle*2)
branch(turt, branch_len*sf)
turt.left(angle)
turt.backward(branch_len)

for t in turtles:
branch(t,100)

exitonclick()


To access the code, click Show Files:

https://replit.com/@SanjinDedic/forrestFractalTrees


                                                   *     *     *

Surely not a coincidence. The 72 year old man who created havoc at events for the 

Chinese New Year might have been born in1950, a Year of the Tiger ending on

January 22, 2023. Or might have been born early 1951, and thus a Rabbit, like the

coming year. 


In the first case, a tiger is a natural leader and very brave. He dispenses justice.

A rabbit is very outgoing. If we are in a person's birth sign year, they are expected

to take the initiative.


Either way...

                                                           *     *     *

https://www.independent.co.uk/news/world/americas/crime/monterey-park-shooting-shooter-huu-can-tran-b2267871.html


Sunday, January 22, 2023

Lipedema

 I have been following, for some time, the story on lipedema, a fat

metabolism problem that affects primarily women. The latter can accumulate

large amounts of deformed fat in the lower body, which no amount of

conventional dieting can get rid of. Strikingly, some 10% of women are

now said to be suffering from ths condition, something quite unheard of in my

youth. So what could be going on, here.


I think I might have a clue. Below, a description of the mechnism of formation

of lipedema ie 'watery fat'.

                                                             

There it is, enlarged fat cells; cells that are gorged with fat. I remember reading that one

has all the fat cells one is ever going to have by adolescence; one cannot create anymore. 

These women must have gained weight in adulthood and strained to store it all. This

would be consistent to higher numbers with this condition in an aging poulation. And these

women then enter the vicious cycle of dieting and discouragement which only makes things 

worse.


In Europe, women who reach an obesity level BMI of 40 and have symptoms of lipedema are

told to get weight loss surgety. But care is taken to incorporate lipdema treatment

at the same time.

Learn More About Bariatric Surgery in Lipedema Patients | Lipedema


Knowledge is power, ladies!




Debt Drama

 The debt ceiling problem in the US will surely ge resolved before the true 

deadline, which is in June,; but 2023 will be a more difficult year than the

Markets are wishing for.

https://news.harvard.edu/gazette/story/2023/01/forget-debt-ceiling-drama-there-are-bigger-likelier-problems/

                                                         *     *     *


https://www.newyorker.com/magazine/2023/01/23/kevin-mccarthy-and-the-republicans-rocky-road-ahead

Saturday, January 21, 2023

Small Tree

Keeping in mind that computers keep session information in stack structures:

 https://youtu.be/NKmasqr_Xkw

                                                 *     *     *

Running the initial branch() at 40; yields a smaller tree. One can see

the stack being run through at the very end of the program.


Or, going forward in debug mode (without Snoop). Useful to click on shos execution.

One can run through the program with the step over button...

                                                        



Friday, January 20, 2023

Debugger

 Installed Bandicam screen recorder, and sarted working with the

debugger in PyCharm, to better see how the code in our fractal tree runs.

Below, run1:


                                                    


The red dots are the breakpoints on the debugger, asking the program to stop.

Here, I've ended up just running 'stepover' continuously. One gets to see how it is

always the first function, with a decreasing length variable, that runs over and over

until the condition is met. 


We are then forced to backtrack - in green - with serial attemps to go forward again...

                                                      *     *     *

I was asked to explain why the tree only branches in twos. This eventually led me

to download a very powerful tool to look at the execution of the code. It is called

Snoop; can be installed with pip, and run with an import statement and a snoop decorator.

The output is what happens at every step of the code...


                                                                 


                                                                                


Thr clue to th whole thing seems to that - once the condition is triggered - control 

goes back to the lst call to the branch function, which is then stepped over!

Thursday, January 19, 2023

One_More

 More code to play with on the fractal tree problem. It does one run in black, then changes to magenta, 

then cyan, and goes backward in green!!

 https://youtu.be/qnx_NCgVZ14                                                              



from turtle import*
goto(0, -100)
pensize(2)
speed(1)
left(90)

def branch(branch_len):
if branch_len>10:
color('black')
angle=30
forward(branch_len)
left(angle)
color('magenta')
branch(branch_len*0.7)
right(angle*2)
color('cyan')
branch(branch_len * 0.7)
left(angle)
color('green')
backward(branch_len)

branch(100)

Wednesday, January 18, 2023

Alcohol

 We seem to be in the midst of a rather odd debate about

drinking alcohol and health. The most recent health guidelines recommend

as litte alcohol as possible, with risk increasing with quantity. There is

no safe level of alcohol consumption.


What strikes me about this discussion is what is missing. Dionysus was the god

of the wine harvest in Antiquity, and the revelries of the non-harvest season

were party season, and also laid the ground for theater and the arts...

          for mortals from their pains

          you have opened a haven without toils.


Striking again in all this is the quantities quibble: better none, one glass for

women, two for men.


No one in Antiquity would have drunk wine without an admixture of water.

Three parts water to one part wine. Not following this rule could lead to

violent behaviour, and even death.(Do say!!) Even those beer-making monks

in the Middle Ages were drinking beer ten times less strong than what

we are sold today!


Finally, there is the reference of both sides of the debate to the American

Guidelines, toutes as most informed. What strikes me about those is they are in 

very simple language, and come in a Spanish version. Below:

Facts about moderate drinking | CDC


Alcohol doesn't change, but the composition of the population does. Folks are older,

and many are from different cultures and traditions.


Voilà. I have had my say on the matter.

                                                         *     *     *


Recursion

 Another day, another problem. The little tree below is

done through recursion. Trying to follow the code...                       

                    



mport turtle
screen = turtle.Screen()
screen.setup(500, 500)
class TreeNode(object):
def __init__(self, val, left=None, right: object = None):
self.val = val
self.left = left
self.right = right
from turtle import *

reset()
color("green")
speed(2)
seth(90)
shape('turtle')

def tree(size):
if size < 10:
return
fd(size)
lt(30)
tree(size * 0.6)
color('hotpink')
rt(60)
tree(size * 0.6)
color('blue')
lt(30)
bk(size)

tree(100)
turtle.mainloop()
I've even tried changing the code :

Or again:



Teaching Kids Programming – Draw a Tree in Python using Turtle Graphics (Recursion) | Algorithms, Blockchain and Cloud (helloacm.com)

Tuesday, January 17, 2023

Dec_CPI

 Canada's CPI numbers for December, 2022 are out. The raw numbers:

https://www150.statcan.gc.ca/t1/tbl1/en/tv.action?pid=1810000401          

                                                     *     *     *

We should be going back to El Nino conditions next summer (warmer

waters in the Pacific). 2024 threatens to be extremely hot and dry!!    

Warning of unprecedented heatwaves as El Niño set to return in 2023 | El Niño southern oscillation | The Guardian                  

                                                        *     *     *

Finally got my generator function; it is a fast way to construct an iterator:

                                                                 





                                                                          *     *     *

Below, a rendering of the tree code with the code as given:

                                                            

Here, I have upped sizedist to 15. A bit of chaos on branching...



                                                                      
Here, I have changed angledist to 20. Tree number 2  -at left - is in trouble...

                                                                             

Changed tree2 to .2 on width factor, and mae it a larger tree. Noteworthy, as well, Tree2 does not have 

an option for a straight up branch, ie a 0 angle change...






Monday, January 16, 2023

Distance

 California dangerous:  

                                                                       


*     *     *


                                                                              


                                                                            


                                                                     


Will be trying for a full force generator function, tomorrow...

Sunday, January 15, 2023

Soup

So, we have just entered the long, and cold part of winter, where we stay below

the freezing point night and day. Decided to go for comfort food and tried my hand at

making pea soup from scratch, yesterday, in the crock pot. It is a long process, because

the peas perform better if they are soaked in water before use. I soaked these for six

hours yesterday. Then made the soup, four hours, at high setting, in the crock pot.



                                                                                    
               

                                                                                   


I am keeping parsley in the fridge, and will be trying my creation later this afternoon...

                                                                          *     *     *

Found some reaaly funcode fordrawing cartoon trees with turtle. One ends up with three 

slightly different threes at each run:


                                                                


The code:

from turtle import Turtle, colormode, tracer, mainloop
from random import randrange
from time import perf_counter as clock

def symRandom(n):
return randrange(-n,n+1)

def randomize( branchlist, angledist, sizedist ):
return [ (angle+symRandom(angledist),
sizefactor*1.01**symRandom(sizedist))
for angle, sizefactor in branchlist ]

def randomfd( t, distance, parts, angledist ):
for i in range(parts):
t.left(symRandom(angledist))
t.forward( (1.0 * distance)/parts )

def tree(tlist, size, level, widthfactor, branchlists, angledist=10, sizedist=5):
if level > 0:
lst = []
brs = []
for t, branchlist in list(zip(tlist,branchlists)):
t.pensize( size * widthfactor )
t.pencolor( 255 - (180 - 11 * level + symRandom(15)),
180 - 11 * level + symRandom(15),
0 )
t.pendown()
randomfd(t, size, level, angledist )
yield 1
for angle, sizefactor in branchlist:
t.left(angle)
lst.append(t.clone())
brs.append(randomize(branchlist, angledist, sizedist))
t.right(angle)
for x in tree(lst, size*sizefactor, level-1, widthfactor, brs,
angledist, sizedist):
yield None


def start(t,x,y):
colormode(255)
t.reset()
t.speed(0)
#t.hideturtle()
t.left(90)
t.penup()
t.setpos(x,y)
t.pendown()

def doit1(level, pen):
pen.hideturtle()
start(pen, 20, -208)
t = tree( [pen], 80, level, 0.1, [[ (45,0.69), (0,0.65), (-45,0.71) ]] )
return t


def doit2(level, pen):
pen.hideturtle()
start(pen, -135, -130)
t = tree( [pen], 120, level, 0.1, [[ (45,0.69), (-45,0.71) ]] )
return t

def doit3(level, pen):
#pen.hideturtle()
start(pen, 190, -90)
t = tree( [pen], 100, level, 0.1, [[ (45,0.7), (0,0.72), (-45,0.65) ]] )
return t

# Hier 3 Baumgeneratoren:
def main():
p = Turtle()
p.ht()
tracer(75,0)
u = doit1(6, Turtle(undobuffersize=1))
s = doit2(7, Turtle(undobuffersize=1))
t = doit3(5, Turtle(undobuffersize=1))
a = clock()
while True:
done = 0
for b in u,s,t:
try:
b.__next__()
except:
done += 1
if done == 3:
break

tracer(1,10)
b = clock()
return "runtime: %.2f sec." % (b-a)

if __name__ == '__main__':
main()
mainloop()


It's like a puzzle, trying to understand what each part of the code does.

Have learned a few things so far. From where the pen goes, doit1 is the tree in the middle, doit2,

that on the left, doit three, the one on the right.

                                                                 



                                                                         


Level influences color.

...Trying to find the levers to change the behavior of the code!!


https://www.simplilearn.com/tutorials/python-tutorial/yield-in-python#:~:text=The%20Yield%20keyword%20in%20Python%20is%20similar%20to%20a%20return,of%20simply%20returning%20a%20value.