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

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.

Related

How to get yDomain value in ReactVis

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. :)

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
}
}

Is it possible to change the pensize of a drag-able poly in turtle?

I'm trying to change the pensize of a drag-able poly in turtle, so that the poly would have a broad border around it? Here is part of the code:
from turtle import Turtle,Shape,Screen
def simple_polygon(turtle):
shape = Shape("compound")
turtle.begin_poly()
turtle.circle(50)
shape.addcomponent(turtle.get_poly(), "yellow", "green") # component #2
screen.register_shape("simple_polygon", shape)
turtle.reset()
def drag_handler(turtle, x, y):
turtle.ondrag(None) # disable ondrag event inside drag_handler
turtle.goto(x, y)
turtle.ondrag(lambda x, y, turtle=turtle: drag_handler(turtle, x, y))
screen = Screen()
magic_marker = Turtle()
simple_polygon(magic_marker)
magic_marker.hideturtle()
mostly_green = Turtle(shape="simple_polygon")
mostly_green.penup()
mostly_green.goto(150, 150)
mostly_green.ondrag(lambda x, y: drag_handler(red, x, y))
screen.mainloop()
Can someone show me how it's done?
Is it possible to change the pensize of a drag-able poly in turtle, so
that the poly would have a broad border around it?
Yes it is. Not at polygon creation nor registration time, but via the outline argument to shapesize() (aka turtlesize()) once it has been set as the turtle cursor:
from turtle import Screen, Turtle
def drag_handler(x, y):
turtle.ondrag(None) # disable event inside handler
turtle.goto(x, y)
turtle.ondrag(drag_handler)
screen = Screen()
turtle = Turtle()
turtle.begin_poly()
turtle.circle(50)
turtle.end_poly()
screen.register_shape('simple_polygon', turtle.get_poly())
turtle.reset()
turtle.shape('simple_polygon')
turtle.color('green', 'yellow')
turtle.shapesize(outline=25)
turtle.penup()
turtle.ondrag(drag_handler)
screen.mainloop()
This is not an answer to the question cited, as compound turtles take on many forms, and are not draggable. But it is a useful thing to do:

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!

NetLogo: procedure for performing an operation on one item in a list in a compact way?

New to NetLogo... wondering if there's a procedure that performs an operation on one item in a list in a compact way (like map but for one item).
For example, say I wanted to add 3 to the item at index i in list blah.
Right now I'm doing this like:
set blah replace-item i blah (item i blah + 3)
It seems a little clunky, and like there would be a procedure that does that, but I haven't been able to find one. Just wanted to make sure I wasn't missing something.
Thank you!
Taylor
There isn't something built in that does this. But you could define it yourself as a procedure that takes a task as input:
;; replace item i of xs with the result of applying fn to that item
to-report mapping-replace-item [i xs fn]
report replace-item i xs (runresult fn item i xs)
end
Sample usage:
observer> show mapping-replace-item 2 [10 20 30 40] task [? * ?]
observer: [10 20 900 40]