Question update: I'm almost there, just missing dotted line style for the grid.
grid: [1100 600]
step-grid: 5
max-n-points: grid/1 / step-grid
x-axis-border: 20
Y-margin: 10
max-random: 1000
n-points: 300
get-random-data: func[n p][
block: copy []
repeat i n [
append block RANDOM p
]
block
]
get-extremes: func[block][
extreme: none
foreach element block [
if none? extreme [
extreme: copy []
repeat i 2 [append extreme element]
]
if element > extreme/1 [
extreme/1: element
]
if element < extreme/2 [
extreme/2: element
]
]
extreme
]
data0: get-random-data n-points max-random
extremes: get-extremes data0
height: extremes/1 - extremes/2
ratio: (grid/2 - x-axis-border - (Y-margin * 2)) / height
data: copy []
foreach element skip data0 (n-points - max-n-points) [
append data to-integer (ratio * element)
]
plot: copy []
color: 0.0.0
append plot [
pen green line
]
x: 0
foreach y data [
append plot as-pair x (grid/2 - x-axis-border - Y-margin) - y
x: x + 5
]
main: layout [
origin 20x0
space 1x1
panel1: box 1100x580 black effect reduce [
'line-pattern 4 4
'grid 30x30 0x0 200.200.200
'draw plot
]
panel2: box 1100x0 black
panel3: box 1100x20 black
]
view main
=== former question
The space between each box is too big and I cannot draw dotted grid, how to do this ?
plot: copy []
color: 0.0.0
append plot [line-pattern 4 4]
repeat x 400 [
repeat y 200 [
append plot compose [
box (xy: 25 * as-pair x - 1 y - 1) (xy + 25)
]
]
]
main: layout [
origin 0x0
panel1: box 800x400 black effect reduce ['draw plot]
panel2: box 800x180 black
panel3: box 800x20 black
]
view main
use the space keyword to control spacing
See http://www.rebol.com/docs/view-guide.html#section-29
Also, you can use the 'grid for drawing a grid
"grid Generate a two dimensional grid of lines. This is a useful backdrop for graphical layout programs. The optional arguments are: a PAIR that specifies the horizontal and vertical spacing of the grid lines, a PAIR that specifies the offset of the first lines, a PAIR that indicates the THICKNESS of the horizontal and vertical lines, and a TUPLE that provides the color of the lines."
Related
I am trying to graph the construction of Thompson using graphviz, and I would like to know if anyone could help me graph one of the rules so that I can do the others.
I attach a reference image: https://en.wikipedia.org/wiki/Thompson%27s_construction#/media/File:Thompson-kleene-star.svg
digraph finite_state_machine {
rankdir=LR;
size="8,5"
node [shape = doublecircle]; s3;
node [shape = circle];
s0 -> s1 [ label = "ε" ];
s0 -> s3 [ label = "ε" ];
s1 -> s2 [ label = "ε" ];
s2 -> s1 [ label = "ε" ];
s2 -> s3 [ label = "ε" ];
}
Graphviz programs try to avoid placing nodes on top of other nodes. You can get the node placement by explicitly providing pos attributes for all the nodes. (Not that difficult, but a nuisance.) You can get neato to generate all straight edges, but you will have to provide the (spline) coordinates for all the arcs. Otherwise you get this:
As an alternative, instead of graphviz, if you use dpic or gpic, this program:
.PS
.defcolor pink rgb #FFC0CB
circlerad=circlerad*.8
## we need to place the large oval before we place nodes on it
Qx: circle invis ; line invis; circle invis; A: line invis;
ellipseht=ellipseht*2;
ellipsewid=ellipsewid*2
E:ellipse at A.c shaded "pink" " N(s)"
move to Qx.w
Q: circle "q" ; arrow "ε" ""; C1: circle ; A: line invis; C2: circle ; arrow "ε" ""; F: circle "f";
circlerad=circlerad*.8
F1:circle at last circle
move to E.n; up; P1: box invis "ε"
arc -> from C2.n to C1.n
arcrad=2
arc -> from Q.s to F.s
### gpic version of greek chars:
# move to E.s; down; box invis "" "\[*e]"
########################################
### dpic/svg version of greek chars
move to E.s; down; box invis "" "ε"
.PE
produced this:
gpic is part of the GNU (Linux) groff package.
dpic can be found here: https://ece.uwaterloo.ca/~aplevich/dpic/
I have a 3d game where I will create an rectangle which is working as screen and the game itself works with vectors to positions. so I will create an rectangle and have only these parameters aviable:
start position ->vector (x,y,z).
Angle(rotation) of object(x,y,z).
size of rectangle.
now also the object need to be roatet to the right side so they are using angels also (x,y,z).
example:
position:-381.968750 -28.653845 -12702.185547
angle: -0.000 90.000 90.000
What I will create is an little bit hard but as idea simple.
I choose 2 complete different positions and angles and will create from the first vector to the second an rectangle.
I can only create an rectangle with the start point and angle.
and I can set the size so (x,y)
So I will now insert 2 positions(vectors) with 2 different angles
The rectangle will have the middle value between the first and second angle so like (90 and 0) -> 45
And the rectangle will start at the start vector and will end with his own size so I don't have a chance to use the end vector directly.
Legendary on photo:
Green=>start and end positions(vectors).
red => the marked zone.
Blue => how I will have the rectangle.
aem_point = vgui.Create( "AEM.Main.Panel" )
if IsValid(aem_point) then
aem_point:SetSize( 2,2 ) -- <-the size that i can set
aem_point:SetPos( 0, 0 )
aem_ph = vgui.Create( "DHTML", aem_point )
aem_ph:SetSize( aem_point:GetSize() )
aem_ph:SetPos(aem_point:GetPos())
aem_ph:SetVisible( true )
aem_ph:SetHTML([[
<html>
<body style="margin:0px;padding:0px;font-size:20px;color:red;border-style: solid;border-color: #ff0000;background-color:rgba(255,0,0,0.1);">
</body>
</html>
]] )
end
hook.Add( "PostDrawOpaqueRenderables", "DrawSample3D2DFrame" .. math.random(), function()
if first and dat_finish then
vgui.Start3D2D( input_position, input_angle, 1 ) -- <-and position&vec
aem_point:Paint3D2D()
vgui.End3D2D()
end
end )
Oh so you want to create a 3d2d plane from 2 vector positions?
Vec1 = A
Vec2 = B
input_position = ( Vec1 + Vec2 ) / 2
A problem you will run into is you need 3 points to generate a plane, so while you can get the position of the screen to get the angle of it you will need another point.
If these screens of yours are staticly set, as in you put their position into the lua code manually and dont intend to have it move or anything, just manually putting in the angle is by far the most simple approch.
As you can see, both of these planes are on the same two points, but they have diffrent angles.
I wrote the demo in expression 2, this should make it clear as to how this works, if you have any other questions just ask.
A = entity(73):pos()
B = entity(83):pos()
if(first())
{
holoCreate(1)
holoCreate(2)
}
holoPos(1,(A+B)/2)
holoScaleUnits(1,vec( abs(B:y() - A:y()) , 1 , abs(sqrt( ( B:z() - A:z() ) ^ 2 + ( B:x() - A:x() ) ^ 2 ))))
holoAng(1,ang(0,90,45))
holoPos(2,(A+B)/2)
holoScaleUnits(2,vec( abs(sqrt( ( B:x() - A:x() ) ^ 2 + ( B:y() - A:y() ) ^ 2 )) , 1 , abs(B:z()-A:z())))
holoAng(2,ang(0,45,0))
Part of what I am trying to do is make a breed of turtles move around, but when one reaches its destination that turtle waits for a certain number of ticks before continuing ? Also is it possible to make turtles wait for different number of ticks depending upon their destination ( different patch colors). Is it a case of making a turtle breed or global variable to count the number of ticks? The hopefully relevant code is below.
You are right, this can be done by making the turtles count the number of ticks they have been on a patch. Also this has to be a turtle variable and not a global variable since each turtle will have a different value for this
The approach, I have used is this:
Once the turtle arrives at its destination record the ticks (the global variable which records the number of ticks that have passed till now) into a turtle variable say ticks-since-here. This works like a time-stamp.
On each successive tick check the difference between the current-time ticks global variable and the ticks-since-here turtle variable. If this becomes greater than the number of ticks the turtle is allowed to stay on the patch, let it choose and move to the new destination.
breed [visitors visitor]
globals [ number-of-visitors ]
visitors-own [
; visitors own destination
destination
ticks-since-here
]
to go
ask visitors [
move
]
tick
end
to move
; Instructions to move the agents around the environment go here
; comparing patch standing on to dest, if at dest then choose random new dest
; then more forward towards new dest
ifelse ( patch-here = destination )
[
if ticks - ticks-since-here > ticks-to-stay-on-patch patch-here
[
set ticks-since-here 0
set destination one-of patches with
[
pcolor = 65 or pcolor = 95 or pcolor = 125 or pcolor = 25 or pcolor = 15 or pcolor = 5
]
]
]
[
face destination
forward 1
if ( patch-here = destination )
[
set ticks-since-here ticks
]
]
end
to-report ticks-to-stay-on-patch [p]
if [pcolor] of p = 65
[
report 6
]
if [pcolor] of p = 95
[
report 5
]
if [pcolor] of p = 125
[
report 4
]
if [pcolor] of p = 25
[
report 3
]
if [pcolor] of p = 15
[
report 2
]
if [pcolor] of p = 5
[
report 1
]
end
to setup-people
;;;; added the following lines to facilitate world view creation
ask patches
[
set pcolor one-of [65 95 125 25 15 5]
]
set number-of-visitors 100
;;;;
create-visitors number-of-visitors
[
ask visitors
[
; set the shape of the visitor to "visitor"
set shape "person"
; set the color of visitor to white
set color white
; give person a random xy
setxy (random 50) (random 50)
; set visitors destination variable
set destination one-of patches with
[
pcolor = 65 or pcolor = 95 or pcolor = 125 or pcolor = 25 or pcolor = 15 or pcolor = 5
]
]
]
end
I have the following code:
digraph g {
graph [rankdir="LR" ,compound="true" ];
subgraph cluster0 {
graph [label="Ready\n\nAllowed Purchaser Operations:\noperation1,operation2\n\nAllowed Supplier Operations:\noperation1,operation3" ];
1 [ shape="none" ,fontcolor="white" ];
};
subgraph cluster2 {
graph [label="Paused\n\nAllowed Purchaser Operations:\noperation1,operation3\n\nAllowed Supplier Operations:\noperation2,operation3" ];
3 [ shape="none" ,fontcolor="white" ];
};
subgraph cluster4 {
graph [label="Completed\n\nAllowed Purchaser Operations:\noperation4\n\nAllowed Supplier Operations:\noperation4" ];
5 [ shape="none" ,fontcolor="white" ];
};
1 -> 3 [ ltail="cluster0" ,lhead="cluster2" ,comment="6" ];
1 -> 5 [ ltail="cluster0" ,lhead="cluster4" ,comment="7" ];
3 -> 1 [ ltail="cluster2" ,lhead="cluster0" ,comment="8" ];
3 -> 5 [ ltail="cluster2" ,lhead="cluster4" ,comment="9" ];
}
I want to increase the distance between the subgraphs. I've tried using len, margin, pad, but the syntax I've tried doesn't work. Can somebody help me?
I think what you are looking for (as Emden points out) are indeed the nodesep and ranksep attributes.
graph [nodesep=6, ranksep=4];
The result would be:
Clusters are derived objects; their layout depends solely on the nodes contained in them. Thus, to alter the cluster spacing, you need to alter the node spacing. Try setting the ranksep and nodesep attributes to larger values.
I have an MxNx2 array of 2D points, where each point represents the center of a measured property of a grid. The graphical representation is below, with white points being the positions:
The point structure is like this (shape: MxNx2):
[[[xij, yij], [xij, yij], ...]],
[[xij, yij], [xij, yij], ...]],
[[xij, yij], [xij, yij], ...]],
[ ..., ...., ............... ],
[[xij, yij], [xij, yij], ...]]]
The desired output would be like this:
[[[x1, x2], [y1, y2]],
[[x1, x2], [y1, y2]],
....................,
[[x1, x2], [y1, y2]]
So that I could plot every segment one by one (using each pair of x,y positions) like this:
I have trying something similar to:
segments = []
for row in xrange(a.shape[0] - 1):
for col in xrange(a.shape[1] - 1):
here = a[row, col]
below = a[row+1, col]
right = a[row, col+1]
segments.extend(((here, right), (here, below)))
but that leaves the right and bottom edges uncovered. Also, I suspect this is a somewhat "dumb", non-vectorized, brute-force way of doing it, it seems to be a common enough problem to have perhaps a mesh-creating function for it.
Any suggestion is welcome!
It can be done by adding segments separately for axis:
for row in xrange(a.shape[0]):
segments.extend( (a[row, col], a[row, col+1]) for col in xrange(a.shape[1] - 1) )
for col in xrange(a.shape[1]):
segments.extend( (a[row, col], a[row+1, col]) for row in xrange(a.shape[0] - 1) )
Or with zip():
s1 = (a.shape[0]*(a.shape[1]-1), 2)
s2 = (a.shape[1]*(a.shape[0]-1), 2)
segments = list(zip( a[:,:-1].reshape(s1), a[:,1:].reshape(s1))) + \
list(zip( a[:-1,:].reshape(s2), a[1:,:].reshape(s2)))
In case someone is interested, I modified the code I was using and it now works, perhaps not so elegantly or eficiently, but...
pairs = []
for row in xrange(pointarray.shape[0]):
for col in xrange(pointarray.shape[1]):
here = pointarray[row, col]
if row < pointarray.shape[0]-1:
below = pointarray[row+1, col]
pairs.append((here, below))
if col < pointarray.shape[1]-1:
right = pointarray[row, col+1]
pairs.append((here, right))