Tag wittgenstein

Code a Week #4 Wittgenstein, my idol.

So this week completes somewhat my dive into processing, at least for a a little while. We salvaged working copies of Canon X-07, which understands the programming language of my childhood: BASIC! WUHUU!!!

Canon X-07

So I am going to be experimenting with that and sharing some results. I am also teaching two eTextile courses in the coming months and using Adafruits Gemma’s and Flora’s in then so some ATTiny code is following also.
But here is Wittgenstein and vectors with force applied into them. The grey dot should be draggable, not sure if it works in the p5.js environment though.
[p5js code canvas]class Attractor {
float mass;
float G;
PVector location;
boolean dragging = false;
boolean rollover = false;
PVector dragOffset;
Attractor() {
location = new PVector(width/2,height/2);
mass = 20;
G = (second()/30);
dragOffset = new PVector(0.0,0.0);
}

PVector attract(Mover m) {
PVector force = PVector.sub(location,m.location);
float d = force.mag();
d = constrain(d,5.0,25.0);
force.normalize();
float strength = (G * mass * m.mass) / (d * d);
force.mult(strength);
return force;
}

void display() {
ellipseMode(CENTER);
noStroke();
if (dragging) fill (second()*4.25,50);
if (dragging) text(“Knowledge is in the end based on acknowledgement.”,350,mouseY+6);
else if (rollover) fill(240,40,40,200);
else fill(175,200);
ellipse(location.x,location.y,mass*2,mass*2);
}

void clicked(int mx, int my) {
float d = dist(mx,my,location.x,location.y);
if (d < mass) {
dragging = true;

dragOffset.x = location.x-mx;
dragOffset.y = location.y-my;

}
}

void hover(int mx, int my) {
float d = dist(mx,my,location.x,location.y);
if (d < mass) {
rollover = true;
text(“One often makes a remark and only later sees how true it is.”,mouseX-80,mouseY+50);

}
else {
rollover = false;
fill(255);
text(“One often makes a remark and only later sees how true it is.”,100,240);
}
}

void stopDragging() {
dragging = false;
fill(255);
text(“Knowledge is in the end based on acknowledgement.”,150,150);
}

void drag() {
if (dragging) {
location.x = mouseX + dragOffset.x;
location.y = mouseY + dragOffset.y;
}
}

}

class Mover {

PVector location;
PVector velocity;
PVector acceleration;
float mass;

Mover(float m, float x, float y) {
mass = m;
location = new PVector(x, y);
velocity = new PVector(1, 0);
acceleration = new PVector(0, 0);
}

void applyForce(PVector force) {
PVector f = PVector.div(force, mass);
acceleration.add(f);
}

void update() {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}

void display() {
noStroke();
fill(10,180,140,100);
ellipse(location.x, location.y, mass*25, mass*25);
}
}

Mover[] movers = new Mover[10];

Attractor a;

void setup() {
PFont myFont;
myFont = createFont(“Georgia”, 12);
textFont(myFont);
size(640, 360);
for (int i = 0; i < movers.length; i++) {
movers[i] = new Mover(random(0.1, 2), random(width), random(height));
}
a = new Attractor();
}

void draw() {
background(255);

a.display();
a.drag();
a.hover(mouseX, mouseY);

for (int i = 0; i < movers.length; i++) {
PVector force = a.attract(movers[i]);
movers[i].applyForce(force);

movers[i].update();
movers[i].display();
}
}

void mousePressed() {
a.clicked(mouseX, mouseY);
}

void mouseReleased() {
a.stopDragging();
}

[/p5js]

Code a Week #3: More Wittgenstein

Again did not have very much time to code and after coding mostly in C for arduino etc. I do find Java & Javascript (the p5.js) to not really fit into my way of thinking. I do still enjoy it and this week I mostly ported the first week’s scipt into vectors. Inspired again (a lot) by Shiffmans Nature of Code-book. It is a recommendable book, if you have some background on programming and Object-oriented programming. Not the most clearly written, but fun. He has done a video tutorials also, which are a joy to watch.

Anyway this weeks code might not work on mobile devices that well, as it does track your mouse position. But who knows if it miraculously detects your touch also… (Did not code that into it, altough p5.js has support for touch controls.) And it’s a one minute loop on the text part. So stick around for the finale..

 

Wittgenstein and certainty:
[p5js code canvas]void thought1(){
int m = second();
if (m >5 && m <25 ){ fill(0); text("I act with complete certainty. But this certainty is my own.",100,250); } else { fill(255); text("I act with complete certainty. But this certainty is my own.",100,250); } } void thought2(){ int m = second(); if (m >27 && m <55 ){ fill(0); text("At the core of all well-founded belief lies belief that is unfounded.",100,50); } else { fill(255); text("At the core of all well-founded belief lies belief that is unfounded.",100,50); } } class Mover { PVector location; PVector velocity; PVector acceleration; float topspeed; Mover() { location = new PVector(width/2, height/2); velocity = new PVector(0, 0); topspeed = 10; } void update() { acceleration = PVector.random2D(); acceleration.mult(random(2)); velocity.add(acceleration); velocity.limit(topspeed-int(random(10))); location.add(velocity); } void display() { fill(255,50); noStroke(); rect(0,0,640,360); fill(10); ellipse(location.x, location.y, 5, 5); } void checkEdges() { if (location.x > width) {
location.x = 0;
}
else if (location.x < 0) { location.x = width; } if (location.y > height) {
location.y = 0;
}
else if (location.y < 0) { location.y = height; } } } class Follower { PVector location2; PVector velocity2; PVector acceleration2; float topspeed2; Follower() { location2 = new PVector(random(width),random(height)); velocity2 = new PVector(0,0); topspeed2 = 4; } void update2() { PVector mouse = new PVector(mouseX,mouseY); PVector dir = PVector.sub(mouse,location2); dir.normalize(); dir.mult(0.5); acceleration2 = dir; velocity2.add(acceleration2); velocity2.limit(topspeed2); location2.add(velocity2); } void display2() { noStroke(); fill(255,0,0,100); ellipse(location2.x,location2.y,4,4); } void checkEdges2() { if (location2.x > width) {
location2.x = 0;
} else if (location2.x < 0) { location2.x = width; } if (location2.y > height) {
location2.y = 0;
} else if (location2.y < 0) { location2.y = height; } } } Mover mover; Follower[] follower = new Follower[20]; void setup() { PFont myFont; myFont = createFont("Georgia", 12); textFont(myFont); size(640,360); mover = new Mover(); for (int i = 0; i < follower.length; i++) { follower[i] = new Follower(); } background(255); } void draw() { thought1(); thought2(); mover.update(); mover.checkEdges(); mover.display(); for (int i = 0; i < follower.length; i++) { follower[i].update2(); follower[i].checkEdges2(); follower[i].display2(); } }[/p5js]

Code a week #1

I have been researching creative coding as a practice in art education for a year now and thinking about much longer. Starting a new year, I realized I have not coded that much during the last year. So I set myself a little challenge -To write a little nifty program every week. – To get myself familiar with the most basic stuff again. These are nothing miraculous or fancy. But something fun for myself. Besides the code, I am exploring the artistic qualities of the code in these little sketches.

Read More