I'm new to p5js :)
When users press a certain key between 1-0 on the keyboard, a certain sound plays and random image shows. I tried this...
function keyPressed() {
if (key === '2') {
songA.play()
image(imgB1, random(windowWidth), random(windowHeight), img.width/2, img.height/2);
}
But p5js only reads "image" in draw function. Then i tried keyisdown in the draw function and tried entering the keyCodes for each number, for instance 1 is 49 I believe, but it didn't work.
if (keyIsDown(49)) {
songA.play()
image(imgB1,random(windowWidth), random(windowHeight), img.width/2, img.height/2);
}}
I'm basically copying https://openprocessing.org/sketch/441971 from openprocessing which is similar to p5js but not really. Help?
Thanks!
Make sure your image is being preloaded in the setup() function
When you display the image, you are referencing "img" instead of imgB1, which means p5js doesn't know what size to display the image at, so I assume it defaults to 0. To fix this, just replace img with imgB1.
Related
I'm quite new to progamming. So here's my function to select a random image in my drawable folder.
fun generateimage(index:Int)
{var images=arrayOf(R.drawable.img1,....)
main_imageView.setImageResource(images[index])
This works as an image is shown randomly every time I start the application. But I would like to be able to know which image was selected. Preferably from retrieving the image name to string.
Possible duplicate of
How to get drawable name from imageView
However, a better implementation would be to have the value in a list of int and put your R.drawable items inside it. That was you can access which element is being shown.
You can do something like this:
fun main() {
val arrayImages = arrayOf("image1", "image2", "image3", "image4", "image5")
// in your case actual images.
val randomIndex = (0..arrayImages.size).random()
val randomImage = arrayImages[randomIndex]
println(randomImage) // in your case: main_imageView.setImageResource(randomImage)
}
Note that you need to assign the variable of randomImage so you can access it later on. I don't know what type "R.drawable.img1" is, but the object you set inside this array has to store the name of the file, so you can retrieve it that way.
I'm using a class extending AbstractDetailsDescriptionPresenter. The summary text is relatively long. For some reason the text gets cut off after a certain length. I could not figure out how to display the entire text without it being cut off.
I tried viewHolder.getBody().setLines(20); and other property changes but nothing seemed to have the desired effect.
This it the Presenter class I'm using:
public class MovieDetailPresenter extends AbstractDetailsDescriptionPresenter {
#Override
protected void onBindDescription(ViewHolder viewHolder, Object item) {
Video video = (Video) item;
if (video != null) {
viewHolder.getTitle().setText(video.title);
viewHolder.getSubtitle().setText(video.subtitle);
viewHolder.getBody().setText(video.summary);
}
}
}
How can I remove the text length limit/cutting off?
Here a picture to better illustrate what I mean. The text at the bottom right isn't displayed in its full length but gets cut off and adds three dots (...) at the end.
Thanks for any hints/help.
Finally found a solution: Making a custom “AbstractDetailsDescriptionPresenter” without the addPreDrawListener() method (which is causing the problem) and use it in the “DetailsDescriptionPresenter”.
body.setMaxLines(Integer.MAX_VALUE) should do the trick unless you are forcing a specific height somewhere in your LayoutParams. I assume you're setting height to wrap_content? You could try enabling Show Layout Bounds in the developer options to see if your changes have any effect.
Pagination can be accomplished by using sequential Render() calls from http://docs.wxwidgets.org/trunk/classwx_grid.html
I understand How - sequential pages can be got from top left and bottom right coordinates.
But I dont get what needs to be the wxDC in the Render() call . ?
I want to get the first three rows in the grid
BigGridFrame::BigGridFrame(long sizeGrid)
: wxFrame(NULL, wxID_ANY, wxT("Plugin Virtual Table"),
wxDefaultPosition, wxSize(500, 450))
{
m_grid = new wxGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_table = new BigGridTable(sizeGrid);
m_grid->SetTable(m_table, true);
//The above code gave me the table
//trying to get first three rows by render() function but it still gets the all of the grid values
**const wxGridCellCoords topLeft(0, 0);
const wxGridCellCoords bottomRight(3,4 );
wxClientDC clientDC(this); //this place I am not sure.. I couldnt find documentation
//m_grid->SelectBlock(topLeft, bottomRight, false);
m_grid->Render(clientDC, wxDefaultPosition, wxDefaultSize, topLeft, bottomRight, wxEXPAND);**
}
The DC is whatever you want to render the grid on, typically a wxMemoryDC to save the grid as a bitmap. This can't be used to partially render the grid on screen, which you appear to want to do, because it's just a static snapshot of the control.
I also have really no idea how can the code using this->Render() above compile considering that this is a wxFrame* and not a wxGrid*.
I misunderstood Render() function .
For pagination, I used the same logic used in
Changing Size of Grid when grid data is changed
I have a SVG map of france in my webpage and every district is a polygon, I need that when I click a district the color change and stay that way until I click it again
this is my code
function init(evt) {
if ( window.svgDocument == null ) {
svgDoc = evt.target.ownerDocument;
}
function update(district){
$(this).find("path, polygon, circle").attr("fill", "#0d0");<- what is wrong
}
this is one of my polygons
<path id="14" d="M82.387,173.009L109.168,141h2.42l3.33-5.965l20.425,8.818l5.296,0.475l-
1.876,31.861l5.236,7.5v8.018 l-15.6-1.701l
0.273-3.599C128.127,186.407,99.635,180.95,82.387,173.009z" fill="#CCCCCC"
onclick="update('14')">
as you can see Im getting the onclick event the problem is I cant get the polygon to change color.
thanks in advance.
Check what this holds. A console.log(this) will make your life so much more easier
I'll answer 1. This will point to the window object when a function is called. So doing a $(this).attr will find the attributes in the window object and not in the object that you expect.
Since you're passing the object id in the function, you can use that to find the element in your document. You can do something like:
$('#'+ubicacion).attr("fill","blue")
Fiddle here.
I've created a simple mapping widget using Dojo and Google Maps. The map is displayed in a dijit.layout.ContentPane set as the center panel of a dijit.layout.BorderContainer (which has the address field and a BusyButton in its top panel); the BorderContainer is in turn wrapped in a dojox.layout.FloatingPane. The widget has a subscription to a topic that will trigger a refresh of the map display when new address data is provided. The updater function is very simple, and looks like this:
_updateAddress: function(data) {
this.addressMapper.show();
if (data === null || !data.address || data.address === "" ) {
this.address.attr("value", "");
} else {
this.address.attr("value", data.address);
}
this.mapBtn.makeBusy();
this._getMap();
}
Every time I call this function, the FloatingPane's resize() method is invoked when I call show(), and it's increasing the height and width of the BorderContainer by 12 pixels every time the pane is shown (even with doLayout and isLayoutContainer set to false on the FloatingPane). I can't seem to prevent this from happening, or correct it afterwards, no matter what I try.
Anyone have any ideas how to remedy this?
Thanks in advance!
-- Joe M --