How to get yDomain value in ReactVis - react-vis

In React-vis, I display the cursor position of the mouse using a LineSeries. I would like it to extend along all the vertical extent of the FlexibleXYPlot in which it's included:
Image of the cursor on a ReactVis plot
¿How can I get the value of the yDomain of the plot?
Thank you!
Edit
I am using React-vis in clojurescript. I got the line seen in the first image with this code:
[:> rvis/LineSeries {:data [{:x #nearest-x :y y-min}{:x #nearest-x :y y-max}]
:strokeStyle "dashed" :color "black"
:opacity (if #button-pressed? .5 0)}]
And I needed to compute the value of y-min and y-max (that was the meaning of my question).
But then I realized that I can use the Crosshair facility:
[:> rvis/Crosshair {:values [{:x #nearest-x :y 0}]
:style {:line {:opacity (if #button-pressed? .5 0)}}}
[:div]]
Crosshair in React-vis
It's difficult to see (it's under the cursor), because I still can't manage to change its color. I thought that this would work:
[:> rvis/Crosshair {:values [{:x #nearest-x :y 0}]
:style {:line {:color "#000"
:opacity (if #button-pressed? .5 0)}}}
[:div]]
But it doesn't. I think this would be another question. :)
Edit 2
It was :background "black" instead of :color "black". I got it reading the file plot.scss. :)

Related

An autoclicker I wrote to claim twitch channel points isn't working properly, I'd like to understand why

I've used AutoHotKey to write out a program that in theory, should claim the little channel point chests on twitch automatically. However, in practice it just does nothing. I'm a bit of a coding noob so cut me some slack. Below is the code:
o:: ; this is a killswitch in case anything goes wrong
{
exitapp
}
p::
while (true)
{
PixelGetColor, color, 1680, 1060 ; finds the color of a pixel that the chest appears on
if (color = 8FFFD2) ; if the color of that pixel is the color of the chest when it is highlighted
{
Click, 1700, 1060 ; click on where the chest appears
}
}
I tried running this while a chest was there and the code did nothing, I made sure that my mouse was highlighting it too. I also understand that BTTV can claim chests automatically, this is just a little project I'm doing for fun.
All you need to do is have a line of code to move the mouse to the co-ordinates, and then another line to click.
Try this, it should work:
o:: ; this is a killswitch in case anything goes wrong
{
exitapp
}
p::
while (true)
{
PixelGetColor, color, 1680, 1060 ; finds the color of a pixel that the chest appears on
if (color = 8FFFD2) ; if the color of that pixel is the color of the chest when it is highlighted
{
Mousemove, 1700, 1060
click ; click on where the chest appears
}
}

MEEP: How to make an array of flux detectors?

I have been using MIT's MEEP for simulation of THz frequency light transmission in silicon photonics. I needed to make an array of flux detectors in MIT's MEEP so that I wouldn't have to write many (add-flux) blocks of code.
Scheme's map seemed like a good solution, yet, despite there being many people in many forums searching for a way to do this, an implementation of such code is sparse online. Thus, I wanted to share a way of doing it.
In the documentation on the MEEP wiki, adding flux detectors is done in the follow fashion:
(define-param fcen 0.25) ; pulse center frequency
(define-param df 0.4) ; pulse width (in frequency)
(define-param nfreq 4001) ; number of frequencies at which to compute flux
(define refl-det ; reflection detector
(add-flux freq_c pulse_width num_freqs
(make flux-region
(center some-x some-y)
(size 1 0))))
(define trans-det ; transmission detector
(add-flux freq_c pulse_width num_freqs
(make flux-region
(center some-other-x some-other-y)
(size 1 0))))
;;...;; code for running sources
(display-fluxes refl-det trans-det) ; MEEP's function for outputting flux for frequencies
So, if I want 20 transmission detectors and 20 reflection detectors, I would have to define 40 blocks by hard coding them...not good.
There are many variants which can be made on this code. The one presented below is for detectors in a straight line. It is also possible to implement one for detectors placed in a circular arrangement; however, that requires calculating your angles in another function and adding another variable to the detectors function.
; The following is a sample algorithm you can use to get the x values
(define det-sample-length 5)
(define det-start-x-position 25)
(define (refl-det-x-position n) (+ det-start-x-position (* n det-sample-length)))
; Here you use map to return a list of the x positions for the detectors
(define det-positions-x (map refl-det-x-position (list 1 2 3 4 5 6 7 8 9)))
; This is a function to make the array of detectors. It takes the x position as an argument.
(define (detectors det-position-x)
(add-flux freq_c pulse_width num_freqs
(make flux-region
(center det-position-x 0)
(size 0 1))))
; To return a list of detectors based on the above function, map it against the x position list.
(define my-refl-flux-list
(map detectors det-positions-x))
; If you need to put another detector not part of the above series, define it as a "list"
(define source-top-det
(list (add-flux freq_c pulse_width num_freqs
(make flux-region
(center some-x some-y)
(size 1 0)))))
; Here, again, you can make another detector as a list or another array of detectors.
(define source-bottom-det
(list (add-flux freq_c pulse_width num_freqs
(make flux-region
(center some-other-x some-other-y)
(size 1 0)))))
; Finally, before you use "display-fluxes", you must append the detectors into a list.
(define my-flux-list (append source-top-det source-bottom-det my-refl-flux-list))
; And last, but not least, use Scheme's "apply" on "display-fluxes" over "my-flux-list"
(apply display-fluxes my-flux-list)
The most important thing to remember is that the detectors must be contained in a list. Map by its nature makes a list, so this is why you don't define a list in the "detectors" function. Append just joins all of the lists into a bigger list. And you have to use "apply" for "display-fluxes" because you are using it on a list, not directly within the function. Hope this helps!

How can I make an image blink in racket language using a frame counter?

The following procedure is in a racket radar simulator for a flight simulator it displays objects that are locking on your aircraft as an ellipse, we need to get the ellipse to blink (appear and reappear periodically). Using a frame counter, or not, how can this be scripted?
(define rwr-tracking
(let ([p (new dc-path%)])
(send p ellipse 0 0 400 400)
p)
)
Here is an example to get you started:
#lang racket
(define (redraw-radar)
(sleep 0.5) ; 0.5 seconds
(displayln "Drawing")
(flush-output)
(redraw-radar))
(thread redraw-radar)
A new thread is created to the redrawing.
The thread waits, redraws, and, loops.

def negatives in JES

I am trying to show my picture as a negative, and I coded it, but it wont show the picture as a negative, did I do something wrong?
def negative(picButterfly2):
for px in getPixels(picButterfly1):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
ALSO HOW DO I DRAW HORIZONTAL LINES? Thanks!
Try with correct variables names: you have picButterfly2 NOT EQUAL TO picButterfly1:
This works:
def negative(picButterfly1):
for px in getPixels(picButterfly1):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
file = pickAFile()
picture = makePicture(file)
negative(picture)
show(picture)
Also look at:
This (for negating images).
This (for drawing lines) - or any of those.
Your variables "red", "blue", and "green" already have a function in it, change it to a single character or just a capital letter like "Red". I know this was posted in 2014 but I'll leave a comment for the future.

How to determine whether colour is within a range of shades

I am not sure if this is possible as I have been looking for a few hours and cant find what I am looking for.
What i am doing is taking a color from a game panel which is semi translucent so the color which I am taking is always subtly changing. What is need is a way to check if it is +/- 10 or so shades of my desired color.
Something like
If color1 is +/-10 of 0x?
I have tried using the image search to do similar but that didn't work.
Any help would be greatly appreciated
In addition to Robert's answer, you can compare the colors mathematically.
First start by separating the Red, Green, and Blue values.
ToRGB(color) {
return { "r": (color >> 16) & 0xFF, "g": (color >> 8) & 0xFF, "b": color & 0xFF }
}
Then we need a function that compares the colors. Each of thee variables holds a number representing the difference in the two color values. For example if red is 255 in c1, and 200 in c2, rdiff will be 55. We use Abs so that we don't end up with -55 when c2 has a higher value. Then we make sure the difference for each of these is less than our vary.
Compare(c1, c2, vary=20) {
rdiff := Abs( c1.r - c2.r )
gdiff := Abs( c1.g - c2.g )
bdiff := Abs( c1.b - c2.b )
return rdiff <= vary && gdiff <= vary && bdiff <= vary
}
Here's how it can be used. We take some numbers, and then compare them to each other with the default vary of 20.
light_pink := ToRGB(0xFFAAFF)
darker_pink := ToRGB(0xFAACEF)
purple := ToRGB(0xAA00FF)
MsgBox % Compare(light_pink, dark_pink) ; True
MsgBox % Compare(light_pink, purple) ; False
I assume that your read about the limitations of PixelGetColor: Known limitations:
"A window that is partially transparent or that has one of its colors marked invisible (TransColor) typically yields colors for the window behind itself rather than its own.
PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word Alt or Slow in the last parameter."
When using ImageSearch, you can specify the Delta of the colours. Example:
ImageSearch, FoundX, FoundY, %SearchRangeLeft%, %SearchRangeTop%, %SearchRangeRight%, %SearchRangeBottom%, *20 %ImageFile%
Here the *20 indicates the variation in the range from 0 to 255 of my search colour. When searching for a pixel inside the image of 100,100,100 (RGB), it will match anything between 80,80,80 and 120,120,120. Hope this helps, but matching transparent colours is difficult and prone to errors. The smaller the image and search range the better (and faster)