1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/usr/bin/perl
#
# Created on: Tue 20 Jul 2010 08:50:58 AM
# Last saved: Mon 13 Sep 2010 03:47:39 PM
#
# This is a test script to generate the 3D PDL sphere
# logo using TriD. I think it would be very cool to
# have a logo3d routine to generate the image as an
# animated splash screen for example....
use PDL;
use PDL::NiceSlice;
use PDL::Graphics::TriD;
$scale = 0.3;
$alpha = 0.5;
$pcolor = pdl(float,0,1,0,$alpha); # green
$dcolor = pdl(float,1,0,0,$alpha); # red
$lcolor = pdl(float,0,0,1,$alpha); # blue
$gcolor = pdl(float,1,0,0,$alpha); # red for grid color
# I think this was from testing grayscale logos
# $pcolor = $dcolor = $lcolor = $gcolor = black;
# draw the 3D grid of lines
foreach my $i ( 0..3 ) {
foreach my $j ( 0..6 ) {
print "draw line from ($i,$j,0) to ($i,$j,4)\n" if $verbose;
}
}
foreach my $i ( 0..3 ) {
foreach my $k ( 0,2,4 ) {
print "draw line from ($i,0,$k) to ($i,6,$k)\n" if $verbose;
}
}
foreach my $j ( 0..6 ) {
foreach my $k ( 0,2,4 ) {
print "draw line from (0,$j,$k) to (3,$j,$k)\n" if $verbose;
}
}
# The letters are on a 4x7 grid
#
$P = pdl [
[1,1,1,0],
[1,0,0,1],
[1,0,0,1],
[1,1,1,0],
[1,0,0,0],
[1,0,0,0],
[1,0,0,0],
];
$D = pdl [
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
[0,1,1,1],
[1,0,0,1],
[1,0,0,1],
[0,1,1,1],
];
$L = pdl [
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
[0,0,0,1],
];
# Assign the bitmaps to the 3D layout, might be clearer to just
# generate the $logomask ndarray with a single constructor call
# since the mask assignments are a bit obtuse
#
$logomask = $P->dummy(2,5)->zeros;
$logomask(:,:,(4)) .= $P(:,-1:0);
$logomask(:,:,(2)) .= $D(:,-1:0);
$logomask(:,:,(0)) .= $L(:,-1:0);
# Now to extract the sphere coordinates for each letter
# $logomask ...starts as 4x7x5 ndarray
# ->ndcoords ...produces 3 x 4x7x5 ndarrays of coords
# ->where( ...select values with set pixels
# $logomask(*3) ...need conforming 3x4x7x5 mask array
# )->splitdim(0,3); ...1D result needs to get dim(0) back
# and all together we get:
#
$logoxyz = $logomask->ndcoords->where($logomask(*3))->splitdim(0,3);
# Need to have the ability to hide/toggle the axes so they
# don't interfere with the image view *and* would like to
# control the viewing direction rather than enabling user
# twiddling of the display axes.
spheres3d $logoxyz;
## draw(shift(0,0,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,1,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,2,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,3,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,4,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,5,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(0,6,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(1,6,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(2,6,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(3,5,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(3,4,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(2,3,4)*scale(s,s,s)*unitsphere, pcolor);
## draw(shift(1,3,4)*scale(s,s,s)*unitsphere, pcolor);
##
## draw(shift(3,6,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,5,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,4,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,3,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,2,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,1,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(3,0,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(2,0,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(1,0,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(0,1,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(0,2,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(1,3,2)*scale(s,s,s)*unitsphere, dcolor);
## draw(shift(2,3,2)*scale(s,s,s)*unitsphere, dcolor);
##
## draw(shift(3,6,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,5,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,4,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,3,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,2,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,1,0)*scale(s,s,s)*unitsphere, lcolor);
## draw(shift(3,0,0)*scale(s,s,s)*unitsphere, lcolor);
|