Skip to content

Instantly share code, notes, and snippets.

View ssaurel's full-sized avatar

Sylvain Saurel ssaurel

View GitHub Profile
@ssaurel
ssaurel / India_Map_Step_2.html
Created January 7, 2024 14:04
India Map Step 2 on SSaurel's Blog
<!DOCTYPE html>
<html lang="en">
<head>
<title>India Interactive SVG Map on the SSaurel's Blog</title>
<style type="text/css">
#title {
font-size: 25px;
fill: black;
@ssaurel
ssaurel / India_Map_Step_1.html
Created January 7, 2024 13:56
India Map Step 1 on the SSaurel's Blog
<!DOCTYPE html>
<html lang="en">
<head>
<title>India Interactive SVG Map on the SSaurel's Blog</title>
</head>
<body>
<svg height="800" width="1000">
<path
id="IN-AN"
@ssaurel
ssaurel / PongGame.py
Created January 4, 2024 13:35
Classical Pong Game in Python with Tkinter UI for the SSaurel's Blog
import tkinter as tk
import random as rand
import threading
import os
#define some constants
WIDTH = 1000
HEIGHT = 700
MARGIN = 15
@ssaurel
ssaurel / Pong.py
Created January 4, 2024 13:31
Pong Object for a Pong Game on the SSaurel's Blog
# Now, we can define the Pong Game Object
class Pong:
def __init__(self, root, width, height, margin):
paddlewidth = width / 50
paddleheight = height / 12
self.leftpoints = 0
self.lefttxt = None
self.rightpoints = 0
self.righttxt = None
self.render = True # True when we need to render the game on the canvas
@ssaurel
ssaurel / Paddle.py
Created January 4, 2024 13:18
Paddle Object for a Pong Game on the SSaurel's Blog
# Now, it is time to design the Paddle for our Pong Game
class Paddle:
def __init__(self, canvas, topx, topy, width, height, boardheight):
self.topx = topx
self.topy = topy
self.width = width
self.height = height
self.boardheight = boardheight
self.score = 0
self.canvas = canvas
@ssaurel
ssaurel / Ball.py
Created January 4, 2024 13:11
Ball Object for a Pong Game on the SSaurel's Blog
# First, we design the Ball Object
class Ball:
def __init__(self, canvas, width, velocity, boardwidth, boardheight):
self.width = width
self.boardwidth = boardwidth
self.boardheight = boardheight
# we center the ball on the board
self.topx = boardwidth / 2 - width / 2
self.topy = boardheight / 2 - width / 2
self.velocity = velocity
@ssaurel
ssaurel / FlippingBitsGame.py
Last active May 8, 2023 14:15
Flipping Bits Game in Python with Tkinter - Tutorial for the SSaurel's Blog
import tkinter as tk
import random
from copy import deepcopy
class FlippingBitsGame:
def __init__(self, level):
self.level = level # Level = size of the square
self.target = [[0] * level for _ in range(level)] # the board to obtain when you play
self.board = [[0] * level for _ in range(level)] # the current board played by the user
self.solved = True
@ssaurel
ssaurel / onclick.py
Created May 8, 2023 14:13
onclick method for a Flipping Bits Game on the SSaurel's Blog
def onclick(self, event):
if self.game.solved:
self.game.newgame()
self.drawboard()
return
# we get coordinates of the user's click
idx = int(event.x)
idy = int(event.y)
@ssaurel
ssaurel / drawboard.py
Created May 8, 2023 14:12
drawboard method for a Flipping Bits Game on the SSaurel's Blog
def drawboard(self):
# we clean the canvas
self.canvas.delete("all")
squaresize = 500 / self.game.level
targetsize = squaresize / 10
for i in range(self.game.level):
x = 100 + i * squaresize
for j in range(self.game.level):
y = 100 + j * squaresize
@ssaurel
ssaurel / FlippingBitsGame.py
Created May 8, 2023 14:11
FlippingBitsGame class for a Flipping Bits Game on the SSaurel's Blog
class FlippingBitsGame:
def __init__(self, level):
self.level = level # Level = size of the square
self.target = [[0] * level for _ in range(level)] # the board to obtain when you play
self.board = [[0] * level for _ in range(level)] # the current board played by the user
self.solved = True
self.newgame() # new game method to define later
# method to flip a column
def flipcol(self, r):