Sunday, December 26, 2021

How to Schedule Automatic Backups of your Google Sheets


Code:

function archiveCopy() {
var file= DriveApp.getFileById("");
var destination= DriveApp.getFolderById("");

var timeZone=Session.getScriptTimeZone();
var formattedDate= Utilities.formatDate(new Date(),timeZone,"yyyy-MM-dd' 'HH:mm:ss");
var name= SpreadsheetApp.getActiveSpreadsheet().getName()+"Copy"+formattedDate;


  file.makeCopy(name,destination);
  
}

Monday, December 13, 2021

Python / Turtle: draw a heart


Code:

# importing package:allows us to use the turtles library
import turtle
# make screen object
sc = turtle.Screen()
# and set size
sc.setup(400,400)
#create a turtle named t
t=turtle.Turtle()
#Picks up the turtle’s Pen
t.penup()
#Move the turtle to position x,y
t.goto(0,-100)
#Puts down the turtle’s Pen
t.pendown()
# Changes the color of the turtle’s pen
t.color("red")
# Changes the color of the turtle will use to fill a polygon
#t.fillcolor('red')
#Remember the starting point for a filled polygon
t.begin_fill()
#Turns the turtle counterclockwise
t.left(50)
#tell turtle to move forward by 120 units
t.forward(120)
# draw a semicircle
t.circle(45,200)
#Turns the turtle counterclockwise
t.left(220)
# draw a semicircle
t.circle(45,200)
#tell turtle to move forward by 120 units
t.forward(120)
#Close the polygon and fill with the current fill color
t.end_fill()
# hide the turtle
t.hideturtle()

Sunday, December 12, 2021

Microbit: Pacman


 Code:

hero = game.create_sprite(22)
food = game.create_sprite(44)
ghost = game.create_sprite(00)
ghost.change(LedSpriteProperty.BLINK, 100)
ghost.set(LedSpriteProperty.BRIGHTNESS, 10)
food.set(LedSpriteProperty.BRIGHTNESS, 5)
while True:
    basic.pause(400)
    if ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X):
        ghost.change(LedSpriteProperty.X, 1)
    elif ghost.get(LedSpriteProperty.X) > hero.get(LedSpriteProperty.X):
        ghost.change(LedSpriteProperty.X, -1)
    elif ghost.get(LedSpriteProperty.Y) < hero.get(LedSpriteProperty.Y):
        ghost.change(LedSpriteProperty.Y, 1)
    elif ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y):
        ghost.change(LedSpriteProperty.Y, -1)
    if input.acceleration(Dimension.X) > 200:
        hero.change(LedSpriteProperty.X, 1)
    elif input.acceleration(Dimension.X) < -200:
        hero.change(LedSpriteProperty.X, -1)
    if input.acceleration(Dimension.Y) > 200:
        hero.change(LedSpriteProperty.Y, 1)
    elif input.acceleration(Dimension.Y) < -200:
        hero.change(LedSpriteProperty.Y, -1)
    if hero.is_touching(food):
        game.add_score(1)
        food.set(LedSpriteProperty.X, randint(05))
        food.set(LedSpriteProperty.Y, randint(05))
        if food.get(LedSpriteProperty.X) < 2 and food.get(LedSpriteProperty.Y) < 2:
            ghost.set(LedSpriteProperty.X, 4)
            ghost.set(LedSpriteProperty.Y, 4)
        elif food.get(LedSpriteProperty.X) > 2 and food.get(LedSpriteProperty.Y) < 2:
            ghost.set(LedSpriteProperty.X, 0)
            ghost.set(LedSpriteProperty.Y, 4)
        elif food.get(LedSpriteProperty.X) < 2 and food.get(LedSpriteProperty.Y) > 2:
            ghost.set(LedSpriteProperty.X, 4)
            ghost.set(LedSpriteProperty.Y, 0)
        else:
            ghost.set(LedSpriteProperty.X, 0)
            ghost.set(LedSpriteProperty.Y, 0)
    if hero.is_touching(ghost):
        game.game_over()
ghost.set(LedSpriteProperty.X, 4)



Python / Turtle: Draw a house


 Code:

import turtle
import math

# Set the background color
screen = turtle.Screen()
screen.bgcolor("skyblue")

# Create your turtle
hay = turtle.Turtle()
hay.color("black")
hay.shape("turtle")
hay.speed(10)

# Define a function to draw and fill a rectangle with
# dimensions and color are given.
def dessinerRectangle(t, largeur, hauteur, couleur):
  t.fillcolor(couleur)
  t.begin_fill()
  for i in range(2):
      t.forward(largeur)
      t.left(90)
      t.forward(hauteur)
      t.left(90)
  t.end_fill()


# Define a function to draw and fill an isosceles right triangle
# with the length of the hypotenuse and the color are given.
def dessinerTriangle(t, longueur, couleur):
  t.fillcolor(couleur)
  t.begin_fill()
  t.forward(longueur)
  t.left(135)
  t.forward(longueur / math.sqrt(2))
  t.left(90)
  t.forward(longueur / math.sqrt(2))
  t.left(135)
  t.end_fill()

# Define a function to draw and fill a parallelogram,
# with dimensions and color are given.
def dessinerParallelogram(t, largeur, hauteur, couleur):
  t.fillcolor(couleur)
  t.begin_fill()
  t.left(30)
  t.forward(largeur)
  t.left(60)
  t.forward(hauteur)
  t.left(120)
  t.forward(largeur)
  t.left(60)
  t.forward(hauteur)
  t.left(90)
  t.end_fill()



# Draw and fill the front of the house
hay.up()
hay.goto(-150, -120)
hay.down()
dessinerRectangle(hay, 100, 110, "blue")

# Draw and fill the front door
hay.up()
hay.goto(-120, -120)
hay.down()
dessinerRectangle(hay, 40, 60, "orange")

# Roof of the house
hay.up()
hay.goto(-150, -10)
hay.down()
dessinerTriangle(hay, 100, "magenta")

# Side of the house
hay.up()
hay.goto(-50, -120)
hay.down()
dessinerParallelogram(hay, 60, 110, "green")

# Window
hay.up()
hay.goto(-30, -60)
hay.down()
dessinerParallelogram(hay, 20, 30, "orange")

# Roof side
hay.penup()
hay.goto(-50, -10)
hay.pendown()
hay.fillcolor("magenta")
hay.begin_fill()
hay.left(30)
hay.forward(60)
hay.left(105)
hay.forward(100 / math.sqrt(2))
hay.left(75)
hay.forward(60)
hay.left(105)
hay.forward(100 / math.sqrt(2))
hay.left(45)
hay.end_fill()



Python / Turtle: Palestinian Flag



Code:

# Palestinian flag
from turtle import*
setup(800,400)
speed(0)
penup()
goto(-400,200)
pendown()

#black rectangle
color("white")
begin_fill()
forward(800)
right(90)
forward(133)
right(90)
forward(800)
right(180)
end_fill()

#white rectangle
color("white")
begin_fill()
forward(800)
right(90)
forward(133)
right(90)
forward(800)
right(180)
end_fill()

#green rectangle
color("white")
begin_fill()
forward(800)
right(90)
forward(133)
right(90)
forward(800)
right(180)
end_fill()

#red triangle
color("red")
begin_fill()
goto(-200,15)
left(318)
forward(-400)
end_fill()


 

Python / Turtle: Algerian Flag


Code:

from turtle import*
setup(800,400)
width = 800
height = 400

up()
goto(-width//2, height//2)
down()
color("green")
begin_fill()
for i in range(4):
    fd(width//2)
    right(90)
end_fill()

up()
goto(0, height//2)
down()
color("white")
begin_fill()
for i in range(4):
    fd(width//2)
    right(90)
end_fill()


color("red")
left(120)
up()
goto(65, 40)
down()
begin_fill()
circle(80, 300)
right(10)
circle(61, -285)
end_fill()
up()

goto(0, 10)
down()
setheading(0)
right(15)
begin_fill()
for i in range(5):
    fd(40)
    right(144)
end_fill()
hideturtle()

Thursday, December 9, 2021

Micro:bit braille text messaging | Send and Receive


The project consists of a gadget that enables blind people to exchange texts using the brail method, it combines two parts. The first part is the sender; a Brail keyboard that enables them to write a word, then send it via radio technology. It also has the option of cancelling the message. To make this exchange possible, we have used three microbit cards because the number of connectors in each card is insufficient to construct a full keyboard; every alphabetic character has an equivalent in the Brail keyboard, which is linked to a mini micro lockless button. This button has two connectors, one is linked to GND, the other to the pin in the microbit.

 

The second part is concerned with the reception of the text message; the constructed gadget enables the receiver to read the word letter by letter, based on a matrix composed of six mini solenoids push pull 5 Volts. For example, if the character is “B”, we activate the two solenoids linked to pin 14 and pin 1. We used a specific button to go from one character to another. We should note that it is possible to read full words if we had the means to install five receptive matrixes instead of one. We also used one more optional microbit that shows the received text in alphabetical letters.