@@ -52,61 +52,75 @@ def __setitem__(self, key, value):
52
52
x , y = key
53
53
self .pixel (x , y , value )
54
54
55
- def shift_right (self , rotate = False ):
55
+ def shift (self , x , y , rotate = False ):
56
56
"""
57
- Shift all pixels right
57
+ Shift pixels by x and y
58
58
59
59
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
60
60
"""
61
- for y in range (0 , self .rows ):
62
- last_pixel = self [self .columns - 1 , y ] if rotate else 0
63
- for x in range (self .columns - 1 , 0 , - 1 ):
64
- self [x , y ] = self [x - 1 , y ]
65
- self [0 , y ] = last_pixel
61
+ if x > 0 : # Shift Right
62
+ for _ in range (x ):
63
+ for row in range (0 , self .rows ):
64
+ last_pixel = self [self .columns - 1 , row ] if rotate else 0
65
+ for col in range (self .columns - 1 , 0 , - 1 ):
66
+ self [col , row ] = self [col - 1 , row ]
67
+ self [0 , row ] = last_pixel
68
+ elif x < 0 : # Shift Left
69
+ for _ in range (- x ):
70
+ for row in range (0 , self .rows ):
71
+ last_pixel = self [0 , row ] if rotate else 0
72
+ for col in range (0 , self .columns - 1 ):
73
+ self [col , row ] = self [col + 1 , row ]
74
+ self [self .columns - 1 , row ] = last_pixel
75
+ if y > 0 : # Shift Up
76
+ for _ in range (y ):
77
+ for col in range (0 , self .columns ):
78
+ last_pixel = self [col , self .rows - 1 ] if rotate else 0
79
+ for row in range (self .rows - 1 , 0 , - 1 ):
80
+ self [col , row ] = self [col , row - 1 ]
81
+ self [col , 0 ] = last_pixel
82
+ elif y < 0 : # Shift Down
83
+ for _ in range (- y ):
84
+ for col in range (0 , self .columns ):
85
+ last_pixel = self [col , 0 ] if rotate else 0
86
+ for row in range (0 , self .rows - 1 ):
87
+ self [col , row ] = self [col , row + 1 ]
88
+ self [col , self .rows - 1 ] = last_pixel
66
89
if self ._auto_write :
67
90
self .show ()
68
91
92
+
93
+ def shift_right (self , rotate = False ):
94
+ """
95
+ Shift all pixels right
96
+
97
+ :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
98
+ """
99
+ self .shift (1 , 0 , rotate )
100
+
69
101
def shift_left (self , rotate = False ):
70
102
"""
71
103
Shift all pixels left
72
104
73
105
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
74
106
"""
75
- for y in range (0 , self .rows ):
76
- last_pixel = self [0 , y ] if rotate else 0
77
- for x in range (0 , self .columns - 1 ):
78
- self [x , y ] = self [x + 1 , y ]
79
- self [self .columns - 1 , y ] = last_pixel
80
- if self ._auto_write :
81
- self .show ()
107
+ self .shift (- 1 , 0 , rotate )
82
108
83
109
def shift_up (self , rotate = False ):
84
110
"""
85
111
Shift all pixels up
86
112
87
113
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
88
114
"""
89
- for x in range (0 , self .columns ):
90
- last_pixel = self [x , self .rows - 1 ] if rotate else 0
91
- for y in range (self .rows - 1 , 0 , - 1 ):
92
- self [x , y ] = self [x , y - 1 ]
93
- self [x , 0 ] = last_pixel
94
- if self ._auto_write :
95
- self .show ()
115
+ self .shift (0 , 1 , rotate )
96
116
97
117
def shift_down (self , rotate = False ):
98
118
"""
99
119
Shift all pixels down
100
120
101
121
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
102
122
"""
103
- for x in range (0 , self .columns ):
104
- last_pixel = self [x , 0 ] if rotate else 0
105
- for y in range (0 , self .rows - 1 ):
106
- self [x , y ] = self [x , y + 1 ]
107
- self [x , self .rows - 1 ] = last_pixel
108
- if self ._auto_write :
109
- self .show ()
123
+ self .shift (0 , - 1 , rotate )
110
124
111
125
@property
112
126
def columns (self ):
0 commit comments