analitics

Pages

Showing posts with label 2D. Show all posts
Showing posts with label 2D. Show all posts

Monday, January 8, 2024

Python 3.12.1 : Create a simple color palette.

Today I tested a simple source code for a color palette created with PIL python package.
This is the result:
Let's see the source code:
from PIL import Image, ImageDraw

# 640x640 pixeli with 10x10 squares 64x64 
img = Image.new('RGB', (640, 640))
draw = ImageDraw.Draw(img)

# color list
colors = []
# for 100 colors you need to set steps with 62,62,64 
# or you can change 64,62,62 some little changes 
for r in range(0, 256, 62):
    for g in range(0, 256, 62):
        for b in range(0, 256, 64):
            colors.append((r, g, b))

# show result of colors and size up 100 items 
print(colors)
print(len(colors))

# create 10x10 colors and fill the image 
for i in range(10):
    for j in range(10):
        x0 = j * 64
        y0 = i * 64
        x1 = x0 + 64
        y1 = y0 + 64
        color = colors[i*10 + j]  # Selectarea culorii din lista
        draw.rectangle([x0, y0, x1, y1], fill=color)

# save teh image
img.save('rgb_color_matrix.png')

Friday, October 1, 2021

Python Qt5 : The QSvgWidget for the SVG image format.

In this example tutorial, I will show you how can show an SVG image format with the PyQt5 and QSvgWidget.
I used Fedora 35 Beta with python pyqt5 package install with pip tool.
$ pip install pyqt5
The source code in the Python programming language is this:
The result image is this:

Monday, December 21, 2020

Python 3.6.9 : Ursina python game engine - part 001 .

I wrote the tutorial a few days ago and today I completed it with a video clip ...
The official webpage comes with this intro:
Ursina makes it easier to develop games, visualizations and other kinds of software.
The concise API combined with the power of the Python programming language, makes life easier for the developer so they can focus on what they are making.

Ursina can be used on Windows and Linux
Today I tested on Fedora Linux and works great.
First, the install process is easy with pip3 tool.
[mythcat@desk ~]$ pip3 install ursina
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: ursina in ./.local/lib/python3.9/site-packages (3.2.2)
Requirement already satisfied: screeninfo in ./.local/lib/python3.9/site-packages (from ursina) (0.6.6)
Requirement already satisfied: numpy in /usr/lib64/python3.9/site-packages (from ursina) (1.19.4)
Requirement already satisfied: panda3d in ./.local/lib/python3.9/site-packages (from ursina) (1.10.7)
Requirement already satisfied: pyperclip in ./.local/lib/python3.9/site-packages (from ursina) (1.8.1)
Requirement already satisfied: pillow in /usr/lib64/python3.9/site-packages (from ursina) (7.2.0)
Let's create some examples and see how this python package works.
Create a python script file:
[mythcat@desk ~]$ cd PythonProjects/
[mythcat@desk PythonProjects]$ vi ursina_001.py
Add this simple example:
from ursina import *
# create the application
app = Ursina()
# set some data , like a cube
ground = Entity(
    model = 'cube',
    color = color.blue,
    z = -.1,
    y = -3,
    origin = (0, .5),
    scale = (50, 1, 10),
    collider = 'box'
    )
# run the application
app.run()
And the last pas, run it with python:
[mythcat@desk PythonProjects]$ python ursina_001.py 
ursina version: 3.2.2
package_folder: /home/mythcat/.local/lib/python3.9/site-packages/ursina
asset_folder: .
psd-tools not installed
which: no blender in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:
/home/mythcat/.composer/vendor/bin:/home/mythcat/.dotnet/tools:/var/lib/snapd/snap/bin)
blender_paths:
{}
OS: posix
screen resolution: (1280, 1024)
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
render mode: default
no settings.py file
no settings.py file
development mode: True
application successfully started
You can read on web!: