Silicon-Chip
view release on metacpan or search on metacpan
lib/Silicon/Chip.pm view on Meta::CPAN
next unless defined $p{$d};
my $y = $p{$d}->y;
$p{$G} = newGatePosition(gate=>$g, x=>$W, y=>$y, width=>1); # Position output gate
}
my $pageWidth = $W + 1; # Width of input, output and non io gates as laid out.
if (defined($title)) # Title if known
{$s->text(x=>$pageWidth, y=>0.5, fill=>"darkGreen", text_anchor=>"end",
stroke_width=>Fw, font_size=>Fs, z=>-1,
cdata=>$title);
}
if (defined($steps)) # Number of steps taken if known
{$s->text(x=>$pageWidth, y=>1.5, fill=>"darkGreen", text_anchor=>"end",
stroke_width=>Fw, font_size=>Fs, z=>-1,
cdata=>"$steps steps");
}
for my $P(sort keys %p) # Each gate with text describing it
{my $p = $p{$P};
my $x = $p->x;
my $y = $p->y;
my $w = $p->width;
my $g = $p->gate;
my $color = sub
lib/Silicon/Chip.pm view on Meta::CPAN
if (defined(my $v = $$values{$g->output})) # Value of gate if known
{$s->text(
x => $g->io != gateOuterOutput ? $x : $x + 1,
y => $y,
fill =>"black",
stroke_width => Fw,
font_size => Fs,
text_anchor => $g->io != gateOuterOutput ? "start": "end",
dominant_baseline => "hanging",
cdata => $v ? "1" : "0");
}
if (defined(my $t = $$changed{$g->output}) and !$g->io) # Gate change time if known for a non io gate
{$s->text(
x => $w + ($g->io != gateOuterOutput ? $x : $x + 1),
y => 1 + $y,
fill =>"black",
stroke_width => fw,
font_size => fs,
text_anchor => "end",
cdata => $t+1);
}
my sub ot($$$$) # Output svg text
{my ($dy, $fill, $pos, $text) = @_;
$s->text(x => $x+$w/2,
y => $y+$dy,
fill => $fill,
text_anchor => "middle",
dominant_baseline => $pos,
cdata => $text);
}
ot(5/12, "red", "auto", $g->type); # Type of gate
ot(7/12, "darkblue", "hanging", $g->output);
if ($g->io != gateOuterInput) # Not an input pin
{my %i = $g->inputs ? $g->inputs->%* : ();
my @i = sort keys %i; # Connections to each gate
my $o = $g->output;
lib/Silicon/Chip.pm view on Meta::CPAN
{my $bottom = $x > $X || $G->io == gateOuterInput;
my $Y = $y + $dy + fs;
$s->text(
x => $cx,
y => $Y,
fill => "black",
stroke_width => fw,
font_size => fs,
text_anchor => "middle",
$bottom ? () : (dominant_baseline=>"hanging"),
cdata => $v ? "1" : "0");
}
}
}
}
my $t = $s->print;
return owf(fpe($options{svg}, q(svg)), $t) if $options{svg};
$t
}
sub Silicon::Chip::Simulation::printSvg($%) # Print simulation results as svg.
lib/Silicon/Chip.pm view on Meta::CPAN
}
}
}
my $py = 0;
my sub wt($;$) # Write titles on following lines
{my ($t, $T) = @_; # Value, title to write
if (defined($t)) # Value to write
{$py += Tl; # Position to write at
my $s = $t; $s .= " $T" if $T; # Text to write
$svg->text(x => $width, y => $py, cdata => $s, # Write text
fill=>"darkGreen", text_anchor=>"end", stroke_width=>Tw, font_size=>Ts);
}
}
wt($chip->title); # Title if known
wt($steps, "steps"); # Number of steps taken if known
wt($thickness, "thick"); # Thickness of bundle
wt($width, "wide"); # Width of page
for my $p(@positions) # Draw each gate
lib/Silicon/Chip.pm view on Meta::CPAN
if (defined(my $v = $p->value)) # Value of gate if known
{$svg->text(
x => $p->x,
y => $p->y,
fill =>"black",
stroke_width => Fw,
font_size => Fs,
text_anchor => "start",
dominant_baseline => "hanging",
cdata => $v ? "1" : "0");
}
if (defined(my $t = $p->changed) and !$p->inPin and !$p->outPin) # Gate change time if known for a non io gate
{$svg->text(
x => $p->x + $p->width,
y => $p->y + 1,
fill => "darkBlue",
stroke_width => fw,
font_size => fs,
text_anchor => "end",
cdata => $t+1);
}
my sub ot($$$$) # Output svg text
{my ($dy, $fill, $pos, $text) = @_;
$svg->text(x => $p->x+$p->width/2,
y => $p->y+$dy,
fill => $fill,
text_anchor => "middle",
dominant_baseline => $pos,
cdata => $text);
}
ot(5/12, "red", "auto", $p->type); # Type of gate
ot(7/12, "darkblue", "hanging", $p->output);
my @i = $p->inputValues->@*;
for my $i(keys @i) # Draw input values to each pin on the gate
{next if $p->inPin or $p->outPin;
my $v = $p->inputValues->[$i];
if (defined($v))
{$svg->text(
x => $p->x + $i + 1/2,
y => $p->y,
fill => "darkRed",
stroke_width => fw,
font_size => fs,
text_anchor => "middle",
dominant_baseline => "hanging",
cdata => $v ? "1" : "0");
}
}
}
if (debugMask) # Show fiber names - useful when debugging bus lines
{for my $i(keys @fibers)
{for my $j(keys $fibers[$i]->@*)
{if (defined(my $n = $fibers[$i][$j][0])) # Horizontal
{$svg->text(
x => $i+1/2,
y => $j+1/2,
fill =>"black",
stroke_width => fw,
font_size => fs,
text_anchor => 'middle',
dominant_baseline => 'auto',
cdata => $n,
)# if $n eq "a4" || $n eq "a4";
}
if (defined(my $n = $fibers[$i][$j][1])) # Vertical
{$svg->text(
x => $i+1/2,
y => $j+1/2,
fill =>"red",
stroke_width => fw,
font_size => fs,
text_anchor => 'middle',
dominant_baseline => 'hanging',
cdata => $n,
)# if $n eq "a4" || $n eq "a4";
}
}
}
}
if (1) # Show fiber lines
{my @h = (stroke =>"darkgreen", stroke_width => Fw); # Fiber lines horizontal
my @v = (stroke =>"darkgreen", stroke_width => Fw); # Fiber lines vertical
my @f = @fibers;
( run in 0.654 second using v1.01-cache-2.11-cpan-454fe037f31 )