import pygame WIDTH = 500 HEIGHT = 500 FPS = 60 #define colors #colors are defined in red,green,blue #values from 0-255 WHITE = (255,255,255) BLACK = (0,0,0) RED = (255,0,0) GREEN = (0,255,0) BLUE = (0,0,255) YELLOW = (255,255,0) pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((WIDTH,HEIGHT)) clock = pygame.time.Clock() class Player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface((50,40)) self.image.fill(GREEN) self.rect = self.image.get_rect() self.rect.centerx = 30 self.rect.centery = 30 self.speedx = 0 self.speedy = 0 self.ticker = 0 def update(self): speed = 5 self.speedx = 0 self.speedy = 0 keystate = pygame.key.get_pressed() if keystate[pygame.K_LEFT]: self.speedx = -speed if keystate[pygame.K_RIGHT]: self.speedx = speed if keystate[pygame.K_UP]: self.speedy = -speed self.ticker += 1 #NEW CODE if keystate[pygame.K_DOWN]: self.speedy = speed self.ticker += 1 #NEW CODE self.rect.x += self.speedx #HERE IS WHERE WE self.ticker = self.ticker % 20 if self.ticker >9: self.image.fill(GREEN) else: self.image.fill(BLUE) #HERE WE ARE GOING TO WRAP AROUND THE EDGES IF THE SPRITE #GOES OFF THE SCREEN #REMEMBER THAT X IS LEFT TO RIGHT AND Y IS UP AND DOWN if self.rect.x > WIDTH: self.rect.x = 0 if self.rect.x < 0: self.rect.x = WIDTH self.rect.y += self.speedy if self.rect.y > HEIGHT: self.rect.y = 0 if self.rect.y < 0: self.rect.y = HEIGHT all_sprites = pygame.sprite.Group() james = Player() all_sprites.add(james) running = True while running: clock.tick(FPS) pygame.event.get() all_sprites.update() screen.fill(BLACK) all_sprites.draw(screen) pygame.display.flip()
Author Archives: admin
3-Bit Adder in Logic.ly
Python Brickbreaker with Tkinter
from tkinter import * import random import time tk = Tk() tk.title("Game") tk.resizable(0, 0) tk.wm_attributes("-topmost", 1) canvas = Canvas(tk, width=500, height=400, bd=0, highlightthickness=0) canvas.pack() tk.update() class Ball: def __init__(self, canvas, paddle, color): self.canvas = canvas self.paddle = paddle self.id = canvas.create_oval(10, 10, 25, 25, fill=color) self.canvas.move(self.id, 245, 100) starts = [-3, -2, -1, 1, 2, 3] random.shuffle(starts) self.x = starts[0] self.y = -3 self.canvas_height = self.canvas.winfo_height() self.canvas_width = self.canvas.winfo_width() def draw(self): self.canvas.move(self.id, self.x, self.y) pos = self.canvas.coords(self.id) if pos[1] <= 0: self.y = 3 if pos[3] >= self.canvas_height: self.y = -3 if self.hit_paddle(pos) == True: self.y = -3 if pos[0] <= 0: self.x = 3 if pos[2] >= self.canvas_width: self.x = -3 def hit_paddle(self, pos): paddle_pos = self.canvas.coords(self.paddle.id) if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]: if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]: return True return False class Paddle: def __init__(self, canvas, color): self.canvas = canvas self.id = canvas.create_rectangle(0, 0, 100, 10, fill=color) self.canvas.move(self.id, 200, 300) self.x = 0 self.canvas_width = self.canvas.winfo_width() self.canvas.bind_all('<KeyPress-Left>', self.turn_left) self.canvas.bind_all('<KeyPress-Right>', self.turn_right) def turn_left(self, evt): self.x = -2 def turn_right(self, evt): self.x = 2 def draw(self): self.canvas.move(self.id, self.x, 0) pos = self.canvas.coords(self.id) if pos[0] <= 0: self.x = 0 elif pos[2] >= self.canvas_width: self.x = 0 paddle = Paddle(canvas, 'blue') ball = Ball(canvas, paddle, 'red') while 1: ball.draw() paddle.draw() tk.update_idletasks() tk.update() time.sleep(0.01)
PyGame Basic Setup
import pygame import random WIDTH = 480 HEIGHT = 480 FPS = 30 # define colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) # initialize pygame and create window pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("My Game") clock = pygame.time.Clock() # Game loop running = True while running: # keep loop running at the right speed clock.tick(FPS) # Process input (events) for event in pygame.event.get(): # check for closing window if event.type == pygame.QUIT: running = False # Update # Draw / render screen.fill(BLACK) # *after* drawing everything, flip the display pygame.display.flip() pygame.quit()
Werewolves of Miller’s Hollow Roles
Werewolves
Each night, the werewolves pick 1 (this can change with the Personnages expansion pack) player to kill. The victim can be anyone except the Moderator, including other werewolves. The next day, they pretend to be a villager and try to seem unsuspicious. The number of werewolves in a game varies depending on the number of players.
Villagers
They don’t have any special power except thinking and the right to vote.
Seer/ Fortune Teller/ Oracle
Each night, they can discover the real identity of a player. They must help the other villagers but discreetly to not be found by werewolves.
Hunter
If they are killed by werewolves or eliminated by vote, they must immediately kill another player of their choice.
Cupido
The first night, Cupid chooses 2 players and make them fall in love, then becomes a villager. If one dies, the other dies too. A lover can’t vote against the other lover. If the lovers are a villager and a werewolf, their objective changes; they must eliminate all the players except them.
Witch
She has two potions:
- one to save the werewolves’s victim
- one to eliminate a player
She can only use each potion once during the game. She can use both potions during the same night. She can save herself if she has been attacked by the werewolves on the first night.
Little Girl
The little girl can secretly look at the werewolves during their turn. If she is caught in the act, she dies instead of the victim. Because she will be scared to death, or depending on how you play the werewolves will kill her later on in the game. It is also possible for her to die immediately along with the victim and can not be saved.
Sheriff/Captain
This card is given to a player besides their card. They are elected by a vote. This player’s vote counts for two instead of one. If they die, they will decide who will be the next Sheriff/Chief. The Sheriff/Chief can be of any role, including a werewolf.
Thief
If the thief is played, two cards more than the number of players need to be played. After each player receives a card, the two cards are put in the center of the table. The thief can,they want to, during the first night, exchange their cards with one of those cards that they will play until the end of the game. If the two cards are werewolf, the thief has to take one of the two werewolf cards, until the end of the game.
Game’s turns
1st Night Only
- Thief
- Cupid
- Lovers
Every night
- Werewolves
- Little Girl
- Seer
- Witch
Python Turtle Demo Spirograph
<br> import random,time,turtle<br>bai = turtle.Turtle()<br>bai.pendown<br>bai.speed(10)<br>bai.tracer(300)<br>bai.hideturtle()<br>for i in range (1000):<br> for i in range(4):<br> for i in range (40):<br> bai.forward(50)<br> bai.left(100)<br> r = random.randint(0,255)<br> g = random.randint(0,255)<br> b = random.randint(0,255)<br> bai.pencolor((r,g,b))<br> for i in range(4):<br> bai.forward(10)<br> bai.left(90)<br> time.sleep(0.1)<br> bai.penup<br> bai.forward(100)<br> bai.pendown
<br><br> import turtle<br>import time<br>import random<br>bob = turtle.Turtle()<br>bob.tracer(300)<br>bob.pendown()<br>bob.hideturtle()<br>for i in range (20):<br> for i in range(200):<br> bob.forward(158)<br> bob.left(200)<br> bob.right(1)<br> r = random.randint(1,255)<br> g = random.randint(1,255)<br> b = random.randint(1,255)<br> bob.pencolor((r,g,b))<br> time.sleep(0.1) <br>
Hex/Binary/Base64
Base64 table[edit]
The Base64 index table:
Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 000000 | A | 16 | 010000 | Q | 32 | 100000 | g | 48 | 110000 | w | |||
1 | 000001 | B | 17 | 010001 | R | 33 | 100001 | h | 49 | 110001 | x | |||
2 | 000010 | C | 18 | 010010 | S | 34 | 100010 | i | 50 | 110010 | y | |||
3 | 000011 | D | 19 | 010011 | T | 35 | 100011 | j | 51 | 110011 | z | |||
4 | 000100 | E | 20 | 010100 | U | 36 | 100100 | k | 52 | 110100 | 0 | |||
5 | 000101 | F | 21 | 010101 | V | 37 | 100101 | l | 53 | 110101 | 1 | |||
6 | 000110 | G | 22 | 010110 | W | 38 | 100110 | m | 54 | 110110 | 2 | |||
7 | 000111 | H | 23 | 010111 | X | 39 | 100111 | n | 55 | 110111 | 3 | |||
8 | 001000 | I | 24 | 011000 | Y | 40 | 101000 | o | 56 | 111000 | 4 | |||
9 | 001001 | J | 25 | 011001 | Z | 41 | 101001 | p | 57 | 111001 | 5 | |||
10 | 001010 | K | 26 | 011010 | a | 42 | 101010 | q | 58 | 111010 | 6 | |||
11 | 001011 | L | 27 | 011011 | b | 43 | 101011 | r | 59 | 111011 | 7 | |||
12 | 001100 | M | 28 | 011100 | c | 44 | 101100 | s | 60 | 111100 | 8 | |||
13 | 001101 | N | 29 | 011101 | d | 45 | 101101 | t | 61 | 111101 | 9 | |||
14 | 001110 | O | 30 | 011110 | e | 46 | 101110 | u | 62 | 111110 | + | |||
15 | 001111 | P | 31 | 011111 | f | 47 | 101111 | v | 63 | 111111 | / | |||
Padding | = |
https://en.wikipedia.org/wiki/Base64
UTF8 – Hex
U+0021 | ! | 21 | EXCLAMATION MARK |
U+0022 | “ | 22 | QUOTATION MARK |
U+0023 | # | 23 | NUMBER SIGN |
U+0024 | $ | 24 | DOLLAR SIGN |
U+0025 | % | 25 | PERCENT SIGN |
U+0026 | & | 26 | AMPERSAND |
U+0027 | ‘ | 27 | APOSTROPHE |
U+0028 | ( | 28 | LEFT PARENTHESIS |
U+0029 | ) | 29 | RIGHT PARENTHESIS |
U+002A | * | 2a | ASTERISK |
U+002B | + | 2b | PLUS SIGN |
U+002C | , | 2c | COMMA |
U+002D | – | 2d | HYPHEN-MINUS |
U+002E | . | 2e | FULL STOP |
U+002F | / | 2f | SOLIDUS |
U+0030 | 0 | 30 | DIGIT ZERO |
U+0031 | 1 | 31 | DIGIT ONE |
U+0032 | 2 | 32 | DIGIT TWO |
U+0033 | 3 | 33 | DIGIT THREE |
U+0034 | 4 | 34 | DIGIT FOUR |
U+0035 | 5 | 35 | DIGIT FIVE |
U+0036 | 6 | 36 | DIGIT SIX |
U+0037 | 7 | 37 | DIGIT SEVEN |
U+0038 | 8 | 38 | DIGIT EIGHT |
U+0039 | 9 | 39 | DIGIT NINE |
U+003A | : | 3a | COLON |
U+003B | ; | 3b | SEMICOLON |
U+003C | < | 3c | LESS-THAN SIGN |
U+003D | = | 3d | EQUALS SIGN |
U+003E | > | 3e | GREATER-THAN SIGN |
U+003F | ? | 3f | QUESTION MARK |
U+0040 | @ | 40 | COMMERCIAL AT |
U+0041 | A | 41 | LATIN CAPITAL LETTER A |
U+0042 | B | 42 | LATIN CAPITAL LETTER B |
U+0043 | C | 43 | LATIN CAPITAL LETTER C |
U+0044 | D | 44 | LATIN CAPITAL LETTER D |
U+0045 | E | 45 | LATIN CAPITAL LETTER E |
U+0046 | F | 46 | LATIN CAPITAL LETTER F |
U+0047 | G | 47 | LATIN CAPITAL LETTER G |
U+0048 | H | 48 | LATIN CAPITAL LETTER H |
U+0049 | I | 49 | LATIN CAPITAL LETTER I |
U+004A | J | 4a | LATIN CAPITAL LETTER J |
U+004B | K | 4b | LATIN CAPITAL LETTER K |
U+004C | L | 4c | LATIN CAPITAL LETTER L |
U+004D | M | 4d | LATIN CAPITAL LETTER M |
U+004E | N | 4e | LATIN CAPITAL LETTER N |
U+004F | O | 4f | LATIN CAPITAL LETTER O |
U+0050 | P | 50 | LATIN CAPITAL LETTER P |
U+0051 | Q | 51 | LATIN CAPITAL LETTER Q |
U+0052 | R | 52 | LATIN CAPITAL LETTER R |
U+0053 | S | 53 | LATIN CAPITAL LETTER S |
U+0054 | T | 54 | LATIN CAPITAL LETTER T |
U+0055 | U | 55 | LATIN CAPITAL LETTER U |
U+0056 | V | 56 | LATIN CAPITAL LETTER V |
U+0057 | W | 57 | LATIN CAPITAL LETTER W |
U+0058 | X | 58 | LATIN CAPITAL LETTER X |
U+0059 | Y | 59 | LATIN CAPITAL LETTER Y |
U+005A | Z | 5a | LATIN CAPITAL LETTER Z |
U+005B | [ | 5b | LEFT SQUARE BRACKET |
U+005C | \ | 5c | REVERSE SOLIDUS |
U+005D | ] | 5d | RIGHT SQUARE BRACKET |
U+005E | ^ | 5e | CIRCUMFLEX ACCENT |
U+005F | _ | 5f | LOW LINE |
U+0060 | ` | 60 | GRAVE ACCENT |
U+0061 | a | 61 | LATIN SMALL LETTER A |
U+0062 | b | 62 | LATIN SMALL LETTER B |
U+0063 | c | 63 | LATIN SMALL LETTER C |
U+0064 | d | 64 | LATIN SMALL LETTER D |
U+0065 | e | 65 | LATIN SMALL LETTER E |
U+0066 | f | 66 | LATIN SMALL LETTER F |
U+0067 | g | 67 | LATIN SMALL LETTER G |
U+0068 | h | 68 | LATIN SMALL LETTER H |
U+0069 | i | 69 | LATIN SMALL LETTER I |
U+006A | j | 6a | LATIN SMALL LETTER J |
U+006B | k | 6b | LATIN SMALL LETTER K |
U+006C | l | 6c | LATIN SMALL LETTER L |
U+006D | m | 6d | LATIN SMALL LETTER M |
U+006E | n | 6e | LATIN SMALL LETTER N |
U+006F | o | 6f | LATIN SMALL LETTER O |
U+0070 | p | 70 | LATIN SMALL LETTER P |
U+0071 | q | 71 | LATIN SMALL LETTER Q |
U+0072 | r | 72 | LATIN SMALL LETTER R |
U+0073 | s | 73 | LATIN SMALL LETTER S |
U+0074 | t | 74 | LATIN SMALL LETTER T |
U+0075 | u | 75 | LATIN SMALL LETTER U |
U+0076 | v | 76 | LATIN SMALL LETTER V |
U+0077 | w | 77 | LATIN SMALL LETTER W |
U+0078 | x | 78 | LATIN SMALL LETTER X |
U+0079 | y | 79 | LATIN SMALL LETTER Y |
U+007A | z | 7a | LATIN SMALL LETTER Z |
DHT11 Arduino Wiring
7-Segment Display with Switch/Case
int a = 6; int b = 5; int c = 2; int d = 3; int e = 4; int f = 7; int g = 8; int p = 9; void setup() { pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(b, OUTPUT); pinMode(a, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); pinMode(p, OUTPUT); pinMode(A1, INPUT); pinMode(A2, INPUT); Serial.begin(9600); } int num = 1; int xvalue; void loop() { LEDplay(num); delay(1000); xvalue = analogRead(A1); if(xvalue > 1000){ num = num+1; num = num%10; } if(xvalue < 10){ num = num-1; num = num%10; } if(num < 0){ num = 9; } } void LEDplay(int num){ switch (num) { case 0: zero(); break; case 1: one(); break; case 2: two(); break; case 3: three(); break; case 4: four(); break; case 5: five(); break; case 6: six(); break; case 7: seven(); break; case 8: eight(); break; case 9: nine(); break; default: //do nothing break; } } void one(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(p, LOW); } void two(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void three(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void four(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void five(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void six(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void seven(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(p, LOW); } void eight(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void nine(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void zero(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW); digitalWrite(p, LOW); }