download: generator-psk.py
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# Copyright 2006 - Juan José Conti <jjconti@gnu.org>
# Copyleft :-)
from math import *
from gimpfu import *
def gen_constellation(bg_colour, stars_colour, circles_colour, axis_colour, power):
img_width = img_height = 350
n = int(pow(2,power))
diam = img_width * 0.8
rad = diam / 2
X_BASE = Y_BASE = img_width / 2
img = pdb.gimp_image_new(img_width, img_height, RGB)
layer = pdb.gimp_layer_new(img, img_width, img_height, RGB_IMAGE, "Starts", 100, NORMAL_MODE)
pdb.gimp_image_add_layer(img,layer,0)
pdb.gimp_context_set_background(bg_colour)
pdb.gimp_drawable_fill(layer,BACKGROUND_FILL)
pdb.gimp_context_set_foreground(circles_colour)
draw_circle(img, layer, X_BASE, Y_BASE, rad)
pdb.gimp_context_set_foreground(axis_colour)
draw_axis(img, layer, img_width, img_height)
pdb.gimp_context_set_foreground(stars_colour)
draw_constellation(img, layer, n, rad, X_BASE, Y_BASE)
float_text = set_text(img, layer, 275, 310, str(n)+"-PSK")
pdb.gimp_floating_sel_anchor(float_text)
pdb.gimp_selection_none(img)
pdb.gimp_display_new(img)
def draw_constellation(img, layer, n, rad, X_BASE, Y_BASE):
arc = (2*pi)/n
arc_sum = arc
i = 1
while(i <= n):
x_offset = sin(arc_sum) * rad
y_offset = cos(arc_sum) * rad
draw_star(img, layer, X_BASE + x_offset, Y_BASE + y_offset)
i += 1
arc_sum += arc
def draw_star(img, layer, x, y):
size = 12
x_top_left = x - size/2
y_top_left = y - size/2
pdb.gimp_ellipse_select(img, x_top_left, y_top_left, size, size, CHANNEL_OP_ADD, False, 0, 0)
pdb.gimp_edit_bucket_fill(layer, FG_BUCKET_FILL, NORMAL_MODE,100, 0, 0, 0, 0)
pdb.gimp_selection_none(img)
def set_text(img, layer, x, y, text):
# last parameter, font name, must be installed in the system
return pdb.gimp_text_fontname(img, layer, x, y, text, 1, False, 16, PIXELS,"URW Gothic L")
def draw_circle(img, layer, x_center, y_center, rad):
width = 2 # line width in pixels
rad = rad + width/2.
x_top_left = x_center - rad
y_top_left = y_center - rad
pdb.gimp_ellipse_select(img, x_top_left, y_top_left, 2*rad, 2*rad, CHANNEL_OP_ADD, False, 0, 0)
# when gimp stable relase suport defining stroke preferences this function
# will looks nicer
# pdb.gimp_edit_stroke(layer)
# meanwhile..
pdb.gimp_edit_bucket_fill(layer, FG_BUCKET_FILL, NORMAL_MODE,100, 0, 0, 0, 0)
pdb.gimp_selection_none(img)
rad = rad - width
x_top_left = x_center - rad
y_top_left = y_center - rad
pdb.gimp_ellipse_select(img, x_top_left, y_top_left, 2*rad, 2*rad, CHANNEL_OP_ADD, False, 0, 0)
pdb.gimp_edit_bucket_fill(layer, BG_BUCKET_FILL, NORMAL_MODE,100, 0, 0, 0, 0)
pdb.gimp_selection_none(img)
def draw_axis(img, layer, total_width, total_height):
width = 3 # line width in pixels
x_center = total_width / 2.
y_center = total_height / 2.
# y axis
x_top_left = x_center - width/2.
y_top_left = 0
pdb.gimp_rect_select(img, x_top_left, y_top_left, width, total_height, CHANNEL_OP_ADD, 0, 0)
# x axis
x_top_left = 0
y_top_left = y_center - width/2.
pdb.gimp_rect_select(img, x_top_left, y_top_left, total_width, width, CHANNEL_OP_ADD, 0, 0)
pdb.gimp_edit_bucket_fill(layer, FG_BUCKET_FILL, NORMAL_MODE,100, 0, 0, 0, 0)
pdb.gimp_selection_none(img)
register(
"gen_constellation",
"Generate a PSK modulation constelation",
"Generate a PSK modulation constelation",
"Juanjo Conti",
"Juanjo Conti",
"2006",
"<Toolbox>/Xtns/Python-Fu/Constellations/PSK",
"",
[
(PF_COLOR, "bg_colour", "Color de fondo:", (255,255,255)),
(PF_COLOR, "stars_colour", "Color de las estrellas:", (0,0,0)),
(PF_COLOR, "circles_colour", "Color de las circunferencias:", (216,255,255)),
(PF_COLOR, "axis_colour", "Color de los ejes de coordenadas:", (232,232,232)),
(PF_SPINNER, "power", "El número de estrellas en la constelación es 2^:", 3, (1,6,1))
],
[],
gen_constellation)
main()