The latest version of this document can be found at www.broad.ology.org.uk/amiga/sketchblock/spreadpalette_py.html
1: #!C:python
2:
3: import arexx
4:
5: colours = []
6: c =[]
7:
8: ###############################################################################
9: # Script goal: create a smooth spread palette from the colours in the current #
10: # Active Palette. #
11: # #
12: # Approach: #
13: # Since the Palette API is still a WIP and we don't have any GETPALETTEINFO #
14: # type commands yet were going to do this the hard way! #
15: # #
16: # Save current foreground colour. #
17: # Iterate through current palette by doing the following #
18: # SetColorFromPalette #
19: # GetColour and add it to our list #
20: # Increment palette index #
21: # Repeat until failure (index too large) #
22: # Restore foreground colour #
23: # Add new palette (by default becomes active ) #
24: # Iterate through list of colours interpolating between each stage creating #
25: # a new list with the extra colour steps #
26: # Iterate through new list adding each colour to palette #
27: # Done #
28: ###############################################################################
29:
30: # Save foreground colour, we simply save the returned string for now.
31:
32: (rc,rc2,savecolour) = arexx.dorexx("SKETCHBLOCK","GETCOLOR")
33:
34:
35: # Set up index variable and fetch first palette colour
36: i = 0
37: (rc,rc2,dummy) = arexx.dorexx("SKETCHBLOCK","SETCOLORFROMPALETTE INDEX " + str(i))
38:
39: # loop until failure indicated by rc != 0
40:
41: while rc == 0:
42: # Fecth colour
43: (rc,rc2,palettecol) = arexx.dorexx("SKETCHBLOCK","GETCOLOR")
44: # parse and append to our colours list
45: (a,r,g,b) = palettecol.split()
46: colours.append((float(r),float(g),float(b),float(a)))
47: # iterate.
48: i += 1
49: (rc,rc2,dummy) = arexx.dorexx("SKETCHBLOCK","SETCOLORFROMPALETTE INDEX " + str(i))
50:
51: # parse saved colour
52: (a,r,g,b) = savecolour.split()
53: # restore
54: arexx.dorexx("SKETCHBLOCK","SETCOLOR A " + a + " R " + r + " G " + g + " B " + b)
55:
56: # loop through colours in out list
57: for i in range(0,len(colours) -1):
58: (r,g,b,a) = colours[i]
59: (er,eg,eb,ea) = colours[i +1]
60:
61: # calculate increment in 10ths
62: dr = (er - r )/ 10.0
63: dg = (eg - g )/ 10.0
64: db = (eb - b )/ 10.0
65: da = (ea - a )/ 10.0
66:
67: # apply increment in 10 steps
68: # add each increment to new list
69: count = 10
70: while count > 0:
71: c.append((r,g,b,a))
72: r += dr
73: g += dg
74: b += db
75: a += da
76: count -= 1
77:
78: # create new palette
79: (rc,rc2,palid) = arexx.dorexx("SKETCHBLOCK","NEWPALETTE NAME "Spread"")
80:
81: # add each colour to new palette.
82:
83: for i in range(0,len(c)):
84: (r,g,b,a) = c[i]
85: arexx.dorexx("SKETCHBLOCK","ADDPALETTEENTRY PALID " + palid + " RED " + str(r) + " GREEN " + str(g) + " BLUE " + str(b) + " ALPHA " + str(a))
86: