Adding array of images to the stage with easeljs and preloadjs - easeljs

Different images should appear on stage. For this I am trying to create an array and put it in a container but id doesn't work. What am I doing wrong? Thanks
canvas = document.getElementById("testCanvas");
stage = new createjs.Stage(canvas);
var queue = new createjs.LoadQueue(true);
var imagesPic = queue.loadManifest(["image1.png", "image2.png","image3.png","image4.png"]);
var w = canvas.width = window.innerWidth;
var h = canvas.height = window.innerHeight;
container = new createjs.Container();
stage.addChild(container);
captureContainers = [];
captureIndex = 0;
for (var i=0; i<50; i++) {
container.addChild(imagesPic);
}
for (i=0; i<100; i++) {
var captureContainer = new createjs.Container();
captureContainer.cache(0,0,w,h);
captureContainers.push(captureContainer);
}

Related

syncfusion_flutter_PDF add photos

How can I put a photo in this place I want in the PDF?
I want add photo this code block(contentRow1.cells[0].value = 'fotoğraflar gelecek';)
Future<PdfGrid> _addContentRow_2(
String srNo,
PdfGrid grid,
PdfStringFormat format,
PdfStringFormat middleFormat,
PdfPaddings padding) async {
//Add a row
final PdfGridRow contentRow1 = grid.rows.add();
//Set height
contentRow1.height = 150;
//Set values and style properties
//contentRow1.cells[0].value = srNo;
contentRow1.cells[0].style.stringFormat = format;
//Set row span
contentRow1.cells[0].rowSpan = 1;
contentRow1.cells[0].value = 'fotoğraflar gelecek';
contentRow1.cells[0].columnSpan = 4;
return grid;
}

How to add button in scroll View using script in unity

I am new to unity and am using unity 2020.3.26f1 . I am receiving an array of names from server. I want to make buttons dynamically using those names inside scroll view using c# script and assign on Click() that simply prints the name of button when its clicked. I just don't know how to create button dynamically. Following is the script I have attached to scroll View;
public string allNames;
void Start()
{
StartCoroutine(getNames());
}
IEnumerator getNames()
{
UnityWebRequest www = UnityWebRequest.Get("http://localhost:8080/names");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
allNames = www.downloadHandler.text;
allNames = allNames.Replace("[", "");
allNames = allNames.Replace("]", "");
allNames = allNames.Replace("\"","");
string[] separatedNames = allNames.Split(',');
for (int i = 0; i < separatedNames.Length; i++)
{
Debug.Log(separatedNames[i]);
//make buttons here and attach them to scroll View
}
}
}
I found a video that applied #ShafqatJamilKhan suggestion. Posting my code here for reference.
//content reference of scroll view
[SerializeField] Transform contentPanel;
[SerializeField] GameObject buttonPrefab;
void Start()
{
StartCoroutine(getNames());
}
IEnumerator getNames()
{
UnityWebRequest www = UnityWebRequest.Get("http://localhost:8080/names");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
string allNames = www.downloadHandler.text;
allNames = allNames.Replace("[", "");
allNames = allNames.Replace("]", "");
allNames = allNames.Replace("\"","");
// prefab button y position and yPosition should be the same.
float yPosition = 115;
string[] separatedNames = allNames.Split(',');
for (int i = 0; i < separatedNames.Length; i++)
{
GameObject button = (GameObject)Instantiate(buttonPrefab);
string name = separatedNames[i];
button.GetComponentInChildren<Text>().text = name;
button.GetComponent<Button>().onClick.AddListener(
// your function whatever you want to do
() => { customFunction(name); });
// applying y positions so the buttons dont overlap
button.transform.SetPositionAndRotation(new Vector3(0.0f, yPosition, 0.0f), new Quaternion(0.0f, 0.0f, 0.0f,0.0f));
button.transform.SetParent(contentPanel,false);
yPosition -= 35;
}
}
}
Make a nice button and save it as prefab.
Instantiate it or Pool it.
Add onClick events.
GameObject buttonPrefab;
void MyAwesomeCreator()
{
GameObject go = Instantiate(buttonPrefab);
var button = GetComponent<UnityEngine.UI.Button>();
button.onClick.AddListener(() => FooOnClick());
}
void FooOnClick()
{
Debug.Log("Ta-Da!");
}
Copied from Unity Forum

Getting value from unSafeMutablePointer Int16 in Swift for audio data purposes

I'm working to convert to Swift this code which helps get me get audio data for visualizations. The code I'm working with in Obj C, which works well, is:
while (reader.status == AVAssetReaderStatusReading) {
AVAssetReaderTrackOutput *trackOutput = (AVAssetReaderTrackOutput *)[reader.outputs objectAtIndex:0];
self.sampleBufferRef = [trackOutput copyNextSampleBuffer];
if (self.sampleBufferRef) {
CMBlockBufferRef blockBufferRef = CMSampleBufferGetDataBuffer(self.sampleBufferRef);
size_t bufferLength = CMBlockBufferGetDataLength(blockBufferRef);
void *data = malloc(bufferLength);
CMBlockBufferCopyDataBytes(blockBufferRef, 0, bufferLength, data);
SInt16 *samples = (SInt16 *)data;
int sampleCount = bufferLength / bytesPerInputSample;
for (int i=0; i<sampleCount; i+=100) {
Float32 sample = (Float32) *samples++;
sample = decibel(sample);
sample = minMaxX(sample,noiseFloor,0);
tally += sample;
for (int j=1; j<channelCount; j++)
samples++;
tallyCount++;
if (tallyCount == downsampleFactor) {
sample = tally / tallyCount;
maximum = maximum > sample ? maximum : sample;
[fullSongData appendBytes:&sample length:sizeof(sample)];//tried dividing the sample by 2
tally = 0;
tallyCount = 0;
outSamples++;
}
}
CMSampleBufferInvalidate(self.sampleBufferRef);
CFRelease(self.sampleBufferRef);
free(data);
}
}
In Swift, I'm trying to write is this part:
while (reader.status == AVAssetReaderStatus.Reading) {
var trackOutput = reader.outputs[0] as! AVAssetReaderTrackOutput
self.sampleBufferRef = trackOutput.copyNextSampleBuffer()
if (self.sampleBufferRef != nil) {
let blockBufferRef = CMSampleBufferGetDataBuffer(self.sampleBufferRef)
let bufferLength = CMBlockBufferGetDataLength(blockBufferRef)
var data = NSMutableData(length: bufferLength)
CMBlockBufferCopyDataBytes(blockBufferRef, 0, bufferLength, data!.mutableBytes)
var samples = UnsafeMutablePointer<Int16>(data!.mutableBytes)
var sampleCount = Int32(bufferLength)/bytesPerInputSample
for var i = 0; i < Int(sampleCount); i++ {
var sampleValue = CGFloat(samples[i]) etc. etc.
However, when I println() sampleValue is just comes out (Opaque Value) in the console. I can't figure out how to actually read the sampleValue.
I'm new at trying to read audio data for visualization purposes. Any help on getting a buffer of audio data to work with would be helpful. Thank you.
Use stride?
let bytesPerInputSample = 4 // assumption ;)
var samplePtr = data.mutableBytes
for _ in stride(from: 0, to: data.length, by: bytesPerInputSample) {
let currentSample = Data(bytes: samplePtr, count: bytesPerInputSample)
// do whatever is needed with current sample
//...
// increase ptr by size of sample
samplePtr = samplePtr + bytesPerInputSample
}

appcelerator titanium iPhone twitter timeline resize

I'm working in appcelerator and I have a tab which is the profile. On the top half there is the profile picture, the name, and other misc items, then on the bottom half is a twitter timeline. When i started putting on the twitter timeline code, it takes up the whole screen. Is there a way to reduce the timeline to only take up a portion of the screen to be able to see the other items?
This is my twitter timeline code:
var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" +
"user_timeline.json?count=10&screen_name=" + twitterUserName);
var twitterData = [];
httpClient.onload = function() {
try {
var tweets = JSON.parse(this.responseText);
for (var i=0; i < tweets.length; i++) {
var tweetText = tweets[i].text;
var user = tweets[i].user.screen_name;
var avatar = tweets[i].user.profile_image_url;
var created_at = tweets[i].created_at;
var row = Ti.UI.createTableViewRow({hasChild:true,
height:'auto'});
var postView = Ti.UI.createView({
height:'55',
top:5,
bottom:5,
left:5,
right:5,
});
var avatarImageView = Ti.UI.createImageView({
image:avatar,
left:0,
top:0,
height:48,
width:48
});
postView.add(avatarImageView);
var userLabel = Ti.UI.createLabel({
text:user,
left:54,
width:120,
top:-48,
bottom:2,
height:16,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,
fontWeight:'bold'}
});
postView.add(userLabel);
var dateLabel = Ti.UI.createLabel({
text:created_at,
right:0,
top:-18,
bottom:2,
height:14,
textAlign:'right',
width:110,
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12}
});
postView.add(dateLabel);
var tweetTextLabel = Ti.UI.createLabel({
text:tweetText,
left:54,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
postView.add(tweetTextLabel);
row.add(postView);
twitterData[i] = row;
}
var tableview = Titanium.UI.createTableView({data:twitterData,
minRowHeight:58});
win1.add(tableview);
}
catch(E) {
alert(E);
}
};
httpClient.send();
Please keep in mind .. We need to use either top and left or bottom and right.. dont mix up top and bottom in same element....
coming to solution to yours .. give top to table so that it goes down .......
i have created top view where you can specify username and etc
below you can post timeline
var win1=Ti.UI.createWindow()
///// this is top portion
var topView=Ti.UI.createView({
top:0,
left:0,
height:100,
background:"#2d2d2d"
})
var username=Ti.UI.createLabel({
text:"foundationsix",
color:"#fff"
})
topView.add(username)
win1.add(topView)
var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" + "user_timeline.json?count=10&screen_name=" + twitterUserName);
var twitterData = [];
httpClient.onload = function() {
try {
var tweets = JSON.parse(this.responseText);
for (var i=0; i < tweets.length; i++) {
var tweetText = tweets[i].text;
var user = tweets[i].user.screen_name;
var avatar = tweets[i].user.profile_image_url;
var created_at = tweets[i].created_at;
var row = Ti.UI.createTableViewRow({hasChild:true,
height:'auto'});
var postView = Ti.UI.createView({height:55});
var avatarImageView = Ti.UI.createImageView({
image:avatar,
left:0,
top:0,
height:48,
width:48
});
postView.add(avatarImageView);
var userLabel = Ti.UI.createLabel({
text:user,
left:54,
width:120,
top:-48,
bottom:2,
height:16,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,
fontWeight:'bold'}
});
postView.add(userLabel);
var dateLabel = Ti.UI.createLabel({
text:created_at,
right:0,
top:-18,
bottom:2,
height:14,
textAlign:'right',
width:110,
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12}
});
postView.add(dateLabel);
var tweetTextLabel = Ti.UI.createLabel({
text:tweetText,
left:54,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
postView.add(tweetTextLabel);
row.add(postView);
twitterData[i] = row;
}
var tableview = Titanium.UI.createTableView({
data:twitterData,
minRowHeight:58,
top:100
});
win1.add(tableview);
}
catch(E) {
alert(E);
}
};
httpClient.send();
win1.open()

cocos2d content.size, boundingBox and size

im writing a game to find the differences between 2 images. i created a subclass of CCSprite, Spot. firstly i tried to create small images and add itself according to it's position, but later i found the position is hard to determine, since it's hard to avoid offset of 1 or 2 pixels.
then i tried to make the Spot the same size as the image, with the other part transparent. but I still need to find out the 'hotspot' of finger tap. but when i use CGRectContainsPoint([self boundingBox], touchLocation), it's actually the whole image.
so is there any other way to do this? like content.size or self.size, and make a CGRect out of it's non-transparent part?
Thank you.
I figured it out now. here is my code: (it's actually quite simple
-(void) findRect:(NSString*) fn {
//the origin of mTex is top left
//the origin of CGRect is top left, in the coordinate system inside the image
int topLeftX = 0;
int topLeftY = 0;
for (int i = 0; i < image_width; i += 10) {
for (int j = 0; j < image_height; j += 10) {
if (([mTex pixelAt:ccp(i, j)].a & 0xFF) != 0) {
topLeftX = i;
topLeftY = j;
goto outer;
}
}
}
outer:;
int topRightX = 0;
for (int i = topLeftX; i < image_width; i += 10) {
if (([mTex pixelAt:ccp(i, topLeftY)].a & 0xFF) == 0) {
topRightX = i;
break;
}
}
if (topRightX == 0) {
topRightX = image_width - 1;
}
int bottomLeftY = 0;
for (int i = topLeftY; i < image_height; i += 10) {
if (([mTex pixelAt:ccp(topLeftX, i)].a & 0xFF) == 0) {
bottomLeftY = i;
break;
}
}
if (bottomLeftY == 0) {
bottomLeftY = image_height - 1;
}
areaRect = CGRectMake(topLeftX, topLeftY, topRightX - topLeftX, bottomLeftY - topLeftY);
}