Skip to content

Commit f23d251

Browse files
committed
zap zeroes use with rvals, random, etc
1 parent e3a01d2 commit f23d251

File tree

11 files changed

+40
-50
lines changed

11 files changed

+40
-50
lines changed

demos/DemoTkTriD.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ sub linedemos{
146146
if($demo ne "Off"){
147147
my $data;
148148
my $size = 25;
149-
my $cz = (xvals zeroes $size+1) / $size; # interval 0..1
149+
my $cz = (xvals $size+1) / $size; # interval 0..1
150150
my $cx = 0.5+sin($cz*12.6)/2; # Corkscrew
151151
my $cy = 0.5+cos($cz*12.6)/2;
152152
if($demo eq "B&W"){
@@ -195,8 +195,8 @@ sub Linesdemos{
195195
my $data;
196196
my $size = 25;
197197
my($x,$y,$z);
198-
$x = (xvals zeroes $size+1,$size+1) / $size;
199-
$y = (yvals zeroes $size+1,$size+1) / $size;
198+
$x = (xvals $size+1,$size+1) / $size;
199+
$y = (yvals $size+1,$size+1) / $size;
200200
$z = 0.5 + 0.5 * (sin($x*6.3) * sin($y*6.3)) ** 3;
201201
if($demo eq "Lines"){
202202
$data=PDL::Graphics::TriD::LineStrip->new([$x,$y,$z],[$x,$y,$z]);
@@ -240,8 +240,8 @@ sub Contourdemos{
240240
my $data;
241241
my $size = 25;
242242
my($x,$y,$z);
243-
$x = (xvals zeroes $size,$size) / $size;
244-
$y = (yvals zeroes $size,$size) / $size;
243+
$x = (xvals $size,$size) / $size;
244+
$y = (yvals $size,$size) / $size;
245245
$z = (sin($x*6.3) * sin($y*6.3)) ** 3;
246246

247247
if($demo eq "2DB&W"){

demos/test4.p

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use PDL::Graphics::TriD::Image;
44
use PDL::IO::Pic;
55

66
$s = 10;
7-
$k = zeroes($s,$s);
7+
$k = random($s,$s);
88

9-
$x = $k->xvals();
10-
random($k->inplace); $x += $k;
9+
$x = $k->xvals() + $k;
1110

1211
$y = $k->yvals();
1312
random($k->inplace); $y += $k;
@@ -25,10 +24,8 @@ $win->clear_objects();
2524
$win->add_object($pa);
2625
$win->add_object($pb);
2726

28-
$nx = zeroes(3,20);
29-
$nc = zeroes(3,20);
30-
random($nx->inplace);
31-
random($nc->inplace);
27+
$nx = random(3,20);
28+
$nc = random(3,20);
3229

3330
use OpenGL qw(:all);
3431
glShadeModel (&GL_SMOOTH);

demos/test5.p

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ $y /= $size;
1212
srandom(5);
1313
random((my $ysl2 = $y->slice("(2)"))->inplace);
1414
$ysl2 /= 5;
15-
my $c = PDL->zeroes(3,$size,$size);
16-
random($c->inplace);
15+
my $c = PDL->random(3,$size,$size);
1716

1817
my @objs = (
1918
['Lattice', {Shading=>0}],

demos/test7.p

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use PDL::Graphics::TriD;
88

99
$nx = 20;
1010

11-
$t = (xvals zeroes $nx+1,$nx+1)/$nx;
12-
$u = (yvals zeroes $nx+1,$nx+1)/$nx;
11+
$t = (xvals $nx+1,$nx+1)/$nx;
12+
$u = (yvals $nx+1,$nx+1)/$nx;
1313

1414
$x = sin($u*15 + $t * 3)/2+0.5 + 5*($t-0.5)**2;
1515

demos/tvrml.p

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ $set->browser_com('netscape/unix');
1616

1717
$nx = 5;
1818

19-
$t = (xvals zeroes $nx+1,$nx+1)/$nx;
20-
$u = (yvals zeroes $nx+1,$nx+1)/$nx;
19+
$t = (xvals $nx+1,$nx+1)/$nx;
20+
$u = (yvals $nx+1,$nx+1)/$nx;
2121

2222
$x = sin($u*15 + $t * 3)/2+0.5 + 5*($t-0.5)**2;
23-
$cx = PDL->zeroes(3,$nx+1,$nx+1);
24-
random($cx->inplace);
25-
$pdl = PDL->zeroes(3,20);
26-
$pdl->inplace->random;
27-
$cols = PDL->zeroes(3,20);
28-
$cols->inplace->random;
23+
$cx = PDL->random(3,$nx+1,$nx+1);
24+
$pdl = PDL->random(3,20);
25+
$cols = PDL->random(3,20);
2926

3027
$g = PDL::Graphics::TriD::get_new_graph;
3128
$name = $g->add_dataseries(PDL::Graphics::TriD::Points->new($pdl,$cols));

demos/tvrml2.p

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ $set->browser_com('netscape/unix');
2222

2323
$nx = 20;
2424

25-
$t = (xvals zeroes $nx+1,$nx+1)/$nx;
26-
$u = (yvals zeroes $nx+1,$nx+1)/$nx;
25+
$t = (xvals $nx+1,$nx+1)/$nx;
26+
$u = (yvals $nx+1,$nx+1)/$nx;
2727

2828
$x = sin($u*15 + $t * 3)/2+0.5 + 5*($t-0.5)**2;
29-
$cx = PDL->zeroes(3,$nx+1,$nx+1);
30-
random($cx->inplace);
31-
$pdl = PDL->zeroes(3,20);
32-
$pdl->inplace->random;
33-
$cols = PDL->zeroes(3,20);
34-
$cols->inplace->random;
29+
$cx = PDL->random(3,$nx+1,$nx+1);
30+
$pdl = PDL->random(3,20);
31+
$cols = PDL->random(3,20);
3532

3633
$g = PDL::Graphics::TriD::get_new_graph;
3734
$name = $g->add_dataseries(PDL::Graphics::TriD::Points->new($pdl,$cols));

lib/PDL/Demos/TriD1.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ my @demo = (
7272
[actnw => q|
7373
# Number of subdivisions for lines / surfaces.
7474
$size = 25;
75-
$cz = (xvals zeroes $size+1) / $size; # interval 0..1
75+
$cz = (xvals $size+1) / $size; # interval 0..1
7676
$cx = sin($cz*12.6); # Corkscrew
7777
$cy = cos($cz*12.6);
7878
line3d [$cx,$cy,$cz]; # Draw a line
@@ -88,8 +88,8 @@ my @demo = (
8888
|],
8989

9090
[actnw => q|
91-
$x = (xvals zeroes $size+1,$size+1) / $size;
92-
$y = (yvals zeroes $size+1,$size+1) / $size;
91+
$x = (xvals $size+1,$size+1) / $size;
92+
$y = (yvals $size+1,$size+1) / $size;
9393
$z = 0.5 + 0.5 * (sin($x*6.3) * sin($y*6.3)) ** 3; # Bumps
9494
line3d [$x,$y,$z]; # Draw several lines
9595
# [press 'q' in the graphics window when done]
@@ -168,7 +168,7 @@ my @demo = (
168168
[actnw => q|
169169
# The reason for the [] around $x,$y,$z:
170170
# 1. You can give all the coordinates and colors in one ndarray.
171-
$c = (zeroes 3,$size+1) / $size;
171+
$c = zeroes 3,$size+1;
172172
$coords =
173173
sin((3+3*xvals $c)*yvals $c);
174174
$colors = $coords;

lib/PDL/Demos/TriD2.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ my @demo = (
3636
# Number of subdivisions for lines / surfaces.
3737
$size = 25;
3838
39-
$r = (xvals zeroes $size+1,$size+1) / $size;
40-
$g = (yvals zeroes $size+1,$size+1) / $size;
39+
$r = (xvals $size+1,$size+1) / $size;
40+
$g = (yvals $size+1,$size+1) / $size;
4141
$b = ((sin($r*6.3) * sin($g*6.3)) ** 3)/2 + 0.5; # Bumps
4242
imagrgb [$r,$g,$b]; # Draw an image
4343
# [press 'q' in the graphics window when done]

lib/PDL/Demos/TriDGallery.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ points3d[map $_+$_->float->random, whichND(($x!=0)&($x != 255))->transpose->dog]
161161
|],
162162

163163
# use PDL; use PDL::Image2D; use PDL::Graphics::TriD;nokeeptwiddling3d;
164-
# $d=byte(random(zeroes(90,90))>0.5);do{$k=byte [[1,1,1],[1,0,1],[1,1,1]];
164+
# $d=byte(random(90,90)>0.5);do{$k=byte [[1,1,1],[1,0,1],[1,1,1]];
165165
# imagrgb[$d]if($k++%2); $s=conv2d($d,$k)/8;$i=90*90*random(50);$t=$d->
166166
# clump(2)-> index($i);$t.=($s->clump(2)->index($i)>.5);}while(!twiddle3d)
167167

@@ -202,7 +202,7 @@ keeptwiddling3d(); # restore waiting for user to press 'q'
202202
[actnw => q~
203203
# Game of life [Robin Williams (edited by Tjl)]
204204
use PDL::Image2D;
205-
$d=byte(random(zeroes(40,40))>0.85); $k=byte [[1,1,1],[1,0,1],[1,1,1]];
205+
$d=byte(random(40,40)>0.85); $k=byte [[1,1,1],[1,0,1],[1,1,1]];
206206
nokeeptwiddling3d;
207207
do {
208208
imagrgb [$d]; $s=conv2d($d,$k);
@@ -238,7 +238,7 @@ twiddle3d();
238238
# Dewdney's voters (parallelized) [Tjl, inspired by the above 'life']
239239
use PDL::Image2D;
240240
nokeeptwiddling3d;
241-
$d=byte(random(zeroes(100,100))>0.5); $k=float [[1,1,1],[1,0,1],[1,1,1]];
241+
$d=byte(random(100,100)>0.5); $k=float [[1,1,1],[1,0,1],[1,1,1]];
242242
do{
243243
imagrgb[$d];
244244
$s=conv2d($d,$k)/8;

lib/PDL/Graphics/TriD.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PDL::Graphics::TriD - PDL 3D interface
2121
2222
# Generate a somewhat interesting sequence of surfaces
2323
$surf1 = (rvals(100, 100) / 50)**2 + sin(xvals(100, 100) / 10);
24-
$surf2 = sqrt(rvals(zeroes(50,50))/2);
24+
$surf2 = sqrt(rvals(50,50)/2);
2525
$x = sin($surface); $y = cos($surface), $z = $surface;
2626
$coords = cat($x, $y, $z)->transpose;
2727
$red = cos(2*$surface); $green = sin($surface); $blue = $surface;
@@ -214,7 +214,7 @@ This is how, and why, the 3D earth in C<demo 3d> arranges its data.
214214
line3d $coords;
215215
216216
# Draw a regularly-gridded surface:
217-
$surface = sqrt(rvals(zeroes(50,50))/2);
217+
$surface = sqrt(rvals(50,50)/2);
218218
print "draw a mesh of a regularly-gridded surface using mesh3d\n";
219219
mesh3d [$surface];
220220
print "draw a regularly-gridded surface using imag3d\n";
@@ -274,7 +274,7 @@ Implemented by L<PDL::Graphics::TriD::LineStrip>.
274274
275275
Example:
276276
277-
pdl> line3d [sqrt(rvals(zeroes(50,50))/2)]
277+
pdl> line3d [sqrt(rvals(50,50)/2)]
278278
- Lines on surface
279279
pdl> line3d [$x,$y,$z]
280280
- Lines over X, Y, Z
@@ -332,7 +332,7 @@ The variant, C<imag3d_ns>, is implemented by L<PDL::Graphics::TriD::Lattice> def
332332
333333
Example:
334334
335-
pdl> imag3d [sqrt(rvals(zeroes(50,50))/2)], {Lines=>0};
335+
pdl> imag3d [sqrt(rvals(50,50)/2)], {Lines=>0};
336336
337337
- Rendered image of surface
338338
@@ -356,7 +356,7 @@ Implemented by L<PDL::Graphics::TriD::Lattice>.
356356
357357
Example:
358358
359-
pdl> mesh3d [sqrt(rvals(zeroes(50,50))/2)]
359+
pdl> mesh3d [sqrt(rvals(50,50)/2)]
360360
361361
- mesh of surface
362362
@@ -408,7 +408,7 @@ Implemented by L<PDL::Graphics::TriD::Points>.
408408
409409
Example:
410410
411-
pdl> points3d [sqrt(rvals(zeroes(50,50))/2)];
411+
pdl> points3d [sqrt(rvals(50,50)/2)];
412412
- points on surface
413413
414414
See module documentation for more information on
@@ -461,7 +461,7 @@ ways one might want to do this.
461461
462462
e.g.
463463
464-
pdl> $x=sqrt(rvals(zeroes(50,50))/2)
464+
pdl> $x=sqrt(rvals(50,50)/2)
465465
pdl> imagrgb [0.5*sin(8*$x)+0.5,0.5*cos(8*$x)+0.5,0.5*cos(4*$x)+0.5]
466466
467467
=head2 imagrgb3d

0 commit comments

Comments
 (0)