processing

Need help adding a class and animations to a simple pet drawing?

寵の児 提交于 2019-12-25 04:10:03
问题 float x = 100; float y = 100; float p = 150; float l = 10; float a = 100; float b = 100; float n =20; int value = 255; int r = 150; int t = 100; int s = 100; int w = 60; int h = 60; int z = 11; int eyeSize = 10; int pigNose = 30; int pigBody = 30; int pigEars = 35; int pigTail = 20; int otherpigTail = 200; int speed = 1; void setup () { size (600, 600); a = width/2.5; b = height/2; } void draw() { background(184, 233, 249); //Draw legs stroke(0); fill(249, 137, 244); rect(x+(2*w), y+h/3.5, z,

How to create array from a class constuctor?

筅森魡賤 提交于 2019-12-25 03:47:53
问题 So basically I have a class with my program and it's constructing rain elements for my animation. I was wondering how can I use arrays to create say 50 objects from this class but at the same time alternate the data in the objects. void setup() { size (400,400); noStroke(); rain = new Rain(20,random(0,10),3,15); rain2 = new Rain(random(15,35), random(70,110),3,15); } void draw() { background(0); rain.colour(125,155,100); rain.display(); rain2.colour(125,155,100); rain2.display(); } This is

Processing: Cube rotating stay in one place while moving

寵の児 提交于 2019-12-25 03:04:37
问题 In the Processing program, I have to make a cube to move in place where the cube moves when pressing lowercase x for counterclockwise of x axis, or pressing capital X for clockwise of x axis, and pressing lowercase y for counterclockwise of y axis, or pressing capital Y for clockwise of y axis, and pressing lowercase z for counterclockwise of z axis, and pressing capital Z for for clockwise for z axis. The problem is that the cube moves out of place, but it does rotate. How do I rotate, but

PShapeSVG contains() function doesn't work when scale() is applied

二次信任 提交于 2019-12-25 03:03:49
问题 As the title said, why doesn't it work if I scale the shape doing shape.scale(0.5) ? It doesn't work even if I do shape(0,0,200,200) meaning I draw the shape not in the original dimensions. Is this a bug or I'm missing something? 回答1: It kind of is a bug, although I'm not sure how severe. As you found out from your test the contains() method doesn't work when transformations(translation/rotation/scale) are used. I've got two somewhat hacky workarounds: Storing a separate array of vertices,

Processing: Getting the volume of a playing sound file in Processing

最后都变了- 提交于 2019-12-25 02:58:23
问题 I'm trying to write an animation which changes according to the volume of music being played. How do I get the volume of music that is playing in Processing. 回答1: import ddf.minim.spi.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.ugens.*; import ddf.minim.effects.*; Minim minim; AudioInput in; void setup() { minim = new Minim(this); in = minim.getLineIn(); } void draw() { float level = in.mix.level(); // value from 0 to 1 background(255 *

How do global variables work in jquery/javascript? (beginner-level)

亡梦爱人 提交于 2019-12-25 00:27:42
问题 I basically want to know how global variables work in a javascript/JQuery environment. I am most familiar with a language called processing which I've been told is java-based. I expected variables in javascript and JQuery to behave like the ones in processing, but they do NOT work as I expect and I cannot for the life of me wrap my head around it. I have a very simple example made up to illustrate my confusion: var what=""; $(document).ready(function(){ $("p").click(function () { what="p"; })

Declaration of 2 Dimensional Array in Processing

帅比萌擦擦* 提交于 2019-12-24 23:17:53
问题 It is possible in processing to initialize and declare a one dimensional array in two steps, or in one. int []a; a= new int[100]; which is equivalent to : int [] a=new int [100]; I would like to know if there is a similar method as above to do the same for 2 dimensional array. int [][] array= new int[100][200]; 回答1: // this?? int[][] a; a = new int [100][200]; println("a.\'x\' length: " + a.length); println("a.\'y\' length: " + a[0].length); //or maybe... this? int[][] b; b = new int [100][];

how to create in best way an instance from the class object

余生颓废 提交于 2019-12-24 21:04:46
问题 There is a way to avoid the slow reflection to create an instance from a class, obviously within another method ? For example: Foo foo = new Foo(); foo.create(Dog.class, "rocky"); class Foo { Object create(Class object, String dogName) { //create an instance of the class 'object' here passing the argument to constructor //e.g. Object obj = new object(dogName); <-- this is wrong return obj; } } class Dog extends Animal { Dog(String dogName) { this.name = dogName; } } class Animal { String name

Processing, Rotate rectangle using matrix?

隐身守侯 提交于 2019-12-24 20:13:59
问题 I am trying to rotate a rectangle without using the rotate function, but instead using a matrix..I know how to rotate a line using a matrix but all my attempts to rotate a rectangle have failed. I dont think this is use full but heres is my code that rotates the line. float[][] rotation; float[] position; float theta = 180; float pointX; float pointY; void setup() { frameRate(60); size(600, 600); pointX = 0; pointY = 0; rotation = new float[2][2]; position = new float[8]; } void draw() {

how to send 100 digit in serial communication from processing to arduino

痴心易碎 提交于 2019-12-24 19:29:20
问题 i am converting pixel array to String and send this String to arduino. but i Think this String is not converted properly because Serial.write send (8 bit or 8 character) i don’t know. and also want to send 100 character of string into Serial . please send your suggestion and getting help me out of this problem. for any mistake Sorry in advance. for(int x =0 ; x < img.height; x++) { for(int y=0; y <img.width; y++) { int i = x+y*width; if(img.pixels[i] == color(0,0,0)) { i=1; } else { i=0; }