Skip to content

Instantly share code, notes, and snippets.

View s-estay's full-sized avatar
👻

Sebastian Estay s-estay

👻
  • Sweden
  • 11:42 (UTC +01:00)
View GitHub Profile
@s-estay
s-estay / instance-mode-example.js
Last active September 5, 2019 14:29
P5js instance mode example
var sketch = function(p){
p.setup = function(){
p.createCanvas(p.windowWidth*0.8, 100);
}
p.draw = function(){
p.background(0);
}
@s-estay
s-estay / instance-mode-example.html
Last active September 4, 2019 19:04
Include new p5 objects within div tag in md-file
<script src = "{{site.baseurl}}/assets/js/instance-mode-example-one.js"></script>
<script src = "{{site.baseurl}}/assets/js/instance-mode-example-two.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<div class = "p5js-script-div" id = "script-1"></div>
<div class = "p5js-script-div" id = "script-2"></div>
@s-estay
s-estay / map-random.js
Last active September 4, 2019 19:01
P5js map random example
//instance mode
//map and random functions
var sketch = function(p){
var bcol = 0;
//objects
//in c++ this would be a struct
var spot = {
x : 100,
@s-estay
s-estay / classes-p5.js
Created August 23, 2018 10:14
Trying out classes in P5js
let bubble1, bubble2; //global variables
function setup(){
createCanvas(640, 200);
bubble1 = new Bubble(320, 50, 20, 'red', 2); //start at the center of the canvas
bubble2 = new Bubble(160, 50, 10, 'blue', 1); //new bubble2 to the left of bubble1
//print(bubble.x, bubble.y);
}
function draw(){
@s-estay
s-estay / this-is-a-test-im-1.js
Last active March 20, 2018 10:20
Create script using instance mode.
//instance mode
//template for creating a p5 sketch (kind of)
var sketch = function(p){
//RGB rainbow colors
p.rainbowR = [248, 255, 255, 254, 208, 105, 18, 68, 59];
p.rainbowG = [12, 51, 102, 174, 195, 208, 189, 68, 12];
p.rainbowB = [18, 17, 68, 45, 16, 37, 185, 221, 189];
var i;
@s-estay
s-estay / this-is-a-test.js
Created March 20, 2018 06:55
Contain script within div tag using p5 parent element.
//RGB rainbow colors
var rainbowR = [248, 255, 255, 254, 208, 105, 18, 68, 59];
var rainbowG = [12, 51, 102, 174, 195, 208, 189, 68, 12];
var rainbowB = [18, 17, 68, 45, 16, 37, 185, 221, 189];
var i;
var canvas;
var t = rainbowR.length;
function setup() {
@s-estay
s-estay / script.js
Last active March 20, 2018 06:56
How to add js to md.
<script src = "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/addons/p5.dom.min.js"></script>
<div id = "script-holder">
<script src = "{{site.baseurl}}/js/this-is-a-test.js"></script>
</div>
@s-estay
s-estay / pwm_adc_led.ino
Created April 9, 2017 18:33
arduino basics: control PWM signal through LED using a ADC signal coming from a potentiometer
// PWM signal through pin 3
// what's a PWM signal? read here: https://en.wikipedia.org/wiki/Pulse-width_modulation
// 8 bits PWM: 0 (0% or GND) to 255 (100% or VCC)
// PWM signal is controlled by a potentiometer connected to pin A2
// the potentiometer have 3 leads: 1 (or 3) connects to GND, 2 to A2 and 3 (or 1) to VCC
// the potentiometer input signal is an analog signal
// the microcontroller converts this analog signal into digital using a 10 bits ADC
// ADC: analog to digital converter
// a 10 bits ADC signal ranges between 0 - 1023
// the ADC signal is equivalent to the input analog voltage where 0 is GND and 1023 is VCC (5V)
@s-estay
s-estay / pwm_led.ino
Last active April 9, 2017 18:23
arduino basics: PWM signal through LED
// PWM signal through pin 3
// 8 bits PWM: 0 (0% or GND) to 255 (100% or VCC)
// what's a PWM signal? read here: https://en.wikipedia.org/wiki/Pulse-width_modulation
// pin 3 will source current to the LED
// refer to source_current.ino file to see how to connect the LED
// code executed on Arduino Leonardo
void setup(){
pinMode(3, OUTPUT); // observe that only pins preceded by ~ in the board can output a PWM signal
}
@s-estay
s-estay / switch_led.ino
Last active April 9, 2017 12:18
arduino basics: control LED using switch
// turn LED ON and OFF using switch
// we read the state of the switch through pin 7
// switch is connected between pin 7 and GND
// we use the microcontroller's internal 20k pullup resistor
// why do we use a pullup resistor? read here: https://learn.sparkfun.com/tutorials/pull-up-resistors
// you can choose between LED ON or LED OFF when switch is pressed
// pin 8 will source current to the LED
// refer to source_current.ino file to see how to connect the LED
// code executed on Arduino Leonardo