Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: Thxios <[email protected]>
  • Loading branch information
Thxios committed Mar 11, 2020
1 parent dc9f77a commit 70bb34e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 9 deletions.
13 changes: 13 additions & 0 deletions img.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from PIL import Image

img = Image.open('newDa/hue.png')
img = img.convert('RGBA')
pixel = img.load()
w, h = img.size
for x in range(w):
for y in range(h):
if pixel[x, y] == (0, 0, 0, 255):
pixel[x, y] = (0, 0, 0, 0)

img.thumbnail((201, 201))
img.save('newDa/hue3.png')
Binary file added newDa/hue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newDa/hue3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 47 additions & 2 deletions src/Section.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pygame as pg
from src.Sprite import Sprite
from src.Brush import Brush
from math import ceil
from src.utility import TimerStart, TimerEnd
from math import ceil, sin, cos, atan2, radians, degrees
from src import utility

_tileSize = 32
_gray1 = pg.Surface((_tileSize, _tileSize), pg.SRCALPHA, 32)
Expand All @@ -16,6 +16,8 @@ class Section:
y: int
w: int
h: int
centerX: int
centerY: int
bgColor: (int, int, int)
rect: pg.Rect
surface: pg.Surface
Expand All @@ -29,6 +31,8 @@ def Setup(self, x, y, w, h):
self.y = y + self.term
self.w = w - self.term * 2
self.h = h - self.term * 2
self.centerX = self.w // 2
self.centerY = self.h // 2
self.rect = pg.Rect(self.x, self.y, self.w, self.h)
self.surface = pg.Surface((self.w, self.h), pg.SRCALPHA, 32)
self._hasChange = True
Expand Down Expand Up @@ -208,9 +212,50 @@ class FrameSection(Section):
bgColor = (32, 32, 32)



R, G, B = 0, 1, 2
H, S, V = 0, 1, 2

class ColorSection(Section):
colorCenterX: int
colorCenterY: int

bgColor = (43, 43, 43)
colorWheelImage = pg.image.load('data/hue.png')
radius = colorWheelImage.get_width() // 2
upperTerm = 15
colorRGB = (190, 49, 83)
colorHSV = utility.RGB2HSV(colorRGB)
print(colorRGB, colorHSV)
dotImage = pg.image.load('data/dot.png')
dotRadius = dotImage.get_width() // 2

# ----- for test -----
wheelCenterX = 125
wheelCenterY = 120

def Update(self):
self.surface.fill(self.bgColor)
self.surface.blit(self.colorWheelImage, (self.centerX - self.radius, self.upperTerm))
self.DrawColor()

def SetColor(self, color: (int, int, int)):
if len(color) == 4:
_r, _g, _b, _ = color
else:
_r, _g, _b = color
self.colorRGB = (_r, _g, _b)
self.colorHSV = utility.RGB2HSV(self.colorRGB)
self.Changed()

def DrawColor(self):
_theta = radians(90 - self.colorHSV[H])
_x = round(cos(_theta) * self.radius * self.colorHSV[S] / 100)
_y = round(sin(_theta) * self.radius * self.colorHSV[S] / 100)
print(_theta, _x, _y)
self.surface.blit(self.colorWheelImage, (self.centerX - self.radius, self.upperTerm))
self.surface.blit(self.dotImage,
(self.wheelCenterX + _x - self.dotRadius, self.wheelCenterY + _y - self.dotRadius))

CanvasSection = CanvasSection()
PaletteSection = PaletteSection()
Expand Down
2 changes: 1 addition & 1 deletion src/TestSection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
section = ColorSection
pg.init()

w, h = 200, 250
w, h = 250, 400
section.Setup(0, 0, w, h)

screen = pg.display.set_mode((w, h))
Expand Down
8 changes: 4 additions & 4 deletions src/Window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@


class MainWindow:
w, h = 1280, 720
w, h = 1600, 960
bgColor = (78, 82, 84)

running = False
screen = None
clock = pg.time.Clock()
fps = 126

originX, originY = 200, h - 250
originX, originY = 250, h - 200

Brush.SetBrush('Pencil')
# ----- for test -----
Expand All @@ -22,9 +22,9 @@ class MainWindow:
CanvasSection.Setup(originX, 0, w - originX, originY)
CanvasSection.SetupCanvas(64, 64)

PaletteSection.Setup(0, 0, originX, originY)
PaletteSection.Setup(0, 0, originX, originY - 200)
FrameSection.Setup(originX, originY, w - originX, h - originY)
ColorSection.Setup(0, originY, originX, h - originY)
ColorSection.Setup(0, originY - 200, originX, h - originY + 200)

# ----- for test -----
# sprite = Canvas.Empty(20, 15, (0, 0, 0, 255))
Expand Down
Binary file added src/data/dot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/hue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions src/utility.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import colorsys
from time import time


def RGBA2INT(color):
def RGBA2INT(color: (int, int, int, int)) -> int:
if len(color) == 4:
_r, _g, _b, _a = color
else:
Expand All @@ -10,14 +11,26 @@ def RGBA2INT(color):
_c = _b + 256 * _g + 256 ** 2 * _r + 256 ** 3 * _a
return _c

def INT2RGBA(color):
def INT2RGBA(color: int) -> (int, int, int, int):
_b = color % 256
_g = color // 256 % 256
_r = color // (256 ** 2) % 256
_a = color // (256 ** 3) % 256
return _r, _g, _b, _a


def RGB2HSV(color: (int, int, int)) -> (float, float, float):
_r, _g, _b = color
_h, _s, _v = colorsys.rgb_to_hsv(_r / 255, _g / 255, _b / 255)
return _h * 360, _s * 100, _v * 100


def HSV2RGB(color: (float, float, float)) -> (int, int, int):
_h, _s, _v = color
_r, _g, _b = colorsys.hsv_to_rgb(_h / 360, _s / 100, _v / 100)
return round(_r * 255), round(_g * 255), round(_b * 255)


t = 0
def TimerStart():
global t
Expand All @@ -26,3 +39,4 @@ def TimerStart():
def TimerEnd():
d = time() - t
print(d, 's')

0 comments on commit 70bb34e

Please sign in to comment.